From 7b9d354694a2afa0aeb65bc42294dfccb00f90a6 Mon Sep 17 00:00:00 2001 From: Michael Tsitrin <114929630+mtsitrin@users.noreply.github.com> Date: Tue, 15 Aug 2023 15:47:02 +0300 Subject: [PATCH] chore: add ibc setup scripts (#30) --- .gitignore | 1 + README.md | 41 +++++++- scripts/config.sh | 16 ++++ scripts/ibc/hub.json | 17 ++++ scripts/ibc/rollapp.json | 17 ++++ scripts/ibc/setup_ibc.sh | 93 +++++++++++++++++++ scripts/init.sh | 10 +- scripts/settlement/register_rollapp_to_hub.sh | 2 - .../settlement/register_sequencer_to_hub.sh | 1 - 9 files changed, 188 insertions(+), 10 deletions(-) create mode 100644 scripts/config.sh create mode 100644 scripts/ibc/hub.json create mode 100644 scripts/ibc/rollapp.json create mode 100644 scripts/ibc/setup_ibc.sh diff --git a/.gitignore b/.gitignore index 95486bb..99fa5c4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ cmd/rollappd/rollappd +scripts/ibc/*.json build/ release/ .idea/ diff --git a/README.md b/README.md index 35589f1..0f53688 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,16 @@ make install ### Initial configuration -This will initialize the rollapp: +export the following variables: + +```shell +export ROLLAPP_CHAIN_ID="demo-dymension-rollapp" +export KEY_NAME_ROLLAPP="rol-user" +export DENOM="urax" +export MONIKER="$ROLLAPP_CHAIN_ID-sequencer" +``` + +And initialize the rollapp: ```shell sh scripts/init.sh @@ -63,7 +72,7 @@ SEQUENCER_ADDR=`dymd keys show sequencer --address --keyring-backend test --keyr fund the sequencer account ```shell -dymd tx bank send local-user $SEQUENCER_ADDR 10000000000udym --keyring-backend test +dymd tx bank send local-user $SEQUENCER_ADDR 10000000000000000000000udym --keyring-backend test ``` ### Register rollapp on settlement @@ -93,6 +102,34 @@ settlement_layer = "dymension" rollappd start ``` +## Setup IBC between rollapp and local dymension hub node + +### Install dymension relayer + +```shell +$ git clone https://github.com/dymensionxyz/dymension-relayer.git +$ git checkout v0.1.0-relayer-v0.2.0-rc3 +$ cd dymension-relayer && make install +``` + +### Establish IBC channel + +while the rollapp and the local dymension hub node running, run: + +```shell +sh scripts/ibc/setup_ibc.sh +``` + +After successful run, the new established channels will be shown + +### run the relayer + +```shell +rly start hub-rollapp +``` + + + ## Developers guide TODO diff --git a/scripts/config.sh b/scripts/config.sh new file mode 100644 index 0000000..82b2b9d --- /dev/null +++ b/scripts/config.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Function to set and log environment variable +set_env_var() { + local var_name="$1" + local value="$2" + + export "$var_name"="$value" + echo "Exported $var_name: $value" +} + +# Set and log environment variables +set_env_var ROLLAPP_CHAIN_ID "demo-dymension-rollapp" +set_env_var KEY_NAME_ROLLAPP "rol-user" +set_env_var DENOM "urax" +set_env_var MONIKER "$ROLLAPP_CHAIN_ID-sequencer" diff --git a/scripts/ibc/hub.json b/scripts/ibc/hub.json new file mode 100644 index 0000000..86c3824 --- /dev/null +++ b/scripts/ibc/hub.json @@ -0,0 +1,17 @@ +{ + "type": "cosmos", + "value": { + "key": "relayer-hub-key", + "chain-id": "dymension_100-1", + "rpc-addr": "http://127.0.0.1:36657", + "account-prefix": "dym", + "keyring-backend": "test", + "gas-adjustment": 1.2, + "gas-prices": "0.25udym", + "debug": true, + "timeout": "10s", + "output-format": "json", + "sign-mode": "direct", + "client-type": "07-tendermint" + } +} diff --git a/scripts/ibc/rollapp.json b/scripts/ibc/rollapp.json new file mode 100644 index 0000000..a9ce2b1 --- /dev/null +++ b/scripts/ibc/rollapp.json @@ -0,0 +1,17 @@ +{ + "type": "cosmos", + "value": { + "key": "relayer-rollapp-key", + "chain-id": "demo-dymension-rollapp", + "rpc-addr": "http://127.0.0.1:26657", + "account-prefix": "rol", + "keyring-backend": "test", + "gas-adjustment": 1.2, + "gas-prices": "0.0urax", + "debug": true, + "timeout": "10s", + "output-format": "json", + "sign-mode": "direct", + "client-type": "01-dymint" + } +} diff --git a/scripts/ibc/setup_ibc.sh b/scripts/ibc/setup_ibc.sh new file mode 100644 index 0000000..c601d4e --- /dev/null +++ b/scripts/ibc/setup_ibc.sh @@ -0,0 +1,93 @@ +#!/bin/bash + +BASEDIR=$(dirname "$0") + +IBC_PORT=transfer +IBC_VERSION=ics20-1 + +RELAYER_EXECUTABLE="rly" + +# settlement config +SETTLEMENT_EXECUTABLE="dymd" +SETTLEMENT_CHAIN_ID="dymension_100-1" +SETTLEMENT_KEY_NAME_GENESIS="local-user" + +EXECUTABLE="rollappd" + +RELAYER_KEY_FOR_ROLLAP="relayer-rollapp-key" +RELAYER_KEY_FOR_HUB="relayer-hub-key" +RELAYER_PATH="hub-rollapp" +ROLLAPP_RPC_FOR_RELAYER="http://127.0.0.1:26657" +SETTLEMENT_RPC_FOR_RELAYER="http://127.0.0.1:36657" + + +if ! command -v $RELAYER_EXECUTABLE >/dev/null; then + echo "$RELAYER_EXECUTABLE does not exist" + echo "please run make install of github.com/dymensionxyz/dymension-relayer" + exit 1 +fi + +# --------------------------------- rly init --------------------------------- # +RLY_PATH="$HOME/.relayer" +RLY_CONFIG_FILE="$RLY_PATH/config/config.yaml" +ROLLAPP_IBC_CONF_FILE="$BASEDIR/rollapp.json" +HUB_IBC_CONF_FILE="$BASEDIR/hub.json" + +if [ -f "$RLY_CONFIG_FILE" ]; then + printf "======================================================================================================\n" + echo "A rly config file already exists. Overwrite? (y/N)" + printf "======================================================================================================\n" + read -r answer + if [[ "$answer" == "Y" || "$answer" == "y" ]]; then + rm -rf "$RLY_PATH" + fi +fi + +echo '# -------------------------- initializing rly config ------------------------- #' +rly config init + +echo '# ------------------------- adding chains to rly config ------------------------- #' +tmp=$(mktemp) + +jq --arg key "$RELAYER_KEY_FOR_ROLLAP" '.value.key = $key' $ROLLAPP_IBC_CONF_FILE > "$tmp" && mv "$tmp" $ROLLAPP_IBC_CONF_FILE +jq --arg chain "$ROLLAPP_CHAIN_ID" '.value."chain-id" = $chain' $ROLLAPP_IBC_CONF_FILE > "$tmp" && mv "$tmp" $ROLLAPP_IBC_CONF_FILE +jq --arg rpc "$ROLLAPP_RPC_FOR_RELAYER" '.value."rpc-addr" = $rpc' $ROLLAPP_IBC_CONF_FILE > "$tmp" && mv "$tmp" $ROLLAPP_IBC_CONF_FILE +jq --arg denom "0.0$DENOM" '.value."gas-prices" = $denom' $ROLLAPP_IBC_CONF_FILE > "$tmp" && mv "$tmp" $ROLLAPP_IBC_CONF_FILE + +jq --arg key "$RELAYER_KEY_FOR_HUB" '.value.key = $key' $HUB_IBC_CONF_FILE > "$tmp" && mv "$tmp" $HUB_IBC_CONF_FILE +jq --arg chain "$SETTLEMENT_CHAIN_ID" '.value."chain-id" = $chain' $HUB_IBC_CONF_FILE > "$tmp" && mv "$tmp" $HUB_IBC_CONF_FILE +jq --arg rpc "$SETTLEMENT_RPC_FOR_RELAYER" '.value."rpc-addr" = $rpc' $HUB_IBC_CONF_FILE > "$tmp" && mv "$tmp" $HUB_IBC_CONF_FILE + +rly chains add --file "$ROLLAPP_IBC_CONF_FILE" "$ROLLAPP_CHAIN_ID" +rly chains add --file "$HUB_IBC_CONF_FILE" "$SETTLEMENT_CHAIN_ID" + +echo '# -------------------------------- creating keys ------------------------------- #' +rly keys add "$ROLLAPP_CHAIN_ID" "$RELAYER_KEY_FOR_ROLLAP" +rly keys add "$SETTLEMENT_CHAIN_ID" "$RELAYER_KEY_FOR_HUB" + +RLY_HUB_ADDR=$(rly keys show "$SETTLEMENT_CHAIN_ID") +RLY_ROLLAPP_ADDR=$(rly keys show "$ROLLAPP_CHAIN_ID") + +echo "# ------------------------------- balance of rly account on hub [$RLY_HUB_ADDR]------------------------------ #" +$SETTLEMENT_EXECUTABLE q bank balances "$(rly keys show "$SETTLEMENT_CHAIN_ID")" --node "$SETTLEMENT_RPC_FOR_RELAYER" +echo "From within the hub node: \"$SETTLEMENT_EXECUTABLE tx bank send $SETTLEMENT_KEY_NAME_GENESIS $RLY_HUB_ADDR 100000000000000000000udym --keyring-backend test --broadcast-mode block\"" + +echo "# ------------------------------- balance of rly account on rollapp [$RLY_ROLLAPP_ADDR] ------------------------------ #" +$EXECUTABLE q bank balances "$(rly keys show "$ROLLAPP_CHAIN_ID")" --node "$ROLLAPP_RPC_FOR_RELAYER" +echo "From within the rollapp node: \"$EXECUTABLE tx bank send $KEY_NAME_ROLLAPP $RLY_ROLLAPP_ADDR 100000000$DENOM --keyring-backend test --broadcast-mode block\"" + +echo "waiting to fund accounts. Press to continue..." +read -r answer + +echo '# -------------------------------- creating IBC link ------------------------------- #' +rly chains set-settlement "$SETTLEMENT_CHAIN_ID" +rly paths new "$ROLLAPP_CHAIN_ID" "$SETTLEMENT_CHAIN_ID" "$RELAYER_PATH" --src-port "$IBC_PORT" --dst-port "$IBC_PORT" --version "$IBC_VERSION" +rly transact link -t300s "$RELAYER_PATH" --src-port "$IBC_PORT" --dst-port "$IBC_PORT" --version "$IBC_VERSION" + + +echo '# -------------------------------- IBC channel established ------------------------------- #' +ROLLAPP_CHANNEL_ID=$(rly q channels "$ROLLAPP_CHAIN_ID" | jq -r 'select(.state == "STATE_OPEN") | .channel_id' | tail -n 1) +HUB_CHANNEL_ID=$(rly q channels "$SETTLEMENT_CHAIN_ID" | jq -r 'select(.state == "STATE_OPEN") | .counterparty.channel_id' | tail -n 1) + +echo "ROLLAPP_CHANNEL_ID: $ROLLAPP_CHANNEL_ID" +echo "HUB_CHANNEL_ID: $HUB_CHANNEL_ID" diff --git a/scripts/init.sh b/scripts/init.sh index 5b627d7..133ecf8 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -3,11 +3,6 @@ tmp=$(mktemp) EXECUTABLE="rollappd" ROLLAPP_CHAIN_DIR="$HOME/.rollapp" -DENOM="urax" -MONIKER="rollapp-sequencer" -ROLLAPP_CHAIN_ID="demo-dymension-rollapp" - -KEY_NAME_ROLLAPP="rol-user" set_denom() { denom=$1 @@ -35,6 +30,11 @@ if ! command -v $EXECUTABLE >/dev/null; then exit 1 fi +if [ -z "$ROLLAPP_CHAIN_ID" ]; then + echo "ROLLAPP_CHAIN_ID is not set" + exit 1 +fi + # Verify that a genesis file doesn't exists for the dymension chain if [ -f "$GENESIS_FILE" ]; then printf "\n======================================================================================================\n" diff --git a/scripts/settlement/register_rollapp_to_hub.sh b/scripts/settlement/register_rollapp_to_hub.sh index 5c6a350..dbe17f8 100644 --- a/scripts/settlement/register_rollapp_to_hub.sh +++ b/scripts/settlement/register_rollapp_to_hub.sh @@ -1,9 +1,7 @@ #!/bin/bash -ROLLAPP_CHAIN_ID="demo-dymension-rollapp" KEYRING_PATH="$HOME/.rollapp/sequencer_keys" KEY_NAME_SEQUENCER="sequencer" - MAX_SEQUENCERS=5 #Register rollapp diff --git a/scripts/settlement/register_sequencer_to_hub.sh b/scripts/settlement/register_sequencer_to_hub.sh index 057204f..68627c5 100644 --- a/scripts/settlement/register_sequencer_to_hub.sh +++ b/scripts/settlement/register_sequencer_to_hub.sh @@ -1,7 +1,6 @@ #!/bin/bash EXECUTABLE="rollappd" -ROLLAPP_CHAIN_ID="demo-dymension-rollapp" KEYRING_PATH="$HOME/.rollapp/sequencer_keys" KEY_NAME_SEQUENCER="sequencer"