From 2dcd974b19e230b052e3fc80531bd4509495c555 Mon Sep 17 00:00:00 2001 From: Ashish Chandra Date: Mon, 28 Aug 2023 16:31:21 -0500 Subject: [PATCH 1/4] Updates to support CCV --- .github/workflows/build.yml | 2 +- .github/workflows/docker-publish.yaml | 89 +++++---- .github/workflows/interchaintest.yml | 2 +- .gitignore | 1 + docker-compose.yml.example | 37 ++++ rly/sample-rly.json | 26 +++ rly/start-rly.sh | 267 +++++++++++++++++++++----- saga.Dockerfile | 2 + 8 files changed, 336 insertions(+), 90 deletions(-) create mode 100644 docker-compose.yml.example create mode 100644 rly/sample-rly.json diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 24fd93e17..fc5839617 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,7 @@ on: pull_request: push: branches: - - master + - '**' jobs: build: diff --git a/.github/workflows/docker-publish.yaml b/.github/workflows/docker-publish.yaml index 6c6cd8164..856c65b53 100644 --- a/.github/workflows/docker-publish.yaml +++ b/.github/workflows/docker-publish.yaml @@ -1,54 +1,63 @@ -name: Create and publish a Docker image +name: Build and Push to DockerHub on: push: tags: - - '**' - branches: - - '**' - -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} + - "v*.*.*" jobs: - build-and-push-image: + docker: runs-on: ubuntu-latest - permissions: - contents: read - packages: write - + env: + GOPRIVATE: github.com/sagaxyz/* steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Log in to the Container registry - uses: docker/login-action@v1 + - name: Set up access to private Go modules + env: + GITHUB_USER: ${{ secrets.GH_USER }} + GITHUB_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }} + run: git config --global url."https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com".insteadOf "https://github.com" + + - name: Checkout + uses: actions/checkout@v3 + - + name: Git fetch everything + run: git fetch --prune --unshallow + - name: Setup Go + uses: actions/setup-go@v3 with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Extract metadata (tags, labels) for Docker + go-version-file: './go.mod' + cache: true + - run: go version + + - name: Compile rly + run : make build + - + name: Get Github tag id: meta - uses: docker/metadata-action@v3 + run: | + echo "::set-output name=tag::$(echo ${{github.ref_name}} | sed -e 's/^v//')" + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - + name: Login to DockerHub + uses: docker/login-action@v2 with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - - name: Build and push Docker image - uses: docker/build-push-action@v2.7.0 + registry: docker.io + username: sagaxyz + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push + uses: docker/build-push-action@v3 with: context: . - platforms: linux/amd64,linux/arm64 - file: Dockerfile + file: saga.Dockerfile push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max + build-args: | + GITHUB_USER=${{ secrets.GH_USER }} + GITHUB_TOKEN=${{ secrets.GH_ACCESS_TOKEN }} + platforms: linux/amd64 + tags: sagaxyz/go-relayer:${{ steps.meta.outputs.tag }}, sagaxyz/spc:latest diff --git a/.github/workflows/interchaintest.yml b/.github/workflows/interchaintest.yml index 402e55bda..efff87ec4 100644 --- a/.github/workflows/interchaintest.yml +++ b/.github/workflows/interchaintest.yml @@ -4,7 +4,7 @@ on: pull_request: push: branches: - - master + - main jobs: events: diff --git a/.gitignore b/.gitignore index 835dd0cc9..4fe5ba715 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ dist/ # Don't commit the vendor directory if anyone runs 'go mod vendor'. /vendor +docker-compose.yml diff --git a/docker-compose.yml.example b/docker-compose.yml.example new file mode 100644 index 000000000..0b0ce35a2 --- /dev/null +++ b/docker-compose.yml.example @@ -0,0 +1,37 @@ +version: '3' + +services: + rly: + container_name: rly + image: "rly:latest" + build: + context: . + dockerfile: saga.Dockerfile + environment: + - KEYNAME=relayer + - PROVIDER_CHAINID= + - CONSUMER_CHAINID= + - PROVIDER_RLY_MNEMONIC= + - CONSUMER_RLY_MNEMONIC= + - KEYRING=test # remember to change to other types of keyring like 'file' in-case exposing to outside world, otherwise your balance will be wiped quickly. The keyring test does not require private key to steal tokens from you + - KEYALGO=secp256k1 + - KEYPASSWD="passw0rdK3y" + - PROVIDER_RPC_ADDRESS= + - CONSUMER_RPC_ADDRESS= + - RLY_SRC_PORT=consumer # Do not change unless you know what you are doing. This impacts the IBC connection ports + - RLY_DST_PORT=provider # Do not change unless you know what you are doing + - RLY_ORDERING=ordered # Do not change unless you know what you are doing + - RLY_DEBUG=true # set it to false as needed + networks: + - localnet + ports: + - 5183:5183 + volumes: + - ./rly/start-rly.sh:/root/start-rly.sh + +volumes: + relayer: + +networks: + localnet: + \ No newline at end of file diff --git a/rly/sample-rly.json b/rly/sample-rly.json new file mode 100644 index 000000000..c1181d3bc --- /dev/null +++ b/rly/sample-rly.json @@ -0,0 +1,26 @@ +{ + "type": "cosmos", + "value": { + "key": "", + "chain-id": "", + "rpc-addr": "", + "account-prefix": "saga", + "keyring-backend": "test", + "gas-adjustment": 1.2, + "gas-prices": "0stake", + "min-gas-amount": 0, + "max-gas-amount": 0, + "debug": true, + "timeout": "20s", + "block-timeout": "", + "output-format": "json", + "sign-mode": "direct", + "extra-codecs": [], + "coin-type": null, + "signing-algorithm": "", + "broadcast-mode": "batch", + "min-loop-duration": 0, + "extension-options": [], + "feegrants": null + } +} \ No newline at end of file diff --git a/rly/start-rly.sh b/rly/start-rly.sh index 6cbe3673d..28fd7d5ee 100755 --- a/rly/start-rly.sh +++ b/rly/start-rly.sh @@ -1,52 +1,223 @@ #!/bin/bash -KEYPASSWD=${KEYPASSWD:-DoNoTuSeInPrOd} - -rly config init - -echo $RELAYER_CHAINLET_MNEMONIC > mnemo.file.sevm -echo $RELAYER_SPC_MNEMONIC > mnemo.file.spc - -mv /root/tmp/sevm_111-1.json.example /root/tmp/$CHAINLET_CHAIN_ID.json -mv /root/tmp/sevm_111-2.json.example /root/tmp/$SPC_CHAIN_ID.json - -cat /root/tmp/$CHAINLET_CHAIN_ID.json | jq '.value."chain-id"="'$CHAINLET_CHAIN_ID'"' > /root/tmp/$CHAINLET_CHAIN_ID.json.tmp && mv /root/tmp/$CHAINLET_CHAIN_ID.json.tmp /root/tmp/$CHAINLET_CHAIN_ID.json -cat /root/tmp/$SPC_CHAIN_ID.json | jq '.value."chain-id"="'$SPC_CHAIN_ID'"' > /root/tmp/$SPC_CHAIN_ID.json.tmp && mv /root/tmp/$SPC_CHAIN_ID.json.tmp /root/tmp/$SPC_CHAIN_ID.json - -# TODO: hardcoded port; http -cat /root/tmp/$CHAINLET_CHAIN_ID.json | jq '.value."rpc-addr"="'$CHAINLET_RPC_ADDRESS'"' > /root/tmp/$CHAINLET_CHAIN_ID.json.tmp && mv /root/tmp/$CHAINLET_CHAIN_ID.json.tmp /root/tmp/$CHAINLET_CHAIN_ID.json -cat /root/tmp/$SPC_CHAIN_ID.json | jq '.value."rpc-addr"="'$SPC_RPC_EXTERNAL_ADDRESS'"' > /root/tmp/$SPC_CHAIN_ID.json.tmp && mv /root/tmp/$SPC_CHAIN_ID.json.tmp /root/tmp/$SPC_CHAIN_ID.json - -cat /root/tmp/$CHAINLET_CHAIN_ID.json | jq '.value."keyring-backend"="file"' > /root/tmp/$CHAINLET_CHAIN_ID.json.tmp && mv /root/tmp/$CHAINLET_CHAIN_ID.json.tmp /root/tmp/$CHAINLET_CHAIN_ID.json -cat /root/tmp/$SPC_CHAIN_ID.json | jq '.value."keyring-backend"="file"' > /root/tmp/$SPC_CHAIN_ID.json.tmp && mv /root/tmp/$SPC_CHAIN_ID.json.tmp /root/tmp/$SPC_CHAIN_ID.json - -cat /root/tmp/$CHAINLET_CHAIN_ID.json | jq '.value."gas-prices"="'1$CHAINLET_DENOM'"' > /root/tmp/$CHAINLET_CHAIN_ID.json.tmp && mv /root/tmp/$CHAINLET_CHAIN_ID.json.tmp /root/tmp/$CHAINLET_CHAIN_ID.json -cat /root/tmp/$SPC_CHAIN_ID.json | jq '.value."gas-prices"="'1$SPC_DENOM'"' > /root/tmp/$SPC_CHAIN_ID.json.tmp && mv /root/tmp/$SPC_CHAIN_ID.json.tmp /root/tmp/$SPC_CHAIN_ID.json - -cp /root/tmp/$CHAINLET_CHAIN_ID.json /root/.relayer/config/ -cp /root/tmp/$SPC_CHAIN_ID.json /root/.relayer/config/ - -rly chains add $CHAINLET_CHAIN_ID --file /root/.relayer/config/$CHAINLET_CHAIN_ID.json -rly chains add $SPC_CHAIN_ID --file /root/.relayer/config/$SPC_CHAIN_ID.json - -yq -i '.chains."'$CHAINLET_CHAIN_ID'".value.extra-codecs |= ["ethermint"]' /root/.relayer/config/config.yaml - -(echo $KEYPASSWD; echo $KEYPASSWD) | rly keys restore $CHAINLET_CHAIN_ID key1 "$(cat /root/mnemo.file.sevm)" --coin-type=60 -(echo $KEYPASSWD; echo $KEYPASSWD) | rly keys restore $SPC_CHAIN_ID key2 "$(cat /root/mnemo.file.spc)" - -rly paths new $CHAINLET_CHAIN_ID $SPC_CHAIN_ID dp - -# we want to make sure that chainlet is up and running -while true -do - rly q node-state $CHAINLET_CHAIN_ID +#from container environment vars +SLEEPTIME=${SLEEPTIME:-5} # if unset, set to 5 seconds +SLEEPTIME_IBC=${SLEEPTIME_IBC:-60} # Amount of time to wait for an IBC channel to be created +SLEEPTIME_BLOCKWAIT=${SLEEPTIME_BLOCKWAIT:-1} + +PROVIDER_CHAIN=${PROVIDER_CHAIN:-provider} +CONSUMER_CHAIN=${CONSUMER_CHAIN:-consumer} +PROVIDER_RLY_GASPRICE=${PROVIDER_RLY_GASPRICE:-0stake} +CONSUMER_RLY_GASPRICE=${CONSUMER_RLY_GASPRICE:-0stake} +PROVIDER_RLY_CLIENTID=${PROVIDER_RLY_CLIENTID:-07-tendermint-0} +CONSUMER_RLY_CLIENTID=${CONSUMER_RLY_CLIENTID:-07-tendermint-0} +RLY_SRC_PORT=${RLY_SRC_PORT:-transfer} +RLY_DST_PORT=${RLY_DST_PORT:-transfer} +RLY_ORDERING=${RLY_ORDERING:-unordered} +RLY_CHANNEL_VERSION=${RLY_CHANNEL_VERSION:-1} +RLY_DEBUG=${RLY_DEBUG:-false} + +KEYRING=${KEYRING:-file} +TESTKEYRING="test" +KEYALGO=${KEYALGO:-"secp256k1"} +KEYNAME=relayer +KEYPASSWD=${KEYPASSWD:-"passw0rdK3y"} + +SESSION_STAMP=RLY_`date +%m%d%Y%H%M%S` +TMPDIR=/tmp +LOGDIR=/tmp +LOGFILE=${LOGDIR}/${SESSION_STAMP}.log +ERRFILE=${LOGDIR}/${SESSION_STAMP}.err + +Logger() +{ + MSG=$1 + echo "`date` $MSG" >> $LOGFILE + echo "`date` $MSG" +} + +CheckRetcode() +{ + # ERRTYPE 1 = HARD ERROR (Exit script), ERRTYPE <> 1 = SOFT ERROR (Report and Continue) + local RETCODE=$1 + local ERRTYPE=$2 + local MSG=$3 + if [ $RETCODE -ne 0 ]; + then + if [ $ERRTYPE -eq 1 ]; + then + Logger "$MSG" + exit 1 + else + Logger "$MSG" + fi + else + Logger "Return code was $RETCODE. Success!" + fi +} + +ValidateEnvVar() +{ + local ENVVAR=$1 + Logger "Validating environment variable $ENVVAR" + local EXITIFUNSET=${2:-1} # exit if env var is not set. Pass 1 for true, 0 for false i.e. if 0, script will continue executing. Default: True (exit) + local ECHOVAL=${3:-1} # echo the value of the variable in a log entry. Pass 1 = true, 0 = false. Default: True (will echo) + if [[ -z ${!ENVVAR} ]]; + then + Logger "Environment variable $ENVVAR is not set" + if [ $EXITIFUNSET -eq 1 ]; + then + Logger "Exiting in error as environment variable $ENVVAR is not set" + exit 1 + else + Logger "Continuing even though environment variable $ENVVAR is not set" + fi + fi + if [ $ECHOVAL -eq 1 ]; + then + Logger "Environment variable $ENVVAR is set to ${!ENVVAR}" + fi + Logger "Finished validating environment variable $ENVVAR" +} + +ValidateAndEchoEnvVars() +{ + Logger "Starting function ValidateAndEchoEnvVars" + ValidateEnvVar PROVIDER_CHAIN + ValidateEnvVar CONSUMER_CHAIN + ValidateEnvVar PROVIDER_CHAINID + ValidateEnvVar CONSUMER_CHAINID + ValidateEnvVar PROVIDER_RLY_MNEMONIC 1 0 + ValidateEnvVar CONSUMER_RLY_MNEMONIC 1 0 + ValidateEnvVar PROVIDER_RPC_ADDRESS + ValidateEnvVar CONSUMER_RPC_ADDRESS + ValidateEnvVar PROVIDER_RLY_GASPRICE + ValidateEnvVar CONSUMER_RLY_GASPRICE + ValidateEnvVar PROVIDER_RLY_CLIENTID + ValidateEnvVar CONSUMER_RLY_CLIENTID + ValidateEnvVar RLY_SRC_PORT + ValidateEnvVar RLY_DST_PORT + ValidateEnvVar RLY_ORDERING + ValidateEnvVar RLY_CHANNEL_VERSION + ValidateEnvVar RLY_DEBUG + ValidateEnvVar KEYRING + ValidateEnvVar SLEEPTIME 0 1 + ValidateEnvVar KEYALGO + ValidateEnvVar KEYPASSWD + ValidateEnvVar TMPDIR + Logger "Exiting function ValidateAndEchoEnvVars" +} + +InitRelayer() +{ + Logger "Starting function InitRelayer" + rm -rf .relayer 1>> $LOGFILE 2>> $ERRFILE + rly config init --home .relayer 1>> $LOGFILE 2>> $ERRFILE + RETCODE=$? + CheckRetcode $RETCODE 1 "Could not initialize relayer. Return code was $RETCODE. Exiting" + Logger "Exiting function InitRelayer" +} + +GenerateChainFiles() +{ + Logger "Starting function GenerateChainFiles" + jq --arg KEY $KEYNAME '.value.key = $KEY' /root/provider-rly.json > /root/provider-rly-tmp.json && mv /root/provider-rly-tmp.json /root/provider-rly.json + jq --arg CHAINID $PROVIDER_CHAINID '.value."chain-id" = $CHAINID' /root/provider-rly.json > /root/provider-rly-tmp.json && mv /root/provider-rly-tmp.json /root/provider-rly.json + jq --arg RPCADDR $PROVIDER_RPC_ADDRESS '.value."rpc-addr" = $RPCADDR' /root/provider-rly.json > /root/provider-rly-tmp.json && mv /root/provider-rly-tmp.json /root/provider-rly.json + jq --arg KEYRING $KEYRING '.value."keyring-backend" = $KEYRING' /root/provider-rly.json > /root/provider-rly-tmp.json && mv /root/provider-rly-tmp.json /root/provider-rly.json + jq --argjson DEBUG $RLY_DEBUG '.value.debug = $DEBUG' /root/provider-rly.json > /root/provider-rly-tmp.json && mv /root/provider-rly-tmp.json /root/provider-rly.json + jq --arg GAS $PROVIDER_RLY_GASPRICE '.value."gas-prices" = $GAS' /root/provider-rly.json > /root/provider-rly-tmp.json && mv /root/provider-rly-tmp.json /root/provider-rly.json + + jq --arg KEY $KEYNAME '.value.key = $KEY' /root/consumer-rly.json > /root/consumer-rly-tmp.json && mv /root/consumer-rly-tmp.json /root/consumer-rly.json + jq --arg CHAINID $CONSUMER_CHAINID '.value."chain-id" = $CHAINID' /root/consumer-rly.json > /root/consumer-rly-tmp.json && mv /root/consumer-rly-tmp.json /root/consumer-rly.json + jq --arg RPCADDR $CONSUMER_RPC_ADDRESS '.value."rpc-addr" = $RPCADDR' /root/consumer-rly.json > /root/consumer-rly-tmp.json && mv /root/consumer-rly-tmp.json /root/consumer-rly.json + jq --arg KEYRING $KEYRING '.value."keyring-backend" = $KEYRING' /root/consumer-rly.json > /root/consumer-rly-tmp.json && mv /root/consumer-rly-tmp.json /root/consumer-rly.json + jq --argjson DEBUG $RLY_DEBUG '.value.debug = $DEBUG' /root/consumer-rly.json > /root/consumer-rly-tmp.json && mv /root/consumer-rly-tmp.json /root/consumer-rly.json + jq --arg GAS $CONSUMER_RLY_GASPRICE '.value."gas-prices" = $GAS' /root/consumer-rly.json > /root/consumer-rly-tmp.json && mv /root/consumer-rly-tmp.json /root/consumer-rly.json + Logger "Exiting function GenerateChainFiles" +} + +ConfigRelayer() +{ + Logger "Starting function ConfigRelayer" + local PATHNAME=pc + rly chains add $PROVIDER_CHAIN --file /root/provider-rly.json --home .relayer #1>> $LOGFILE 2>> $ERRFILE + RETCODE=$? + CheckRetcode $RETCODE 1 "Could not add chain $PROVIDER_CHAINID to relayer config. Return code was $RETCODE. Exiting" + rly chains add $CONSUMER_CHAIN --file /root/consumer-rly.json --home .relayer #1>> $LOGFILE 2>> $ERRFILE RETCODE=$? - if [[ ${RETCODE} -eq 0 ]]; then - break + CheckRetcode $RETCODE 1 "Could not add chain $CONSUMER_CHAINID to relayer config. Return code was $RETCODE. Exiting" + Logger "Added both provider and consumer chains" + Logger "Restoring keys from provided mnemonics" + if [[ "$KEYRING" == "file" ]]; + then + (echo $KEYPASSWD; echo $KEYPASSWD) | rly keys restore $PROVIDER_CHAIN relayer "${PROVIDER_RLY_MNEMONIC}" --home .relayer #1>> $LOGFILE 2>> $ERRFILE + RETCODE=$? + CheckRetcode $RETCODE 1 "Could not restore keys from mnemonic for chain $PROVIDER_CHAINID. Return code was $RETCODE. Exiting" + (echo $KEYPASSWD; echo $KEYPASSWD) | rly keys restore $CONSUMER_CHAIN relayer "${CONSUMER_RLY_MNEMONIC}" --home .relayer #1>> $LOGFILE 2>> $ERRFILE + RETCODE=$? + CheckRetcode $RETCODE 1 "Could not restore keys from mnemonic for chain $CONSUMER_CHAINID. Return code was $RETCODE. Exiting" + else + rly keys restore $PROVIDER_CHAIN relayer "${PROVIDER_RLY_MNEMONIC}" --home .relayer #1>> $LOGFILE 2>> $ERRFILE + RETCODE=$? + CheckRetcode $RETCODE 1 "Could not restore keys from mnemonic for chain $PROVIDER_CHAINID. Return code was $RETCODE. Exiting" + rly keys restore $CONSUMER_CHAIN relayer "${CONSUMER_RLY_MNEMONIC}" --home .relayer #1>> $LOGFILE 2>> $ERRFILE + RETCODE=$? + CheckRetcode $RETCODE 1 "Could not restore keys from mnemonic for chain $CONSUMER_CHAINID. Return code was $RETCODE. Exiting" fi - sleep 5 -done - -(echo $KEYPASSWD; sleep 1; echo $KEYPASSWD) | rly transact link dp - -(echo $KEYPASSWD; sleep 1; echo $KEYPASSWD) | rly start dp + Logger "Created keys" + Logger "Creating relayer paths..." + rly paths new $CONSUMER_CHAINID $PROVIDER_CHAINID $PATHNAME --home .relayer #1>> $LOGFILE 2>> $ERRFILE + RETCODE=$? + CheckRetcode $RETCODE 1 "Could not create a new path for chains $PROVIDER_CHAINID and $CONSUMER_CHAINID. Return code was $RETCODE. Exiting" + Logger "New path $PATHNAME successfully created for chains $PROVIDER_CHAINID and $CONSUMER_CHAINID" + rly paths update $PATHNAME --src-client-id $CONSUMER_RLY_CLIENTID --dst-client-id $PROVIDER_RLY_CLIENTID --home .relayer #1>> $LOGFILE 2>> $ERRFILE + RETCODE=$? + CheckRetcode $RETCODE 1 "Could not update the path with source/destination client-id for chains $PROVIDER_CHAINID and $CONSUMER_CHAINID. Return code was $RETCODE. Exiting" + Logger "Path $PATHNAME successfully updated for chains $PROVIDER_CHAINID and $CONSUMER_CHAINID" + Logger "Exiting function ConfigRelayer" +} + +LinkRelayer() +{ + Logger "Starting function LinkRelayer" + # Logger "Debug sleep" + # sleep 600 + Logger "Now connecting $PROVIDER_CHAIN and $CONSUMER_CHAIN" + (echo $KEYPASSWD; sleep 1; echo $KEYPASSWD) | rly transact link pc --home .relayer --src-port $RLY_SRC_PORT --dst-port $RLY_DST_PORT --order $RLY_ORDERING --version $RLY_CHANNEL_VERSION #1>> $LOGFILE 2>> $ERRFILE + RETCODE=$? + CheckRetcode $RETCODE 1 "Could not create a connection between chains $PROVIDER_CHAINID and $CONSUMER_CHAINID. Return code was $RETCODE. Exiting" + Logger "Chains $PROVIDER_CHAINID and $CONSUMER_CHAINID successfully connected" + Logger "Exiting function LinkRelayer" +} + +CheckLaunchReadiness() +{ + Logger "Starting function CheckLaunchReadiness" + # we want to make sure that chainlet is up and running + while true + do + rly q node-state $PROVIDER_CHAIN --home .relayer #1>> $LOGFILE 2>> $ERRFILE + RETCODEP=$? + rly q node-state $CONSUMER_CHAIN --home .relayer #1>> $LOGFILE 2>> $ERRFILE + RETCODEC=$? + if [[ ${RETCODEP} -eq 0 && ${RETCODEC} -eq 0 ]]; then + break + fi + Logger "DEBUG Provider chain $PROVIDER_CHAINID shows $RETCODEP and consumer chain $CONSUMER_CHAINID shows $RETCODEC" + Logger "Waiting for provider chain $PROVIDER_CHAINID and consumer chain $CONSUMER_CHAINID to come online" + sleep $SLEEPTIME + done + Logger "Both provider and consumer chains are online. Continuing" + Logger "Exiting function CheckLaunchReadiness" +} + + +## MAIN +ValidateAndEchoEnvVars +InitRelayer +GenerateChainFiles +ConfigRelayer +CheckLaunchReadiness +LinkRelayer +rly start pc --home .relayer diff --git a/saga.Dockerfile b/saga.Dockerfile index f779b9743..2b7de22c5 100644 --- a/saga.Dockerfile +++ b/saga.Dockerfile @@ -23,6 +23,8 @@ COPY --from=build-env /root/rly/start-rly.sh /root/start-rly.sh RUN mkdir -p /root/tmp COPY --from=build-env /root/rly/sevm_111-1.json.example /root/tmp/ COPY --from=build-env /root/rly/sevm_111-2.json.example /root/tmp/ +COPY --from=build-env /root/rly/sample-rly.json /root/provider-rly.json +COPY --from=build-env /root/rly/sample-rly.json /root/consumer-rly.json RUN chmod -R 755 /root/start-rly.sh From a667a46066429fc7a51532bdad3fd6e85858173f Mon Sep 17 00:00:00 2001 From: Ashish Chandra Date: Mon, 28 Aug 2023 17:07:40 -0500 Subject: [PATCH 2/4] Re-added out/err redirect to log files --- rly/start-rly.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/rly/start-rly.sh b/rly/start-rly.sh index 28fd7d5ee..922ed4311 100755 --- a/rly/start-rly.sh +++ b/rly/start-rly.sh @@ -141,37 +141,37 @@ ConfigRelayer() { Logger "Starting function ConfigRelayer" local PATHNAME=pc - rly chains add $PROVIDER_CHAIN --file /root/provider-rly.json --home .relayer #1>> $LOGFILE 2>> $ERRFILE + rly chains add $PROVIDER_CHAIN --file /root/provider-rly.json --home .relayer 1>> $LOGFILE 2>> $ERRFILE RETCODE=$? CheckRetcode $RETCODE 1 "Could not add chain $PROVIDER_CHAINID to relayer config. Return code was $RETCODE. Exiting" - rly chains add $CONSUMER_CHAIN --file /root/consumer-rly.json --home .relayer #1>> $LOGFILE 2>> $ERRFILE + rly chains add $CONSUMER_CHAIN --file /root/consumer-rly.json --home .relayer 1>> $LOGFILE 2>> $ERRFILE RETCODE=$? CheckRetcode $RETCODE 1 "Could not add chain $CONSUMER_CHAINID to relayer config. Return code was $RETCODE. Exiting" Logger "Added both provider and consumer chains" Logger "Restoring keys from provided mnemonics" if [[ "$KEYRING" == "file" ]]; then - (echo $KEYPASSWD; echo $KEYPASSWD) | rly keys restore $PROVIDER_CHAIN relayer "${PROVIDER_RLY_MNEMONIC}" --home .relayer #1>> $LOGFILE 2>> $ERRFILE + (echo $KEYPASSWD; echo $KEYPASSWD) | rly keys restore $PROVIDER_CHAIN relayer "${PROVIDER_RLY_MNEMONIC}" --home .relayer 1>> $LOGFILE 2>> $ERRFILE RETCODE=$? CheckRetcode $RETCODE 1 "Could not restore keys from mnemonic for chain $PROVIDER_CHAINID. Return code was $RETCODE. Exiting" - (echo $KEYPASSWD; echo $KEYPASSWD) | rly keys restore $CONSUMER_CHAIN relayer "${CONSUMER_RLY_MNEMONIC}" --home .relayer #1>> $LOGFILE 2>> $ERRFILE + (echo $KEYPASSWD; echo $KEYPASSWD) | rly keys restore $CONSUMER_CHAIN relayer "${CONSUMER_RLY_MNEMONIC}" --home .relayer 1>> $LOGFILE 2>> $ERRFILE RETCODE=$? CheckRetcode $RETCODE 1 "Could not restore keys from mnemonic for chain $CONSUMER_CHAINID. Return code was $RETCODE. Exiting" else - rly keys restore $PROVIDER_CHAIN relayer "${PROVIDER_RLY_MNEMONIC}" --home .relayer #1>> $LOGFILE 2>> $ERRFILE + rly keys restore $PROVIDER_CHAIN relayer "${PROVIDER_RLY_MNEMONIC}" --home .relayer 1>> $LOGFILE 2>> $ERRFILE RETCODE=$? CheckRetcode $RETCODE 1 "Could not restore keys from mnemonic for chain $PROVIDER_CHAINID. Return code was $RETCODE. Exiting" - rly keys restore $CONSUMER_CHAIN relayer "${CONSUMER_RLY_MNEMONIC}" --home .relayer #1>> $LOGFILE 2>> $ERRFILE + rly keys restore $CONSUMER_CHAIN relayer "${CONSUMER_RLY_MNEMONIC}" --home .relayer 1>> $LOGFILE 2>> $ERRFILE RETCODE=$? CheckRetcode $RETCODE 1 "Could not restore keys from mnemonic for chain $CONSUMER_CHAINID. Return code was $RETCODE. Exiting" fi Logger "Created keys" Logger "Creating relayer paths..." - rly paths new $CONSUMER_CHAINID $PROVIDER_CHAINID $PATHNAME --home .relayer #1>> $LOGFILE 2>> $ERRFILE + rly paths new $CONSUMER_CHAINID $PROVIDER_CHAINID $PATHNAME --home .relayer 1>> $LOGFILE 2>> $ERRFILE RETCODE=$? CheckRetcode $RETCODE 1 "Could not create a new path for chains $PROVIDER_CHAINID and $CONSUMER_CHAINID. Return code was $RETCODE. Exiting" Logger "New path $PATHNAME successfully created for chains $PROVIDER_CHAINID and $CONSUMER_CHAINID" - rly paths update $PATHNAME --src-client-id $CONSUMER_RLY_CLIENTID --dst-client-id $PROVIDER_RLY_CLIENTID --home .relayer #1>> $LOGFILE 2>> $ERRFILE + rly paths update $PATHNAME --src-client-id $CONSUMER_RLY_CLIENTID --dst-client-id $PROVIDER_RLY_CLIENTID --home .relayer 1>> $LOGFILE 2>> $ERRFILE RETCODE=$? CheckRetcode $RETCODE 1 "Could not update the path with source/destination client-id for chains $PROVIDER_CHAINID and $CONSUMER_CHAINID. Return code was $RETCODE. Exiting" Logger "Path $PATHNAME successfully updated for chains $PROVIDER_CHAINID and $CONSUMER_CHAINID" @@ -184,7 +184,7 @@ LinkRelayer() # Logger "Debug sleep" # sleep 600 Logger "Now connecting $PROVIDER_CHAIN and $CONSUMER_CHAIN" - (echo $KEYPASSWD; sleep 1; echo $KEYPASSWD) | rly transact link pc --home .relayer --src-port $RLY_SRC_PORT --dst-port $RLY_DST_PORT --order $RLY_ORDERING --version $RLY_CHANNEL_VERSION #1>> $LOGFILE 2>> $ERRFILE + (echo $KEYPASSWD; sleep 1; echo $KEYPASSWD) | rly transact link pc --home .relayer --src-port $RLY_SRC_PORT --dst-port $RLY_DST_PORT --order $RLY_ORDERING --version $RLY_CHANNEL_VERSION 1>> $LOGFILE 2>> $ERRFILE RETCODE=$? CheckRetcode $RETCODE 1 "Could not create a connection between chains $PROVIDER_CHAINID and $CONSUMER_CHAINID. Return code was $RETCODE. Exiting" Logger "Chains $PROVIDER_CHAINID and $CONSUMER_CHAINID successfully connected" @@ -197,9 +197,9 @@ CheckLaunchReadiness() # we want to make sure that chainlet is up and running while true do - rly q node-state $PROVIDER_CHAIN --home .relayer #1>> $LOGFILE 2>> $ERRFILE + rly q node-state $PROVIDER_CHAIN --home .relayer 1>> $LOGFILE 2>> $ERRFILE RETCODEP=$? - rly q node-state $CONSUMER_CHAIN --home .relayer #1>> $LOGFILE 2>> $ERRFILE + rly q node-state $CONSUMER_CHAIN --home .relayer 1>> $LOGFILE 2>> $ERRFILE RETCODEC=$? if [[ ${RETCODEP} -eq 0 && ${RETCODEC} -eq 0 ]]; then break From 7a657360d75f11d96fe0870844e4cf0a2c5854a2 Mon Sep 17 00:00:00 2001 From: Ashish Chandra Date: Wed, 30 Aug 2023 10:03:35 -0500 Subject: [PATCH 3/4] Add multiple tries for linking. Upd chain waiting --- rly/start-rly.sh | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/rly/start-rly.sh b/rly/start-rly.sh index 922ed4311..eeb305d80 100755 --- a/rly/start-rly.sh +++ b/rly/start-rly.sh @@ -181,12 +181,26 @@ ConfigRelayer() LinkRelayer() { Logger "Starting function LinkRelayer" - # Logger "Debug sleep" - # sleep 600 - Logger "Now connecting $PROVIDER_CHAIN and $CONSUMER_CHAIN" - (echo $KEYPASSWD; sleep 1; echo $KEYPASSWD) | rly transact link pc --home .relayer --src-port $RLY_SRC_PORT --dst-port $RLY_DST_PORT --order $RLY_ORDERING --version $RLY_CHANNEL_VERSION 1>> $LOGFILE 2>> $ERRFILE - RETCODE=$? - CheckRetcode $RETCODE 1 "Could not create a connection between chains $PROVIDER_CHAINID and $CONSUMER_CHAINID. Return code was $RETCODE. Exiting" + local cnt=0 + local RETCODE_LNK=0 + Logger "Now connecting $PROVIDER_CHAIN and $CONSUMER_CHAIN. This can take a few minutes..." + until [ $cnt -ge 3 ]; + do + (echo $KEYPASSWD; sleep 1; echo $KEYPASSWD) | rly transact link pc --home .relayer --src-port $RLY_SRC_PORT --dst-port $RLY_DST_PORT --order $RLY_ORDERING --version $RLY_CHANNEL_VERSION 1>> $LOGFILE 2>> $ERRFILE + RETCODE_LNK=$? + Logger "DEBUG RETCODE is $RETCODE_LNK" + if [ $RETCODE_LNK -ne 0 ]; + then + cnt=$(( cnt + 1 )) + Logger "DEBUG cnt = $cnt" + Logger "DEBUG error is `tail -15 $ERRFILE`" + sleep 1 + else + Logger "DEBUG break invoked" + break + fi + done + CheckRetcode $RETCODE_LNK 1 "Could not create a connection between chains $PROVIDER_CHAINID and $CONSUMER_CHAINID after 3 attempts. Exiting" Logger "Chains $PROVIDER_CHAINID and $CONSUMER_CHAINID successfully connected" Logger "Exiting function LinkRelayer" } @@ -204,11 +218,24 @@ CheckLaunchReadiness() if [[ ${RETCODEP} -eq 0 && ${RETCODEC} -eq 0 ]]; then break fi - Logger "DEBUG Provider chain $PROVIDER_CHAINID shows $RETCODEP and consumer chain $CONSUMER_CHAINID shows $RETCODEC" Logger "Waiting for provider chain $PROVIDER_CHAINID and consumer chain $CONSUMER_CHAINID to come online" sleep $SLEEPTIME done - Logger "Both provider and consumer chains are online. Continuing" + Logger "Ensuring both provider and consumer chains are producing blocks" + local BLOCKNUM=3 # Height should be at least 2 in order to link the chains via IBC + while true + do + rly q header $PROVIDER_CHAIN $BLOCKNUM --home .relayer 1>> $LOGFILE 2>> $ERRFILE + RETCODEP=$? + rly q header $CONSUMER_CHAIN $BLOCKNUM --home .relayer 1>> $LOGFILE 2>> $ERRFILE + RETCODEC=$? + if [[ ${RETCODEP} -eq 0 && ${RETCODEC} -eq 0 ]]; then + break + fi + Logger "Waiting for provider chain $PROVIDER_CHAINID and consumer chain $CONSUMER_CHAINID to produce blocks" + sleep $SLEEPTIME + done + Logger "Both provider and consumer chains are online and producing blocks. Continuing" Logger "Exiting function CheckLaunchReadiness" } From 92ef9f388d9184ef70141a766677377b530642b8 Mon Sep 17 00:00:00 2001 From: Ashish Chandra Date: Wed, 6 Sep 2023 11:32:19 -0500 Subject: [PATCH 4/4] Minor fix to Github action. Update rly start --- .github/workflows/docker-publish.yaml | 2 +- rly/start-rly.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-publish.yaml b/.github/workflows/docker-publish.yaml index 856c65b53..1461b6c89 100644 --- a/.github/workflows/docker-publish.yaml +++ b/.github/workflows/docker-publish.yaml @@ -60,4 +60,4 @@ jobs: GITHUB_USER=${{ secrets.GH_USER }} GITHUB_TOKEN=${{ secrets.GH_ACCESS_TOKEN }} platforms: linux/amd64 - tags: sagaxyz/go-relayer:${{ steps.meta.outputs.tag }}, sagaxyz/spc:latest + tags: sagaxyz/go-relayer:${{ steps.meta.outputs.tag }}, sagaxyz/go-relayer:latest diff --git a/rly/start-rly.sh b/rly/start-rly.sh index eeb305d80..8f9df40ca 100755 --- a/rly/start-rly.sh +++ b/rly/start-rly.sh @@ -247,4 +247,4 @@ GenerateChainFiles ConfigRelayer CheckLaunchReadiness LinkRelayer -rly start pc --home .relayer +(echo $KEYPASSWD; sleep 1; echo $KEYPASSWD) | rly start pc --home .relayer