Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add ibc setup scripts #30

Merged
merged 8 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmd/rollappd/rollappd
scripts/ibc/*.json
build/
release/
.idea/
Expand Down
41 changes: 39 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
16 changes: 16 additions & 0 deletions scripts/config.sh
Original file line number Diff line number Diff line change
@@ -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"
17 changes: 17 additions & 0 deletions scripts/ibc/hub.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
17 changes: 17 additions & 0 deletions scripts/ibc/rollapp.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
93 changes: 93 additions & 0 deletions scripts/ibc/setup_ibc.sh
Original file line number Diff line number Diff line change
@@ -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"
10 changes: 5 additions & 5 deletions scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions scripts/settlement/register_rollapp_to_hub.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion scripts/settlement/register_sequencer_to_hub.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/bash

EXECUTABLE="rollappd"
ROLLAPP_CHAIN_ID="demo-dymension-rollapp"
KEYRING_PATH="$HOME/.rollapp/sequencer_keys"
KEY_NAME_SEQUENCER="sequencer"

Expand Down