diff --git a/.github/workflows/test-tutorial.yml b/.github/workflows/test-tutorial.yml new file mode 100644 index 00000000000..5e148825d62 --- /dev/null +++ b/.github/workflows/test-tutorial.yml @@ -0,0 +1,19 @@ +name: Test GM Tutorial +on: push + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Run GM tutorial in docker-compose + uses: isbang/compose-action@v1.5.0 + with: + compose-file: "./gmbuilder-docker-compose.yml" + up-flags: "--build" + - name: Test the GM tutorial + run: ./gm-tester.sh diff --git a/gm-tester.sh b/gm-tester.sh new file mode 100755 index 00000000000..3f87e51eb8e --- /dev/null +++ b/gm-tester.sh @@ -0,0 +1,40 @@ +#!/bin/bash +URL=localhost:26657/block\?height=3 + +# Define the maximum number of retries +MAX_RETRIES=50 + +# Define the delay between retries in seconds +RETRY_DELAY=5 + +# Counter for the number of retries +RETRY_COUNT=0 + +# Loop until the result is not equal to the expected string or maximum retries are reached +while [[ $RETRY_COUNT -lt $MAX_RETRIES ]]; do + # Execute the curl command and capture the result + RESULT=$(curl -s "$URL") + + # Compare the result with the expected string or null string + if jq -e '.result' <<< "$RESULT" > /dev/null; then + echo "Rollup has produced block #3:" + echo $RESULT + exit 0 + break + fi + + # Increment the retry count + ((RETRY_COUNT++)) + + # Display a retry message + echo "Retrying... (Attempt $RETRY_COUNT)" + + # Sleep for the specified delay before the next retry + sleep $RETRY_DELAY +done + +# Check if maximum retries are reached without success +if [[ $RETRY_COUNT -eq $MAX_RETRIES ]]; then + echo "Maximum retries reached. Unable to obtain a different result." +fi +exit 1 diff --git a/gmbuilder-docker-compose.yml b/gmbuilder-docker-compose.yml new file mode 100644 index 00000000000..e9712fbd46e --- /dev/null +++ b/gmbuilder-docker-compose.yml @@ -0,0 +1,23 @@ +version: "3.9" +services: + celestia: + image: ghcr.io/rollkit/local-celestia-devnet:latest + # Rollup can't start until after DA starts. + # This ensures it waits 5 seconds so the rollup can query it. + ports: + - "26657:26657" + - "26659:26659" + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:26657/block?height=1"] + interval: 5s + timeout: 10s + retries: 5 + gm: + build: + context: . + dockerfile: gmbuilder.Dockerfile + depends_on: + celestia: + condition: service_healthy + ports: + - "36657:26657" \ No newline at end of file diff --git a/gmbuilder.Dockerfile b/gmbuilder.Dockerfile new file mode 100644 index 00000000000..0deba4896e5 --- /dev/null +++ b/gmbuilder.Dockerfile @@ -0,0 +1,8 @@ +FROM golang:1.20.3 + +WORKDIR / + +ADD ./ /cosmos-sdk/ + +COPY --chmod=+x script.sh /script.sh +ENTRYPOINT /bin/bash /script.sh diff --git a/script.sh b/script.sh new file mode 100755 index 00000000000..fa891dc52a9 --- /dev/null +++ b/script.sh @@ -0,0 +1,59 @@ +#!/bin/bash +cd .. +sudo apt-get update +sudo apt-get install jq -y +curl https://get.ignite.com/cli@v0.26.1! | bash +ignite scaffold chain gm --address-prefix gm +cd gm +go mod edit -replace github.com/cosmos/cosmos-sdk=../cosmos-sdk +go mod edit -replace github.com/tendermint/tendermint=github.com/rollkit/cometbft@v0.0.0-20230524013049-75272ebaee38 +go mod tidy +go mod download + +VALIDATOR_NAME=validator1 +CHAIN_ID=gm +KEY_NAME=gm-key +KEY_2_NAME=gm-key-2 +CHAINFLAG="--chain-id ${CHAIN_ID}" +TOKEN_AMOUNT="10000000000000000000000000stake" +STAKING_AMOUNT="1000000000stake" + +# create a random Namespace ID for your rollup to post blocks to +NAMESPACE_ID=$(openssl rand -hex 8) +echo $NAMESPACE_ID + +# build the gm chain with Rollkit +ignite chain build +# reset any existing genesis/chain data +#/home/runner/go/bin/gmd tendermint unsafe-reset-all +gmd tendermint unsafe-reset-all + +# initialize the validator with the chain ID you set +#/home/runner/go/bin/gmd init $VALIDATOR_NAME --chain-id $CHAIN_ID +gmd init $VALIDATOR_NAME --chain-id $CHAIN_ID + +# add keys for key 1 and key 2 to keyring-backend test +echo y | /home/runner/go/bin/gmd keys add $KEY_NAME --keyring-backend test +echo y | /home/runner/go/bin/gmd keys add $KEY_2_NAME --keyring-backend test + +# add these as genesis accounts +gmd add-genesis-account $KEY_NAME $TOKEN_AMOUNT --keyring-backend test +gmd add-genesis-account $KEY_2_NAME $TOKEN_AMOUNT --keyring-backend test + +# set the staking amounts in the genesis transaction +gmd gentx $KEY_NAME $STAKING_AMOUNT --chain-id $CHAIN_ID --keyring-backend test + +# collect genesis transactions +gmd collect-gentxs + +# query the DA Layer start height, in this case we are querying +# our local devnet at port 26657, the RPC. The RPC endpoint is +# to allow users to interact with Celestia's nodes by querying +# the node's state and broadcasting transactions on the Celestia +# network. The default port is 26657. +DA_BLOCK_HEIGHT=$(curl http://celestia:26657/block | jq -r '.result.block.header.height') +echo $DA_BLOCK_HEIGHT + +# start the chain +echo "Starting rollup in foreground!" +/home/runner/go/bin/gmd start --rollkit.aggregator true --rollkit.da_layer celestia --rollkit.da_config='{"base_url":"http://celestia:26659","timeout":60000000000,"fee":6000,"gas_limit":6000000}' --rollkit.namespace_id $NAMESPACE_ID --rollkit.da_start_height $DA_BLOCK_HEIGHT