From 349bb7cf51b954aba087f951bdce02f914d32d6c Mon Sep 17 00:00:00 2001 From: "bcdev.tools" <153984575+0xbcdev@users.noreply.github.com> Date: Fri, 12 Apr 2024 04:42:23 +0700 Subject: [PATCH 1/2] chores(deps): bumps `block-explorer-rpc-cosmos v1.0.3` & `wasm-block-explorer-rpc-cosmos v1.0.3` (#45) --- CHANGELOG.md | 67 +++++++++++++++++++ go.mod | 4 +- go.sum | 8 +-- .../backend/rollapp_wasm_interceptor.go | 18 ++--- rollappd/cmd/start.go | 2 +- 5 files changed, 83 insertions(+), 16 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..a6329c8 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,67 @@ + + + + +# Changelog + +## Unreleased + +### Improvements + +- (deps) [#42](https://github.com/dymensionxyz/rollapp-wasm/issues/42) Bumps `block-explorer-rpc-cosmos v1.0.2` & `wasm-block-explorer-rpc-cosmos v1.0.2` +- (deps) [#45](https://github.com/dymensionxyz/rollapp-wasm/issues/45) Bumps `block-explorer-rpc-cosmos v1.0.3` & `wasm-block-explorer-rpc-cosmos v1.0.3` diff --git a/go.mod b/go.mod index 705f6e7..7285502 100644 --- a/go.mod +++ b/go.mod @@ -5,8 +5,8 @@ go 1.22.1 require ( cosmossdk.io/errors v1.0.0-beta.7 github.com/CosmWasm/wasmd v0.33.0 - github.com/bcdevtools/block-explorer-rpc-cosmos v1.0.2 - github.com/bcdevtools/wasm-block-explorer-rpc-cosmos v1.0.2 + github.com/bcdevtools/block-explorer-rpc-cosmos v1.0.3 + github.com/bcdevtools/wasm-block-explorer-rpc-cosmos v1.0.3 github.com/cosmos/cosmos-sdk v0.46.15 github.com/cosmos/ibc-go/v6 v6.3.0 github.com/dymensionxyz/dymension-rdk v1.2.0-beta diff --git a/go.sum b/go.sum index 6093891..539c166 100644 --- a/go.sum +++ b/go.sum @@ -291,10 +291,10 @@ github.com/aws/aws-sdk-go-v2/service/route53 v1.1.1/go.mod h1:rLiOUrPLW/Er5kRcQ7 github.com/aws/aws-sdk-go-v2/service/sso v1.1.1/go.mod h1:SuZJxklHxLAXgLTc1iFXbEWkXs7QRTQpCLGaKIprQW0= github.com/aws/aws-sdk-go-v2/service/sts v1.1.1/go.mod h1:Wi0EBZwiz/K44YliU0EKxqTCJGUfYTWXrrBwkq736bM= github.com/aws/smithy-go v1.1.0/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB9LgIw= -github.com/bcdevtools/block-explorer-rpc-cosmos v1.0.2 h1:184TNBIvyozlPy12CPgXvmY/YcWN+ur2m0qA5vlHMQY= -github.com/bcdevtools/block-explorer-rpc-cosmos v1.0.2/go.mod h1:AWXHI5ICXK4wB+A59dNddzq5Xdc1wtQDRiIXfMw8cwc= -github.com/bcdevtools/wasm-block-explorer-rpc-cosmos v1.0.2 h1:cGbafUCyRyDtK1eQTKOX2MYnX0KtjJHYOL9AYkEz9gU= -github.com/bcdevtools/wasm-block-explorer-rpc-cosmos v1.0.2/go.mod h1:tWGjBIWpKGiFRnhz2Oa9JjVzeKd3RKbGHWRTVXZAquE= +github.com/bcdevtools/block-explorer-rpc-cosmos v1.0.3 h1:TBC6STStcirdPrUGvsJf4Q07x8lka8Fz24OV5NHFBdA= +github.com/bcdevtools/block-explorer-rpc-cosmos v1.0.3/go.mod h1:AWXHI5ICXK4wB+A59dNddzq5Xdc1wtQDRiIXfMw8cwc= +github.com/bcdevtools/wasm-block-explorer-rpc-cosmos v1.0.3 h1:UPPRh+uXOMgzyXvTQFaojvVF3D24hYaTfNG45iBCy68= +github.com/bcdevtools/wasm-block-explorer-rpc-cosmos v1.0.3/go.mod h1:NX8l/hBC6rjww59X+21QkMyItiyi0A+wqV/a0HW3I5w= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o= diff --git a/ra_wasm_be_rpc/backend/rollapp_wasm_interceptor.go b/ra_wasm_be_rpc/backend/rollapp_wasm_interceptor.go index 536309b..c1beae0 100644 --- a/ra_wasm_be_rpc/backend/rollapp_wasm_interceptor.go +++ b/ra_wasm_be_rpc/backend/rollapp_wasm_interceptor.go @@ -8,37 +8,37 @@ import ( "google.golang.org/grpc/status" ) -var _ berpcbackend.RequestInterceptor = (*RollAppEvmRequestInterceptor)(nil) +var _ berpcbackend.RequestInterceptor = (*RollAppWasmRequestInterceptor)(nil) -type RollAppEvmRequestInterceptor struct { +type RollAppWasmRequestInterceptor struct { beRpcBackend berpcbackend.BackendI backend RollAppWasmBackendI defaultInterceptor berpcbackend.RequestInterceptor } -func NewRollAppEvmRequestInterceptor( +func NewRollAppWasmRequestInterceptor( beRpcBackend berpcbackend.BackendI, backend RollAppWasmBackendI, defaultInterceptor berpcbackend.RequestInterceptor, -) *RollAppEvmRequestInterceptor { - return &RollAppEvmRequestInterceptor{ +) *RollAppWasmRequestInterceptor { + return &RollAppWasmRequestInterceptor{ beRpcBackend: beRpcBackend, backend: backend, defaultInterceptor: defaultInterceptor, } } -func (m *RollAppEvmRequestInterceptor) GetTransactionByHash(hashStr string) (intercepted bool, response berpctypes.GenericBackendResponse, err error) { +func (m *RollAppWasmRequestInterceptor) GetTransactionByHash(hashStr string) (intercepted bool, response berpctypes.GenericBackendResponse, err error) { // handled completely by the default interceptor return m.defaultInterceptor.GetTransactionByHash(hashStr) } -func (m *RollAppEvmRequestInterceptor) GetDenomsInformation() (intercepted, append bool, denoms map[string]string, err error) { +func (m *RollAppWasmRequestInterceptor) GetDenomsInformation() (intercepted, append bool, denoms map[string]string, err error) { // handled completely by the default interceptor return m.defaultInterceptor.GetDenomsInformation() } -func (m *RollAppEvmRequestInterceptor) GetModuleParams(moduleName string) (intercepted bool, res berpctypes.GenericBackendResponse, err error) { +func (m *RollAppWasmRequestInterceptor) GetModuleParams(moduleName string) (intercepted bool, res berpctypes.GenericBackendResponse, err error) { var params any switch moduleName { @@ -67,7 +67,7 @@ func (m *RollAppEvmRequestInterceptor) GetModuleParams(moduleName string) (inter return } -func (m *RollAppEvmRequestInterceptor) GetAccount(accountAddressStr string) (intercepted, append bool, response berpctypes.GenericBackendResponse, err error) { +func (m *RollAppWasmRequestInterceptor) GetAccount(accountAddressStr string) (intercepted, append bool, response berpctypes.GenericBackendResponse, err error) { // handled completely by the default interceptor return m.defaultInterceptor.GetAccount(accountAddressStr) } diff --git a/rollappd/cmd/start.go b/rollappd/cmd/start.go index ac2faa8..7179df3 100644 --- a/rollappd/cmd/start.go +++ b/rollappd/cmd/start.go @@ -468,7 +468,7 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, nodeConfig *d }, false) }, func(backend berpcbackend.BackendI, wasmBeRpcBackend wasmberpcbackend.WasmBackendI) berpcbackend.RequestInterceptor { - return rawberpcbackend.NewRollAppEvmRequestInterceptor( + return rawberpcbackend.NewRollAppWasmRequestInterceptor( backend, rawBeRpcBackend, wasmberpcbackend.NewDefaultRequestInterceptor(backend, wasmBeRpcBackend), From 54bce9ce57ecef4a78a8166d61a4dd283108b7aa Mon Sep 17 00:00:00 2001 From: artpav <19916123+artemijspavlovs@users.noreply.github.com> Date: Fri, 12 Apr 2024 00:42:44 +0300 Subject: [PATCH 2/2] chore: add advanced setup (#44) --- README.md | 33 ++- README.with-advanced-features.md | 244 ++++++++++++++++++ .../add_vesting_accounts_to_genesis_file.sh | 14 + scripts/ibc/setup_ibc.sh | 48 ++-- scripts/init.sh | 24 +- scripts/settlement/add_genesis_accounts.sh | 24 ++ scripts/settlement/generate_denom_metadata.sh | 35 +++ scripts/settlement/register_rollapp_to_hub.sh | 12 +- .../settlement/register_sequencer_to_hub.sh | 13 +- scripts/update_genesis_file.sh | 73 ++++++ 10 files changed, 478 insertions(+), 42 deletions(-) create mode 100644 README.with-advanced-features.md create mode 100644 scripts/add_vesting_accounts_to_genesis_file.sh create mode 100644 scripts/settlement/add_genesis_accounts.sh create mode 100644 scripts/settlement/generate_denom_metadata.sh create mode 100644 scripts/update_genesis_file.sh diff --git a/README.md b/README.md index 692a735..13ef585 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,12 @@ export the following variables: ```shell export ROLLAPP_CHAIN_ID="rollappwasm_1234-1" export KEY_NAME_ROLLAPP="rol-user" -export DENOM="urax" +export BASE_DENOM="awsm" +export DENOM=$(echo "$BASE_DENOM" | sed 's/^.//') export MONIKER="$ROLLAPP_CHAIN_ID-sequencer" + +export ROLLAPP_HOME_DIR="$HOME/.rollapp" +export ROLLAPP_SETTLEMENT_INIT_DIR_PATH="${ROLLAPP_HOME_DIR}/init" ``` And initialize the rollapp: @@ -82,6 +86,20 @@ You should have a running local rollapp! Follow the instructions on [Dymension docs](https://docs.dymension.xyz/validate/dymension/build-dymd?network=localhost) to run local dymension hub node +all scripts are adjusted to use local hub node that's hosted on the default port `localhost:36657`. + +configuration with a remote hub node is also supported, the following variables must be set: + +```shell +export HUB_RPC_ENDPOINT="http://localhost" +export HUB_RPC_PORT="36657" # default: 36657 +export HUB_RPC_URL="http://${HUB_RPC_ENDPOINT}:${HUB_RPC_PORT}" +export HUB_CHAIN_ID="dymension_100-1" + +dymd config chain-id ${HUB_CHAIN_ID} +dymd config node ${HUB_RPC_URL} +``` + ### Create sequencer keys create sequencer key using `dymd` @@ -94,7 +112,13 @@ SEQUENCER_ADDR=`dymd keys show sequencer --address --keyring-backend test --keyr fund the sequencer account ```shell -dymd tx bank send local-user $SEQUENCER_ADDR 10000000000000000000000adym --keyring-backend test --broadcast-mode block --fees 20000000000000adym -y +# this will retrieve the min bond amount from the hub +# if you're using an new address for registering a sequencer, +# you have to account for gas fees so it should the final value should be increased +BOND_AMOUNT="$(dymd q sequencer params -o json | jq -r '.params.min_bond.amount')$(dymd q sequencer params -o jsono | jq -r '.params.min_bond.denom')" +echo $BOND_AMOUNT + +dymd tx bank send local-user dym1978q3tcxwg0ldzgv7ynfr3mzytr9qfsuwjt7tl 100000000000000000000000adym --keyring-backend test --broadcast-mode block --fees 20000000000000adym -y ``` ### Register rollapp on settlement @@ -115,8 +139,9 @@ Modify `dymint.toml` in the chain directory (`~/.rollapp/config`) set: ```shell -settlement_layer = "dymension" -gas_prices = "0.025adym" +sed -i 's/settlement_layer.*/settlement_layer = "dymension"/' ${ROLLAPP_HOME_DIR}/config/dymint.toml +sed -i '/node_address =/c\node_address = '\"$HUB_RPC_URL\" "${ROLLAPP_HOME_DIR}/config/dymint.toml" +sed -i '/rollapp_id =/c\rollapp_id = '\"$ROLLAPP_CHAIN_ID\" "${ROLLAPP_HOME_DIR}/config/dymint.toml" ``` ### Run rollapp locally diff --git a/README.with-advanced-features.md b/README.with-advanced-features.md new file mode 100644 index 0000000..f663565 --- /dev/null +++ b/README.with-advanced-features.md @@ -0,0 +1,244 @@ +# Dymension WASM Rollapp + +## rollappd - A template WASM RollApp chain + +This repository hosts `rollappd`, a template implementation of a dymension rollapp with `WASM` execution layer. + +`rollappd` is an example of a working RollApp using `dymension-RDK` and `dymint`. + +It uses Cosmos-SDK's [simapp](https://github.com/cosmos/cosmos-sdk/tree/main/simapp) as a reference, but with the following changes: + +- minimal app setup +- wired IBC for [ICS 20 Fungible Token Transfers](https://github.com/cosmos/ibc/tree/main/spec/app/ics-020-fungible-token-transfer) +- Uses `dymint` for block sequencing and replacing `tendermint` +- Uses modules from `dymension-RDK` to sync with `dymint` and provide RollApp custom logic + +## Overview + +**Note**: Requires [Go 1.20](https://go.dev/) + +## Quick guide + +Get started with [building RollApps](https://docs.dymension.xyz/develop/get-started/setup) + +## Installing / Getting started + +Build and install the ```rollappd``` binary: + +```shell +make install +``` + +### Initial configuration + +export the following variables: + +```shell +export ROLLAPP_CHAIN_ID="rollappwasm_1234-1" +export KEY_NAME_ROLLAPP="rol-user" +export BASE_DENOM="awsm" +export DENOM=$(echo "$BASE_DENOM" | sed 's/^.//') +export MONIKER="$ROLLAPP_CHAIN_ID-sequencer" + +export ROLLAPP_HOME_DIR="$HOME/.rollapp" +export ROLLAPP_SETTLEMENT_INIT_DIR_PATH="${ROLLAPP_HOME_DIR}/init" +``` + +if you want to change the max wasm size: + +```shell +export MAX_WASM_SIZE=WASM_SIZE_IN_BYTES +``` + +And initialize the rollapp: + +```shell +sh scripts/init.sh +``` + +### Download cw20-ics20 smartcontract + +Download cw20-ics20 smartcontract with a specific version: + +```shell +bash scripts/download_release.sh v1.0.0 +``` + +### Run rollapp + +```shell +rollappd start +``` + +You should have a running local rollapp! + +## Run a rollapp with a settlement node + +### Run local dymension hub node + +Follow the instructions on [Dymension Hub docs](https://docs.dymension.xyz/develop/get-started/run-base-layers) to run local dymension hub node + +all scripts are adjusted to use local hub node that's hosted on the default port `localhost:36657`. + +configuration with a remote hub node is also supported, the following variables must be set: + +```shell +export HUB_RPC_ENDPOINT="http://localhost" +export HUB_RPC_PORT="36657" # default: 36657 +export HUB_RPC_URL="http://${HUB_RPC_ENDPOINT}:${HUB_RPC_PORT}" +export HUB_CHAIN_ID="dymension_100-1" + +dymd config chain-id ${HUB_CHAIN_ID} +dymd config node ${HUB_RPC_URL} +``` + +### Create sequencer keys + +create sequencer key using `dymd` + +```shell +dymd keys add sequencer --keyring-dir ${ROLLAPP_HOME_DIR}/sequencer_keys --keyring-backend test +SEQUENCER_ADDR=`dymd keys show sequencer --address --keyring-backend test --keyring-dir ${ROLLAPP_HOME_DIR}/sequencer_keys` +``` + +fund the sequencer account (if you're using a remote hub node, you must fund the sequencer account or you must have an account with enough funds in your keyring) + +```shell +# this will retrieve the min bond amount from the hub +# if you're using an new address for registering a sequencer, +# you have to account for gas fees so it should the final value should be increased +BOND_AMOUNT="$(dymd q sequencer params -o json | jq -r '.params.min_bond.amount')$(dymd q sequencer params -o json | jq -r '.params.min_bond.denom')" + +dymd tx bank send local-user $SEQUENCER_ADDR ${BOND_AMOUNT} --keyring-backend test --broadcast-mode block --fees 1dym -y +``` + +### Generate denommetadata + +```shell + +sh scripts/settlement/generate_denom_metadata.sh +``` + +### Add genesis accounts + + +```shell +sh scripts/settlement/add_genesis_accounts.sh +``` + +### Register rollapp on settlement + +```shell +# for permissioned deployment setup, you must have access to an account whitelisted for rollapp +# registration, assuming you want to import an existing account, you can do: +dymd keys add local-user --recover +# input mnemonic from the account that has the permission to register rollapp + +sh scripts/settlement/register_rollapp_to_hub.sh +``` + +### Register sequencer for rollapp on settlement + +```shell +sh scripts/settlement/register_sequencer_to_hub.sh +``` + +### Configure the rollapp + +Modify `dymint.toml` in the chain directory (`${ROLLAPP_HOME_DIR}/config`) + +set: + +```shell +sed -i 's/settlement_layer.*/settlement_layer = "dymension"/' ${ROLLAPP_HOME_DIR}/config/dymint.toml +sed -i '/node_address =/c\node_address = '\"$HUB_RPC_URL\" "${ROLLAPP_HOME_DIR}/config/dymint.toml" +sed -i '/rollapp_id =/c\rollapp_id = '\"$ROLLAPP_CHAIN_ID\" "${ROLLAPP_HOME_DIR}/config/dymint.toml" +``` + +### Update the Genesis file to include the denommetadata, genesis accounts, module account and elevated accounts + +```shell +sh scripts/update_genesis_file.sh +``` + +### Update the Genesis file to include the denommetadata, genesis accounts, module account and elevated accounts + +```shell +# this script automatically adds 2 vesting accounts, adjust the timestampts to your liking or skip this step +sh scripts/add_vesting_accounts_to_genesis_file.sh +``` + +### Run rollapp locally + +```shell +rollappd start +``` + +or as a systemd service: + +```shell +sudo tee /etc/systemd/system/rollapp.service > /dev/null < /dev/null </dev/null; then echo "$RELAYER_EXECUTABLE does not exist" @@ -30,6 +30,10 @@ if ! command -v $RELAYER_EXECUTABLE >/dev/null; then exit 1 fi +# --------------------------------- change block time to easily create ibc channels --------------------------------- # +sed -i 's/empty_blocks_max_time =.*/empty_blocks_max_time = "3s"/' ${ROLLAPP_HOME_DIR}/config/dymint.toml +sudo systemctl restart rollapp + # --------------------------------- rly init --------------------------------- # RLY_PATH="$HOME/.relayer" RLY_CONFIG_FILE="$RLY_PATH/config/config.yaml" @@ -52,14 +56,14 @@ 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_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$BASE_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 +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" @@ -72,16 +76,16 @@ RLY_HUB_ADDR=$(rly keys show "$SETTLEMENT_CHAIN_ID") RLY_ROLLAPP_ADDR=$(rly keys show "$ROLLAPP_CHAIN_ID") echo '# -------------------------------- funding for rly account ------------------------------- #' -$SETTLEMENT_EXECUTABLE tx bank send $SETTLEMENT_KEY_NAME_GENESIS "$(rly keys show "$SETTLEMENT_CHAIN_ID")" 1000000000000000000000adym --keyring-backend test --broadcast-mode block --fees 20000000000000adym -y --node "$SETTLEMENT_RPC_FOR_RELAYER" -$EXECUTABLE tx bank send $ROLLAPP_KEY_NAME_GENESIS "$(rly keys show "$ROLLAPP_CHAIN_ID")" 1000000000000000000000$DENOM --keyring-backend test --broadcast-mode block -y --node "$ROLLAPP_RPC_FOR_RELAYER" +$SETTLEMENT_EXECUTABLE tx bank send $SETTLEMENT_KEY_NAME_GENESIS "$(rly keys show "$SETTLEMENT_CHAIN_ID")" 1000000000000000000000${SETTLEMENT_BASE_DENOM} --keyring-backend test --broadcast-mode block --fees 20000000000000${SETTLEMENT_BASE_DENOM} -y +$EXECUTABLE tx bank send $ROLLAPP_KEY_NAME_GENESIS "$(rly keys show "$ROLLAPP_CHAIN_ID")" 1000000000000000000000$BASE_DENOM --keyring-backend test --broadcast-mode block -y --node "$ROLLAPP_RPC_FOR_RELAYER" 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\"" +$SETTLEMENT_EXECUTABLE q bank balances "$(rly keys show "$SETTLEMENT_CHAIN_ID")" +echo "From within the hub node: \n\"$SETTLEMENT_EXECUTABLE tx bank send $SETTLEMENT_KEY_NAME_GENESIS $RLY_HUB_ADDR 100000000000000000000${SETTLEMENT_BASE_DENOM} --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 "From within the rollapp node: \n\"$EXECUTABLE tx bank send $KEY_NAME_ROLLAPP $RLY_ROLLAPP_ADDR 100000000$BASE_DENOM --keyring-backend test --broadcast-mode block\"" echo '# -------------------------------- creating IBC link ------------------------------- #' @@ -94,5 +98,9 @@ rly tx link "$RELAYER_PATH" --src-port "$IBC_PORT" --dst-port "$IBC_PORT" --vers sleep 5 echo '# -------------------------------- IBC channel established ------------------------------- #' -echo "ROLLAPP_CHANNEL: $(rly q channels "$ROLLAPP_CHAIN_ID")" -echo "HUB_CHANNEL: $(rly q channels "$SETTLEMENT_CHAIN_ID")" +echo "Channel Information:" +echo $(rly q channels "$ROLLAPP_CHAIN_ID" | jq '{ "rollapp-channel": .channel_id, "hub-channel": .counterparty.channel_id }') + +# --------------------------------- revert empty block time to 1h --------------------------------- # +sed -i 's/empty_blocks_max_time =.*/empty_blocks_max_time = "3600s"/' ${ROLLAPP_HOME_DIR}/config/dymint.toml +sudo systemctl restart rollapp diff --git a/scripts/init.sh b/scripts/init.sh index 6ffde27..4f589fe 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -6,17 +6,16 @@ ROLLAPP_CHAIN_DIR="$HOME/.rollapp" set_denom() { denom=$1 - jq --arg denom $denom '.app_state.mint.params.mint_denom = $denom' "$GENESIS_FILE" > "$tmp" && mv "$tmp" "$GENESIS_FILE" - jq --arg denom $denom '.app_state.staking.params.bond_denom = $denom' "$GENESIS_FILE" > "$tmp" && mv "$tmp" "$GENESIS_FILE" - jq --arg denom $denom '.app_state.gov.deposit_params.min_deposit[0].denom = $denom' "$GENESIS_FILE" > "$tmp" && mv "$tmp" "$GENESIS_FILE" + jq --arg denom $denom '.app_state.mint.params.mint_denom = $denom' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" + jq --arg denom $denom '.app_state.staking.params.bond_denom = $denom' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" + jq --arg denom $denom '.app_state.gov.deposit_params.min_deposit[0].denom = $denom' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" } # ---------------------------- initial parameters ---------------------------- # # Assuming 1,000,000 tokens #half is staked -TOKEN_AMOUNT="1000000000000000000000000$DENOM" -STAKING_AMOUNT="500000000000000000000000$DENOM" - +TOKEN_AMOUNT="1000000000000000000000000$BASE_DENOM" +STAKING_AMOUNT="500000000000000000000000$BASE_DENOM" CONFIG_DIRECTORY="$ROLLAPP_CHAIN_DIR/config" GENESIS_FILE="$CONFIG_DIRECTORY/genesis.json" @@ -56,8 +55,8 @@ $EXECUTABLE config keyring-backend test $EXECUTABLE config chain-id "$ROLLAPP_CHAIN_ID" # -------------------------------- app config -------------------------------- # -sed -i'' -e "s/^minimum-gas-prices *= .*/minimum-gas-prices = \"0$DENOM\"/" "$APP_CONFIG_FILE" -set_denom "$DENOM" +sed -i'' -e "s/^minimum-gas-prices *= .*/minimum-gas-prices = \"0$BASE_DENOM\"/" "$APP_CONFIG_FILE" +set_denom "$BASE_DENOM" # --------------------- adding keys and genesis accounts --------------------- # #local genesis account @@ -68,12 +67,17 @@ $EXECUTABLE add-genesis-account "$KEY_NAME_ROLLAPP" "$TOKEN_AMOUNT" --keyring-ba operator_address=$($EXECUTABLE keys show "$KEY_NAME_ROLLAPP" -a --keyring-backend test --bech val) jq --arg addr $operator_address '.app_state["sequencers"]["genesis_operator_address"] = $addr' "$GENESIS_FILE" > "$tmp" && mv "$tmp" "$GENESIS_FILE" +# set sequencer's operator address +operator_address=$($EXECUTABLE keys show "$KEY_NAME_ROLLAPP" -a --keyring-backend test --bech val) +jq --arg addr $operator_address '.app_state["sequencers"]["genesis_operator_address"] = $addr' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" + echo "Do you want to include staker on genesis? (Y/n) " read -r answer -if [ ! "$answer" != "${answer#[Nn]}" ] ;then +if [ ! "$answer" != "${answer#[Nn]}" ]; then + set -x $EXECUTABLE gentx "$KEY_NAME_ROLLAPP" "$STAKING_AMOUNT" --chain-id "$ROLLAPP_CHAIN_ID" --keyring-backend test --home "$ROLLAPP_CHAIN_DIR" $EXECUTABLE collect-gentxs --home "$ROLLAPP_CHAIN_DIR" + set +x fi - $EXECUTABLE validate-genesis diff --git a/scripts/settlement/add_genesis_accounts.sh b/scripts/settlement/add_genesis_accounts.sh new file mode 100644 index 0000000..fb6d289 --- /dev/null +++ b/scripts/settlement/add_genesis_accounts.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +if [ ! -d "$ROLLAPP_SETTLEMENT_INIT_DIR_PATH" ]; then + mkdir -p "$ROLLAPP_SETTLEMENT_INIT_DIR_PATH" + echo "Creating the ROLLAPP_SETTLEMENT_INIT_DIR_PATH: $ROLLAPP_SETTLEMENT_INIT_DIR_PATH" +else + echo "ROLLAPP_SETTLEMENT_INIT_DIR_PATH already exists: $ROLLAPP_SETTLEMENT_INIT_DIR_PATH" +fi + +dymd keys add alice-genesis --keyring-backend test +dymd keys add bob-genesis --keyring-backend test + +tee "$ROLLAPP_SETTLEMENT_INIT_DIR_PATH/genesis_accounts.json" >/dev/null </dev/null <"$tmp" && mv "$tmp" "$GENESIS_FILE" +jq '.consensus_params["block"]["max_bytes"] = "5242880"' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" + +jq '.app_state.gov.voting_params.voting_period = "300s"' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" + +# this is a static module account for the hubgenesis module +# retrieved using 'rollappd q auth module-accounts' command +module_account_address="ethm1748tamme3jj3v9wq95fc3pmglxtqscljdy7483" + +# Construct the JSON object with the obtained address +module_account=$(jq -n \ + --arg address "$module_account_address" \ + '[{ + "@type": "/cosmos.auth.v1beta1.ModuleAccount", + "base_account": { + "account_number": "0", + "address": $address, + "pub_key": null, + "sequence": "0" + }, + "name": "hubgenesis", + "permissions": [] + }]') + +jq --argjson module_account "$module_account" '.app_state.auth.accounts += $module_account' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" + +module_account_balance=$( + jq -n \ + --arg address "$module_account_address" \ + --arg denom "$BASE_DENOM" \ + '[{ + "address": $address, + "coins": [ + { + "denom": $denom, + "amount": "60000000000000000000000" + } + ] + }]' +) + +jq '.app_state.bank.balances[0].coins[0].amount = "2000000000000000000000000000"' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" +jq --argjson module_account_balance "$module_account_balance" '.app_state.bank.balances += $module_account_balance' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" + +jq '.app_state.bank.supply[0].amount = "2000060000000000000000000000"' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" + +# ---------------------------- add elevated account ---------------------------- # +elevated_address=$(${EXECUTABLE} keys show ${KEY_NAME_ROLLAPP} --keyring-backend test --output json | jq -r .address) +elevated_address_json=$(jq -n \ + --arg address "$elevated_address" \ + '[{ + "address": $address + }]') +jq --argjson elevated_address_json "$elevated_address_json" '.app_state.hubgenesis.params.genesis_triggerer_whitelist += $elevated_address_json' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" +jq --arg hub_chain_id "$HUB_CHAIN_ID" '.app_state.hubgenesis.hub.hub_id = $hub_chain_id' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" + +# ---------------------------- add denom metadata ---------------------------- # +denom_metadata=$(cat $ROLLAPP_SETTLEMENT_INIT_DIR_PATH/denommetadata.json) +jq --argjson denom_metadata "$denom_metadata" '.app_state.bank.denom_metadata = $denom_metadata' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" +jq --arg elevated_address "$elevated_address" '.app_state.denommetadata.params.allowed_addresses += [$elevated_address]' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE"