From 8fdaf536c3aa4fa9f892796cff0121a2d7e45161 Mon Sep 17 00:00:00 2001 From: sampocs Date: Tue, 29 Nov 2022 15:51:50 -0600 Subject: [PATCH] moved HOST_CHAINS to vars and made chain id generic --- scripts/README.md | 36 +++++++++++++++++----------------- scripts/create_logs.sh | 2 -- scripts/init_chain.sh | 27 +++++++++++++------------ scripts/register_host.sh | 19 +++++++++--------- scripts/start_chain.sh | 11 ++--------- scripts/start_network.sh | 8 +++----- scripts/start_relayers.sh | 2 -- scripts/tests/run_all_tests.sh | 2 -- scripts/vars.sh | 9 ++++++--- 9 files changed, 53 insertions(+), 63 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index 8988a99684..ef6ee4d327 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -44,25 +44,25 @@ while getopts sgojhir{n} flag; do volumes: - ./scripts/state/{new-host-zone}5:/home/{new-host-zone}/.{new-host-zone} ``` -* Add the following parameters to `scripts/vars.sh`, where `CHAIN_ID` is the ID of the new host zone -``` -{CHAIN_ID}_CHAIN_ID={NEW-HOST-ZONE} -{CHAIN_ID}_NODE_PREFIX={new-host-zone} -{CHAIN_ID}_NUM_NODES=3 -{CHAIN_ID}_CMD="$SCRIPT_DIR/../build/{new-host-zone}d" -{CHAIN_ID}_VAL_PREFIX={n}val -{CHAIN_ID}_ADDRESS_PREFIX=stars -{CHAIN_ID}_REV_ACCT={n}rev1 -{CHAIN_ID}_DENOM={add denom as a constant at the top of the script and then reference here} -{CHAIN_ID}_RPC_PORT={the one included in the docker-compose above} -{CHAIN_ID}_MAIN_CMD="${CHAIN_ID}_CMD --home $SCRIPT_DIR/state/${${CHAIN_ID}_NODE_PREFIX}1" +* Add the following parameters to `scripts/vars.sh`, where `CHAIN` is the ID of the new host zone +``` +{CHAIN}_CHAIN_ID={NEW-HOST-ZONE} +{CHAIN}_NODE_PREFIX={new-host-zone} +{CHAIN}_NUM_NODES=3 +{CHAIN}_CMD="$SCRIPT_DIR/../build/{new-host-zone}d" +{CHAIN}_VAL_PREFIX={n}val +{CHAIN}_ADDRESS_PREFIX=stars +{CHAIN}_REV_ACCT={n}rev1 +{CHAIN}_DENOM={add denom as a constant at the top of the script and then reference here} +{CHAIN}_RPC_PORT={the one included in the docker-compose above} +{CHAIN}_MAIN_CMD="${CHAIN}_CMD --home $SCRIPT_DIR/state/${${CHAIN}_NODE_PREFIX}1" -RELAYER_{CHAIN_ID}_EXEC="docker-compose run --rm relayer-{new-host-zone}" -RELAYER_{CHAIN_ID}_ACCT=rly{add one since the account from the last host zone} -HOST_RELAYER_ACCTS=(... $RELAYER_{CHAIN_ID}_ACCT) +RELAYER_{CHAIN}_EXEC="docker-compose run --rm relayer-{new-host-zone}" +RELAYER_{CHAIN}_ACCT=rly{add one since the account from the last host zone} +HOST_RELAYER_ACCTS=(... $RELAYER_{CHAIN}_ACCT) -RELAYER_{CHAIN_ID}_MNEMONIC="" -RELAYER_MNEMONICS=(...,"$RELAYER_{CHAIN_ID}_MNEMONIC") +RELAYER_{CHAIN}_MNEMONIC="" +RELAYER_MNEMONICS=(...,"$RELAYER_{CHAIN}_MNEMONIC") ``` * Add the IBC denom's for the host zone across each channel to `vars.sh` (e.g. `IBC_{HOST}_CHANNEL_{N}_DENOM)`). You can use the following code block to generate the variables (just temporarily throw it in any of the test files, run it, and copy the output to `vars.sh`) @@ -110,7 +110,7 @@ paths: rule: "" channel-list: [] ``` -* To enable the the new host zone, include it in the `HOST_CHAINS` array in `scripts/start_network.sh`. **Note: You can only run up to 4 host zones at once.** +* To enable the the new host zone, include it in the `HOST_CHAINS` array in `scripts/vars.sh`. **Note: You can only run up to 4 host zones at once.** ``` HOST_CHAINS=(GAIA {NEW-HOST-ZONE}) ``` diff --git a/scripts/create_logs.sh b/scripts/create_logs.sh index 08c4be0b38..6f3db69f71 100755 --- a/scripts/create_logs.sh +++ b/scripts/create_logs.sh @@ -6,8 +6,6 @@ SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) source ${SCRIPT_DIR}/vars.sh -HOST_CHAINS="$@" - LOGS_DIR=$SCRIPT_DIR/logs TEMP_LOGS_DIR=$LOGS_DIR/temp diff --git a/scripts/init_chain.sh b/scripts/init_chain.sh index 331b862b4a..b522cb76ac 100644 --- a/scripts/init_chain.sh +++ b/scripts/init_chain.sh @@ -5,15 +5,16 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source $SCRIPT_DIR/vars.sh -CHAIN_ID="$1" +CHAIN="$1" KEYS_LOGS=$SCRIPT_DIR/logs/keys.log -CMD=$(GET_VAR_VALUE ${CHAIN_ID}_CMD) -DENOM=$(GET_VAR_VALUE ${CHAIN_ID}_DENOM) -RPC_PORT=$(GET_VAR_VALUE ${CHAIN_ID}_RPC_PORT) -NUM_NODES=$(GET_VAR_VALUE ${CHAIN_ID}_NUM_NODES) -NODE_PREFIX=$(GET_VAR_VALUE ${CHAIN_ID}_NODE_PREFIX) -VAL_PREFIX=$(GET_VAR_VALUE ${CHAIN_ID}_VAL_PREFIX) +CHAIN_ID=$(GET_VAR_VALUE ${CHAIN}_CHAIN_ID) +CMD=$(GET_VAR_VALUE ${CHAIN}_CMD) +DENOM=$(GET_VAR_VALUE ${CHAIN}_DENOM) +RPC_PORT=$(GET_VAR_VALUE ${CHAIN}_RPC_PORT) +NUM_NODES=$(GET_VAR_VALUE ${CHAIN}_NUM_NODES) +NODE_PREFIX=$(GET_VAR_VALUE ${CHAIN}_NODE_PREFIX) +VAL_PREFIX=$(GET_VAR_VALUE ${CHAIN}_VAL_PREFIX) IFS=',' read -r -a VAL_MNEMONICS <<< "${VAL_MNEMONICS}" IFS=',' read -r -a RELAYER_MNEMONICS <<< "${RELAYER_MNEMONICS}" @@ -62,7 +63,7 @@ MAIN_NODE_CMD="" MAIN_NODE_ID="" MAIN_CONFIG="" MAIN_GENESIS="" -echo "Initializing $CHAIN_ID chain..." +echo "Initializing $CHAIN chain..." for (( i=1; i <= $NUM_NODES; i++ )); do # Node names will be of the form: "stride-node1" node_name="${NODE_PREFIX}${i}" @@ -131,7 +132,7 @@ for (( i=1; i <= $NUM_NODES; i++ )); do fi done -if [ "$CHAIN_ID" == "$STRIDE_CHAIN_ID" ]; then +if [ "$CHAIN" == "STRIDE" ]; then # add the stride admin account echo "$STRIDE_ADMIN_MNEMONIC" | $MAIN_NODE_CMD keys add $STRIDE_ADMIN_ACCT --recover --keyring-backend=test >> $KEYS_LOGS 2>&1 STRIDE_ADMIN_ADDRESS=$($MAIN_NODE_CMD keys show $STRIDE_ADMIN_ACCT --keyring-backend test -a) @@ -148,13 +149,13 @@ if [ "$CHAIN_ID" == "$STRIDE_CHAIN_ID" ]; then done else # add a revenue account - REV_ACCT_VAR=${CHAIN_ID}_REV_ACCT + REV_ACCT_VAR=${CHAIN}_REV_ACCT REV_ACCT=${!REV_ACCT_VAR} echo $REV_MNEMONIC | $MAIN_NODE_CMD keys add $REV_ACCT --recover --keyring-backend=test >> $KEYS_LOGS 2>&1 # add a relayer account - RELAYER_ACCT=$(GET_VAR_VALUE RELAYER_${CHAIN_ID}_ACCT) - RELAYER_MNEMONIC=$(GET_VAR_VALUE RELAYER_${CHAIN_ID}_MNEMONIC) + RELAYER_ACCT=$(GET_VAR_VALUE RELAYER_${CHAIN}_ACCT) + RELAYER_MNEMONIC=$(GET_VAR_VALUE RELAYER_${CHAIN}_MNEMONIC) echo "$RELAYER_MNEMONIC" | $MAIN_NODE_CMD keys add $RELAYER_ACCT --recover --keyring-backend=test >> $KEYS_LOGS 2>&1 RELAYER_ADDRESS=$($MAIN_NODE_CMD keys show $RELAYER_ACCT --keyring-backend test -a) @@ -168,7 +169,7 @@ $MAIN_NODE_CMD collect-gentxs &> /dev/null sed -i -E "s|persistent_peers = .*|persistent_peers = \"\"|g" $MAIN_CONFIG # update chain-specific genesis settings -if [ "$CHAIN_ID" == "$STRIDE_CHAIN_ID" ]; then +if [ "$CHAIN" == "STRIDE" ]; then set_stride_genesis $MAIN_GENESIS else set_host_genesis $MAIN_GENESIS diff --git a/scripts/register_host.sh b/scripts/register_host.sh index 77768da7b6..42dfdd33c5 100644 --- a/scripts/register_host.sh +++ b/scripts/register_host.sh @@ -4,28 +4,29 @@ set -eu SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source $SCRIPT_DIR/vars.sh -CHAIN_ID="$1" +CHAIN="$1" HOST_ZONE_NUM="$2" CONNECTION="connection-$HOST_ZONE_NUM" CHANNEL="channel-$HOST_ZONE_NUM" -VAL_PREFIX=$(GET_VAR_VALUE ${CHAIN_ID}_VAL_PREFIX) -IBC_DENOM=$(GET_VAR_VALUE IBC_${CHAIN_ID}_CHANNEL_${HOST_ZONE_NUM}_DENOM) -HOST_DENOM=$(GET_VAR_VALUE ${CHAIN_ID}_DENOM) -ADDRESS_PREFIX=$(GET_VAR_VALUE ${CHAIN_ID}_ADDRESS_PREFIX) -NUM_VALS=$(GET_VAR_VALUE ${CHAIN_ID}_NUM_NODES) +CHAIN_ID=$(GET_VAR_VALUE ${CHAIN}_CHAIN_ID) +VAL_PREFIX=$(GET_VAR_VALUE ${CHAIN}_VAL_PREFIX) +IBC_DENOM=$(GET_VAR_VALUE IBC_${CHAIN}_CHANNEL_${HOST_ZONE_NUM}_DENOM) +HOST_DENOM=$(GET_VAR_VALUE ${CHAIN}_DENOM) +ADDRESS_PREFIX=$(GET_VAR_VALUE ${CHAIN}_ADDRESS_PREFIX) +NUM_VALS=$(GET_VAR_VALUE ${CHAIN}_NUM_NODES) -echo "$CHAIN_ID - Registering host zone..." +echo "$CHAIN - Registering host zone..." $STRIDE_MAIN_CMD tx stakeibc register-host-zone \ $CONNECTION $HOST_DENOM $ADDRESS_PREFIX $IBC_DENOM $CHANNEL 1 \ --gas 1000000 --from $STRIDE_ADMIN_ACCT --home $SCRIPT_DIR/state/stride1 -y | TRIM_TX sleep 10 -echo "$CHAIN_ID - Registering validators..." +echo "$CHAIN - Registering validators..." weights=(5 10 5 10 5) # alternate weights across vals for (( i=1; i <= $NUM_VALS; i++ )); do - delegate_val=$(GET_VAL_ADDR $CHAIN_ID $i) + delegate_val=$(GET_VAL_ADDR $CHAIN $i) weight=${weights[$i]} $STRIDE_MAIN_CMD tx stakeibc add-validator $CHAIN_ID ${VAL_PREFIX}${i} $delegate_val 10 $weight \ diff --git a/scripts/start_chain.sh b/scripts/start_chain.sh index 64d566815d..2498e2f194 100644 --- a/scripts/start_chain.sh +++ b/scripts/start_chain.sh @@ -5,14 +5,7 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source ${SCRIPT_DIR}/vars.sh -# Pass the CHAIN_ID's of the chains to start -CHAINS="$@" -if [[ "$CHAINS" == "" ]]; then - echo "ERROR: Please specify chain IDs to start" - exit 1 -fi - -for chain_id in ${CHAINS[@]}; do +for chain_id in STRIDE ${HOST_CHAINS[@]}; do num_nodes=$(GET_VAR_VALUE ${chain_id}_NUM_NODES) node_prefix=$(GET_VAR_VALUE ${chain_id}_NODE_PREFIX) @@ -25,7 +18,7 @@ for chain_id in ${CHAINS[@]}; do docker-compose logs -f ${node_prefix}1 | sed -r -u "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" > $log_file 2>&1 & done -for chain_id in ${CHAINS[@]}; do +for chain_id in STRIDE ${HOST_CHAINS[@]}; do printf "Waiting for $chain_id to start..." node_prefix=$(GET_VAR_VALUE ${chain_id}_NODE_PREFIX) diff --git a/scripts/start_network.sh b/scripts/start_network.sh index c4ce35073d..2b6ff69500 100755 --- a/scripts/start_network.sh +++ b/scripts/start_network.sh @@ -4,8 +4,6 @@ set -eu SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source ${SCRIPT_DIR}/vars.sh -HOST_CHAINS=(GAIA JUNO OSMO STARS) - # cleanup any stale state make stop-docker rm -rf $SCRIPT_DIR/state $SCRIPT_DIR/logs/*.log $SCRIPT_DIR/logs/temp @@ -47,12 +45,12 @@ for chain_id in STRIDE ${HOST_CHAINS[@]}; do done # Start the chain and create the transfer channels -bash ${SCRIPT_DIR}/start_chain.sh STRIDE ${HOST_CHAINS[@]} -bash ${SCRIPT_DIR}/start_relayers.sh ${HOST_CHAINS[@]} +bash ${SCRIPT_DIR}/start_chain.sh +bash ${SCRIPT_DIR}/start_relayers.sh # Register all host zones for i in ${!HOST_CHAINS[@]}; do bash $SCRIPT_DIR/register_host.sh ${HOST_CHAINS[$i]} $i done -$SCRIPT_DIR/create_logs.sh ${HOST_CHAINS[@]} & +$SCRIPT_DIR/create_logs.sh & diff --git a/scripts/start_relayers.sh b/scripts/start_relayers.sh index c5b46637f6..02be1afad5 100644 --- a/scripts/start_relayers.sh +++ b/scripts/start_relayers.sh @@ -5,8 +5,6 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source ${SCRIPT_DIR}/vars.sh -HOST_CHAINS="$@" - for chain_id in ${HOST_CHAINS[@]}; do relayer_exec=$(GET_VAR_VALUE RELAYER_${chain_id}_EXEC) chain_name=$(printf "$chain_id" | awk '{ print tolower($0) }') diff --git a/scripts/tests/run_all_tests.sh b/scripts/tests/run_all_tests.sh index 307d6c490b..01f123a0e2 100755 --- a/scripts/tests/run_all_tests.sh +++ b/scripts/tests/run_all_tests.sh @@ -5,5 +5,3 @@ BASE_SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && p CHAIN_NAME=GAIA TRANSFER_CHANNEL_NUMBER=0 bats $BASE_SCRIPT_DIR/integration_tests.bats CHAIN_NAME=JUNO TRANSFER_CHANNEL_NUMBER=1 bats $BASE_SCRIPT_DIR/integration_tests.bats CHAIN_NAME=OSMO TRANSFER_CHANNEL_NUMBER=2 bats $BASE_SCRIPT_DIR/integration_tests.bats -CHAIN_NAME=STARS TRANSFER_CHANNEL_NUMBER=3 bats $BASE_SCRIPT_DIR/integration_tests.bats - diff --git a/scripts/vars.sh b/scripts/vars.sh index 9abf59ccd5..60fad12679 100644 --- a/scripts/vars.sh +++ b/scripts/vars.sh @@ -12,6 +12,9 @@ STRIDE_LOGS=$LOGS/stride.log TX_LOGS=$SCRIPT_DIR/logs/tx.log KEYS_LOGS=$SCRIPT_DIR/logs/keys.log +# List of hosts enabled +HOST_CHAINS=(GAIA JUNO OSMO) + # Sets up upgrade if {UPGRADE_NAME} is non-empty UPGRADE_NAME="" UPGRADE_OLD_COMMIT_HASH="" @@ -228,11 +231,11 @@ WAIT_FOR_STRING() { } GET_VAL_ADDR() { - chain_id=$1 + chain=$1 val_index=$2 - MAIN_CMD=$(GET_VAR_VALUE ${chain_id}_MAIN_CMD) - $MAIN_CMD q staking validators | grep ${chain_id}_${val_index} -A 5 | grep operator | awk '{print $2}' + MAIN_CMD=$(GET_VAR_VALUE ${chain}_MAIN_CMD) + $MAIN_CMD q staking validators | grep ${chain}_${val_index} -A 5 | grep operator | awk '{print $2}' } GET_ICA_ADDR() {