Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

Commit

Permalink
feat: add initial scaffolding for the blobstream demo (#615)
Browse files Browse the repository at this point in the history
* feat: add initial environment for demo

* Update demo/README.md

Co-authored-by: Josh Stein <[email protected]>

* feat: add more tooling and the verifier

* chore: remove unnecessary deployer

---------

Co-authored-by: Josh Stein <[email protected]>
  • Loading branch information
rach-id and jcstein authored Dec 6, 2023
1 parent 33f7618 commit 11227eb
Show file tree
Hide file tree
Showing 28 changed files with 2,563 additions and 0 deletions.
14 changes: 14 additions & 0 deletions demo/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM ghcr.io/celestiaorg/orchestrator-relayer:v1.0.1 as orchestrator-relayer

FROM ghcr.io/celestiaorg/celestia-app:v1.3.0 as celestia-app

USER root

RUN apk update && apk --no-cache add bash jq coreutils curl

COPY --from=orchestrator-relayer /bin/blobstream /bin/blobstream

# p2p port
EXPOSE 9090 26657 30000

CMD [ "/bin/blobstream" ]
8 changes: 8 additions & 0 deletions demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Blobstream rollup dev environment

To run this demo, first clone the repository and change to the `/demo` directory.

Then run the docker-compose setup:

```bash
docker-compose up -d
112 changes: 112 additions & 0 deletions demo/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
version: '3'

services:
# validator always needs to start first for the E2E suite to work correctly
validator:
container_name: validator
build:
dockerfile: Dockerfile
ports:
- "9090:9090"
- "26657:26657"
entrypoint: [
"/bin/bash"
]
command: [
"/opt/start_validator.sh"
]
# EVM Address: 0x966e6f22781EF6a6A82BBB4DB3df8E225DfD9488
# key: da6ed55cb2894ac2c9c10209c09de8e8b9d109b910338d5bf3d747a7e1fc9eb9
volumes:
- ${PWD}/validator/config/priv_validator_key.json:/opt/config/priv_validator_key.json:ro
- ${PWD}/validator/config/node_key.json:/opt/config/node_key.json:ro
- ${PWD}/validator/keyring-test:/opt/keyring-test:ro
- ${PWD}/validator/config/config.toml:/opt/config/config.toml:ro
- ${PWD}/validator/config/app.toml:/opt/config/app.toml:ro
- ${PWD}/validator/config/genesis.json:/opt/config/genesis.json:rw
- ${PWD}/scripts/start_validator.sh:/opt/start_validator.sh:ro

orchestrator:
container_name: orchestrator
build:
dockerfile: Dockerfile
depends_on:
- validator
ports:
- "30000:30000"
environment:
- MONIKER=validator
- PRIVATE_KEY=da6ed55cb2894ac2c9c10209c09de8e8b9d109b910338d5bf3d747a7e1fc9eb9
- EVM_ACCOUNT=0x966e6f22781EF6a6A82BBB4DB3df8E225DfD9488
- CORE_RPC_HOST=validator
- CORE_RPC_PORT=26657
- CORE_GRPC_HOST=validator
- CORE_GRPC_PORT=9090
# the other peers will consider validator as a bootstrapper. So, it doesn't need to connect to any need during startup
- P2P_BOOTSTRAPPERS=
- P2P_IDENTITY=f7fd2be6b2abaa8519b0570d3a12e684a397456b0cc721198ebdd7e343cdd8f41813ef8aa857426c4e909c4fe19120a0f3f8c505286ca9d9249b5681475ec459
- P2P_LISTEN=/ip4/0.0.0.0/tcp/30000
entrypoint: [
"/bin/bash"
]
command: [
"/opt/start_orchestrator_after_validator_created.sh"
]
volumes:
- ${PWD}/validator/keyring-test:/opt/keyring-test:ro
- ${PWD}/scripts/start_orchestrator_after_validator_created.sh:/opt/start_orchestrator_after_validator_created.sh:ro

ganache:
container_name: ganache
image: trufflesuite/ganache-cli
command: [
"--port=8545",
"--verbose",
"--host=0.0.0.0",
"--networkId=1234",
"--chainId=1234",
"--gasLimit=30000000",
"--account=\"0x0e9688e585562e828dcbd4f402d5eddf686f947fb6bf75894a85bf008b017401,0x90000000000000000000000\""
]
ports:
- "8545:8545"

relayer:
container_name: relayer
build:
dockerfile: Dockerfile
depends_on:
- ganache
- validator
ports:
- "30004:30000"
environment:
- EVM_CHAIN_ID=blobstream-e2e
- EVM_ACCOUNT=0x95359c3348e189ef7781546e6E13c80230fC9fB5
- PRIVATE_KEY=0e9688e585562e828dcbd4f402d5eddf686f947fb6bf75894a85bf008b017401
- CORE_RPC_HOST=validator
- CORE_RPC_PORT=26657
- CORE_GRPC_HOST=validator
- CORE_GRPC_PORT=9090
- EVM_CHAIN_ID=1234
- EVM_ENDPOINT=http://ganache:8545
- STARTING_NONCE=latest
- P2P_BOOTSTRAPPERS=/dns/orchestrator/tcp/30000/p2p/12D3KooWBSMasWzRSRKXREhediFUwABNZwzJbkZcYz5rYr9Zdmfn
- P2P_LISTEN=/ip4/0.0.0.0/tcp/30000
entrypoint: [
"/bin/bash"
]
command: [
"/opt/start_relayer.sh"
]
volumes:
- ${PWD}/scripts/start_relayer.sh:/opt/start_relayer.sh:ro
- ${PWD}/scripts/deploy_blobstream_contract.sh:/opt/deploy_blobstream_contract.sh:ro

sequencer:
container_name: sequencer
build:
context: ./sequencer
dockerfile: Dockerfile
depends_on:
- relayer
78 changes: 78 additions & 0 deletions demo/scripts/deploy_blobstream_contract.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash

# This script deploys the Blobstream contract and outputs the address to stdout.

# check whether to deploy a new contract or no need
if [[ "${DEPLOY_NEW_CONTRACT}" != "true" ]]
then
echo "no need to deploy a new Blobstream contract. exiting..."
exit 0
fi

# check if environment variables are set
if [[ -z "${EVM_CHAIN_ID}" || -z "${PRIVATE_KEY}" ]] || \
[[ -z "${CORE_RPC_HOST}" || -z "${CORE_RPC_PORT}" ]] || \
[[ -z "${CORE_GRPC_HOST}" || -z "${CORE_GRPC_PORT}" ]] || \
[[ -z "${EVM_ENDPOINT}" || -z "${STARTING_NONCE}" ]]
then
echo "Environment not setup correctly. Please set:"
echo "EVM_CHAIN_ID, PRIVATE_KEY, CORE_RPC_HOST, CORE_RPC_PORT, CORE_GRPC_HOST, CORE_GRPC_PORT, EVM_ENDPOINT, STARTING_NONCE variables"
exit 1
fi

# wait for the node to get up and running
while true
do
# verify that the node is listening on gRPC
nc -z -w5 "$CORE_GRPC_HOST" "$CORE_GRPC_PORT"
result=$?
if [ "${result}" != "0" ]; then
echo "Waiting for node gRPC to be available ..."
sleep 1s
continue
fi

height=$(/bin/celestia-appd query block 1 -n tcp://${CORE_RPC_HOST}:${CORE_RPC_PORT} 2>/dev/null)
if [[ -n ${height} ]] ; then
break
fi
echo "Waiting for block 1 to be generated..."
sleep 1s
done

# wait for the evm node to start
while true
do
status_code=$(curl --write-out '%{http_code}' --silent --output /dev/null \
--location --request POST ${EVM_ENDPOINT} \
--header 'Content-Type: application/json' \
--data-raw "{
\"jsonrpc\":\"2.0\",
\"method\":\"eth_blockNumber\",
\"params\":[],
\"id\":${EVM_CHAIN_ID}}")
if [[ "${status_code}" -eq 200 ]] ; then
break
fi
echo "Waiting for ethereum node to be up..."
sleep 1s
done

# import keys to deployer
/bin/blobstream deploy keys evm import ecdsa "${PRIVATE_KEY}" --evm.passphrase=123

echo "deploying Blobstream contract..."

/bin/blobstream deploy \
--evm.chain-id "${EVM_CHAIN_ID}" \
--evm.account "${EVM_ACCOUNT}" \
--core.rpc="${CORE_RPC_HOST}:${CORE_RPC_PORT}" \
--core.grpc="${CORE_GRPC_HOST}:${CORE_GRPC_PORT}" \
--grpc.insecure \
--starting-nonce "${STARTING_NONCE}" \
--evm.rpc "${EVM_ENDPOINT}" \
--evm.passphrase=123 2> /opt/output

echo $(cat /opt/output)

cat /opt/output | grep "deployed" | awk '{ print $6 }' | grep -o '0x.*' > /opt/blobstream_address.txt
32 changes: 32 additions & 0 deletions demo/scripts/start_orchestrator_after_validator_created.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

# This script waits for the validator to be created before starting the orchestrator

# check if environment variables are set
if [[ -z "${MONIKER}" || -z "${PRIVATE_KEY}" ]] || \
[[ -z "${CORE_GRPC_HOST}" || -z "${CORE_GRPC_PORT}" ]] || \
[[ -z "${CORE_RPC_HOST}" || -z "${CORE_RPC_PORT}" ]] || \
[[ -z "${P2P_LISTEN}" ]]
then
echo "Environment not setup correctly. Please set:"
echo "MONIKER, PRIVATE_KEY, CORE_GRPC_HOST, CORE_GRPC_PORT, CORE_RPC_HOST, CORE_RPC_PORT, P2P_LISTEN variables"
exit 1
fi

# initialize orchestrator
/bin/blobstream orch init

# add keys to keystore
/bin/blobstream orch keys evm import ecdsa "${PRIVATE_KEY}" --evm.passphrase 123

# import the p2p key to use
/bin/blobstream orchestrator keys p2p import key "${P2P_IDENTITY}"

/bin/blobstream orchestrator start \
--evm.account="${EVM_ACCOUNT}" \
--core.rpc="${CORE_RPC_HOST}:${CORE_RPC_PORT}" \
--core.grpc="${CORE_GRPC_HOST}:${CORE_GRPC_PORT}" \
--grpc.insecure \
--p2p.nickname=key \
--p2p.listen-addr="${P2P_LISTEN}" \
--evm.passphrase=123
61 changes: 61 additions & 0 deletions demo/scripts/start_relayer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

# This script runs the Blobstream relayer with the ability to deploy a new Blobstream contract or
# pass one as an environment variable BLOBSTREAM_CONTRACT

# check if environment variables are set
if [[ -z "${EVM_CHAIN_ID}" || -z "${PRIVATE_KEY}" ]] || \
[[ -z "${CORE_GRPC_HOST}" || -z "${CORE_GRPC_PORT}" ]] || \
[[ -z "${CORE_RPC_HOST}" || -z "${CORE_RPC_PORT}" ]] || \
[[ -z "${EVM_ENDPOINT}" || -z "${P2P_BOOTSTRAPPERS}" ]] || \
[[ -z "${P2P_LISTEN}" ]]
then
echo "Environment not setup correctly. Please set:"
echo "EVM_CHAIN_ID, PRIVATE_KEY, CORE_GRPC_HOST, CORE_GRPC_PORT, CORE_RPC_HOST, CORE_RPC_PORT, EVM_ENDPOINT, P2P_BOOTSTRAPPERS, P2P_LISTEN variables"
exit 1
fi

echo "starting relayer..."

# wait for the node to get up and running
while true
do
height=$(/bin/celestia-appd query block 1 -n tcp://$CORE_RPC_HOST:$CORE_RPC_PORT 2>/dev/null)
if [[ -n ${height} ]] ; then
break
fi
echo "Waiting for block 1 to be generated..."
sleep 5s
done

# check whether to deploy a new contract or use an existing one
if [[ -z "${BLOBSTREAM_CONTRACT}" ]]
then
export DEPLOY_NEW_CONTRACT=true
export STARTING_NONCE=latest
# expects the script to be mounted to this directory
/bin/bash /opt/deploy_blobstream_contract.sh
fi

# get the address from the `blobstream_address.txt` file
BLOBSTREAM_CONTRACT=$(cat /opt/blobstream_address.txt)

# init the relayer
/bin/blobstream relayer init

# import keys to relayer
/bin/blobstream relayer keys evm import ecdsa "${PRIVATE_KEY}" --evm.passphrase 123

# to give time for the bootstrappers to be up
sleep 5s
/bin/blobstream relayer start \
--evm.account="${EVM_ACCOUNT}" \
--core.rpc="${CORE_RPC_HOST}:${CORE_RPC_PORT}" \
--core.grpc="${CORE_GRPC_HOST}:${CORE_GRPC_PORT}" \
--grpc.insecure \
--evm.chain-id="${EVM_CHAIN_ID}" \
--evm.rpc="${EVM_ENDPOINT}" \
--evm.contract-address="${BLOBSTREAM_CONTRACT}" \
--p2p.bootstrappers="${P2P_BOOTSTRAPPERS}" \
--p2p.listen-addr="${P2P_LISTEN}" \
--evm.passphrase=123
51 changes: 51 additions & 0 deletions demo/scripts/start_validator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

# This script starts validator

# set the genesis time to current time for pruning to work properly
new_time=$(date -u +"%Y-%m-%dT%H:%M:%S.%N")"Z"
cp /opt/config/genesis.json genesis.json
jq --arg new_time "$new_time" '.genesis_time = $new_time' genesis.json > /opt/config/genesis.json

if [[ ! -f /opt/data/priv_validator_state.json ]]
then
mkdir /opt/data
cat <<EOF > /opt/data/priv_validator_state.json
{
"height": "0",
"round": 0,
"step": 0
}
EOF
fi

{
# wait for the node to get up and running
while true
do
status_code=$(curl --write-out '%{http_code}' --silent --output /dev/null localhost:26657/status)
if [[ "${status_code}" -eq 200 ]] ; then
break
fi
echo "Waiting for node to be up..."
sleep 2s
done

VAL_ADDRESS=$(celestia-appd keys show validator --keyring-backend test --bech=val --home /opt -a)

# Register the validator EVM address
celestia-appd tx qgb register \
"${VAL_ADDRESS}" \
0x966e6f22781EF6a6A82BBB4DB3df8E225DfD9488 \
--from validator \
--home /opt \
--fees "30000utia" \
-b block \
--chain-id="blobstream-e2e" \
--yes
} &

/bin/celestia-appd start \
--moniker validator \
--rpc.laddr tcp://0.0.0.0:26657 \
--home /opt
1 change: 1 addition & 0 deletions demo/sequencer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
8 changes: 8 additions & 0 deletions demo/sequencer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM docker.io/golang:1.21.4-alpine3.18

RUN apk update && apk --no-cache add make gcc musl-dev git bash
WORKDIR /opt
COPY . .
RUN make build

CMD ["./build/demo"]
Loading

0 comments on commit 11227eb

Please sign in to comment.