From cd6271c330e5bca0ac10eb41c124cf5e281d532d Mon Sep 17 00:00:00 2001 From: Jehan Tremback Date: Tue, 15 Feb 2022 15:37:49 -0800 Subject: [PATCH 1/9] try using a seed node --- .../start-chain/setup-validators.sh | 85 ------------ testnet-scripts/start-chain/start-chain.sh | 121 +++++++++++++++++- .../start-chain/start-validators.sh | 45 ------- 3 files changed, 118 insertions(+), 133 deletions(-) delete mode 100644 testnet-scripts/start-chain/setup-validators.sh delete mode 100644 testnet-scripts/start-chain/start-validators.sh diff --git a/testnet-scripts/start-chain/setup-validators.sh b/testnet-scripts/start-chain/setup-validators.sh deleted file mode 100644 index 97ec919..0000000 --- a/testnet-scripts/start-chain/setup-validators.sh +++ /dev/null @@ -1,85 +0,0 @@ -#!/bin/bash -set -eux - -BIN=$1 -MNEMONICS=$2 -CHAIN_ID=$3 -CHAIN_IP_PREFIX=$4 -GENESIS_TRANSFORM=$5 -ALLOCATION=$6 -STAKE_AMOUNT=$7 -SKIP_GENTX=$8 - -# Get number of nodes from length of mnemonics array -NODES=$(jq '. | length' <<< "$MNEMONICS") - - -# first we start a genesis.json with validator0 -# validator0 will also collect the gentx's once gnerated -# todo add git hash to chain name -jq -r ".[0]" <<< "$MNEMONICS" | $BIN init --home /$CHAIN_ID/validator0 --chain-id=$CHAIN_ID validator0 --recover > /dev/null - - -## Modify generated genesis.json to our liking by editing fields using jq -## we could keep a hardcoded genesis file around but that would prevent us from -## testing the generated one with the default values provided by the module. - -# Apply transformations to genesis file -jq "$GENESIS_TRANSFORM" /$CHAIN_ID/validator0/config/genesis.json > /$CHAIN_ID/edited-genesis.json - -mv /$CHAIN_ID/edited-genesis.json /$CHAIN_ID/genesis.json - - -# Sets up an arbitrary number of validators on a single machine by manipulating -# the --home parameter on gaiad -for i in $(seq 0 $(($NODES - 1))); -do - # TODO: we need to pass in an identifier to identify the validator folder and other things instead of - # using the index - - # make the folders for this validator - mkdir -p /$CHAIN_ID/validator$i/config/ - - ARGS="--home /$CHAIN_ID/validator$i --keyring-backend test" - - # Generate a validator key, orchestrator key, and eth key for each validator - jq -r ".[$((i-1))]" <<< "$MNEMONICS" | $BIN keys add $ARGS validator$i --recover > /$CHAIN_ID/validator$i/mnemonic - - echo "validator$i keys:" - $BIN keys show validator$i $ARGS - - # move the genesis in - mv /$CHAIN_ID/genesis.json /$CHAIN_ID/validator$i/config/genesis.json - $BIN add-genesis-account $ARGS validator$i $ALLOCATION - - # move the genesis back out - mv /$CHAIN_ID/validator$i/config/genesis.json /$CHAIN_ID/genesis.json -done - - -for i in $(seq 0 $(($NODES - 1))); -do - cp /$CHAIN_ID/genesis.json /$CHAIN_ID/validator$i/config/genesis.json - - $BIN gentx validator$i "$STAKE_AMOUNT" --home /$CHAIN_ID/validator$i --keyring-backend test --moniker validator$i --chain-id=$CHAIN_ID --ip $CHAIN_IP_PREFIX.$i - - # obviously we don't need to copy validator0's gentx to itself - if [ $i -gt 0 ]; then - cp /$CHAIN_ID/validator$i/config/gentx/* /$CHAIN_ID/validator0/config/gentx/ - fi -done - -if [ "$SKIP_GENTX" = "false" ] ; then - # make the final genesis.json - $BIN collect-gentxs --home /$CHAIN_ID/validator0 -fi - -# and copy it to the root -cp /$CHAIN_ID/validator0/config/genesis.json /$CHAIN_ID/genesis.json - -# put the now final genesis.json into the correct folders -for i in $(seq 1 $(($NODES - 1))); -do - cp /$CHAIN_ID/genesis.json /$CHAIN_ID/validator$i/config/genesis.json -done - diff --git a/testnet-scripts/start-chain/start-chain.sh b/testnet-scripts/start-chain/start-chain.sh index b605fa0..3275120 100644 --- a/testnet-scripts/start-chain/start-chain.sh +++ b/testnet-scripts/start-chain/start-chain.sh @@ -37,9 +37,124 @@ STAKE_AMOUNT=$9 # Whether to skip collecting gentxs so that the genesis does not have them SKIP_GENTX=${10} -# generate accounts and do genesis ceremony -/bin/bash "$DIR/setup-validators.sh" "$BIN" "$MNEMONICS" "$CHAIN_ID" "$CHAIN_IP_PREFIX" "$GENESIS_TRANSFORM" "$ALLOCATION" "$STAKE_AMOUNT" "$SKIP_GENTX" -/bin/bash "$DIR/start-validators.sh" "$BIN" "$MNEMONICS" "$CHAIN_ID" "$CHAIN_IP_PREFIX" "$RPC_PORT" "$GRPC_PORT" + + + + +# CREATE VALDIATORS AND DO GENESIS CEREMONY + +# Get number of nodes from length of mnemonics array +NODES=$(jq '. | length' <<< "$MNEMONICS") + + +# first we start a genesis.json with validator0 +# validator0 will also collect the gentx's once gnerated +# todo add git hash to chain name +jq -r ".[0]" <<< "$MNEMONICS" | $BIN init --home /$CHAIN_ID/validator0 --chain-id=$CHAIN_ID validator0 --recover > /dev/null + + +## Modify generated genesis.json to our liking by editing fields using jq +## we could keep a hardcoded genesis file around but that would prevent us from +## testing the generated one with the default values provided by the module. + +# Apply transformations to genesis file +jq "$GENESIS_TRANSFORM" /$CHAIN_ID/validator0/config/genesis.json > /$CHAIN_ID/edited-genesis.json + +mv /$CHAIN_ID/edited-genesis.json /$CHAIN_ID/genesis.json + + +# Sets up an arbitrary number of validators on a single machine by manipulating +# the --home parameter on gaiad +for i in $(seq 0 $(($NODES - 1))); +do + # TODO: we need to pass in an identifier to identify the validator folder and other things instead of + # using the index + + # make the folders for this validator + mkdir -p /$CHAIN_ID/validator$i/config/ + + ARGS="--home /$CHAIN_ID/validator$i --keyring-backend test" + + # Generate a validator key, orchestrator key, and eth key for each validator + jq -r ".[$((i-1))]" <<< "$MNEMONICS" | $BIN keys add $ARGS validator$i --recover > /$CHAIN_ID/validator$i/mnemonic + + echo "validator$i keys:" + $BIN keys show validator$i $ARGS + + # move the genesis in + mv /$CHAIN_ID/genesis.json /$CHAIN_ID/validator$i/config/genesis.json + $BIN add-genesis-account $ARGS validator$i $ALLOCATION + + # move the genesis back out + mv /$CHAIN_ID/validator$i/config/genesis.json /$CHAIN_ID/genesis.json +done + + +for i in $(seq 0 $(($NODES - 1))); +do + cp /$CHAIN_ID/genesis.json /$CHAIN_ID/validator$i/config/genesis.json + + $BIN gentx validator$i "$STAKE_AMOUNT" --home /$CHAIN_ID/validator$i --keyring-backend test --moniker validator$i --chain-id=$CHAIN_ID --ip $CHAIN_IP_PREFIX.$i + + # obviously we don't need to copy validator0's gentx to itself + if [ $i -gt 0 ]; then + cp /$CHAIN_ID/validator$i/config/gentx/* /$CHAIN_ID/validator0/config/gentx/ + fi +done + +if [ "$SKIP_GENTX" = "false" ] ; then + # make the final genesis.json + $BIN collect-gentxs --home /$CHAIN_ID/validator0 +fi + +# and copy it to the root +cp /$CHAIN_ID/validator0/config/genesis.json /$CHAIN_ID/genesis.json + +# put the now final genesis.json into the correct folders +for i in $(seq 1 $(($NODES - 1))); +do + cp /$CHAIN_ID/genesis.json /$CHAIN_ID/validator$i/config/genesis.json +done + + + + +# START VALIDATOR NODES + +# Set up seed node +$BIN init --home /$CHAIN_ID/seed --chain-id=$CHAIN_ID seed +cp /$CHAIN_ID/genesis.json /$CHAIN_ID/seed/config/genesis.json +SEED_ID=$($BIN tendermint show-node-id --home /$CHAIN_ID/seed) +ip addr add $CHAIN_IP_PREFIX.254/32 dev eth0 || true # allowed to fail +$BIN start \ + --home /$CHAIN_ID/seed \ + --p2p.laddr tcp://$CHAIN_IP_PREFIX.254:26656 \ + --rpc.laddr tcp://$CHAIN_IP_PREFIX.254:26658 \ + --grpc.address $CHAIN_IP_PREFIX.254:9091 \ + --address tcp://$CHAIN_IP_PREFIX.254:26655 \ + --p2p.laddr tcp://$CHAIN_IP_PREFIX.254:26656 \ + --grpc-web.enable=false \ + &> /$CHAIN_ID/seed/logs & + +for i in $(seq 0 $(($NODES - 1))); +do + # add this ip for loopback dialing + ip addr add $CHAIN_IP_PREFIX.$i/32 dev eth0 || true # allowed to fail + + GAIA_HOME="--home /$CHAIN_ID/validator$i" + RPC_ADDRESS="--rpc.laddr tcp://$CHAIN_IP_PREFIX.$i:26658" + GRPC_ADDRESS="--grpc.address $CHAIN_IP_PREFIX.$i:9091" + LISTEN_ADDRESS="--address tcp://$CHAIN_IP_PREFIX.$i:26655" + P2P_ADDRESS="--p2p.laddr tcp://$CHAIN_IP_PREFIX.$i:26656" + LOG_LEVEL="--log_level info" + ENABLE_WEBGRPC="--grpc-web.enable=false" + + ARGS="$GAIA_HOME $LISTEN_ADDRESS $RPC_ADDRESS $GRPC_ADDRESS $LOG_LEVEL $P2P_ADDRESS $ENABLE_WEBGRPC --p2p.seeds $SEED_ID@$CHAIN_IP_PREFIX.254:26656" + $BIN $ARGS start &> /$CHAIN_ID/validator$i/logs & +done + + + # poll for chain start set +e diff --git a/testnet-scripts/start-chain/start-validators.sh b/testnet-scripts/start-chain/start-validators.sh deleted file mode 100644 index 031ff61..0000000 --- a/testnet-scripts/start-chain/start-validators.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash -set -eux - -BIN=$1 -MNEMONICS=$2 -CHAIN_ID=$3 - -# This is the first 3 fields of the IP addresses which will be used internally by the validators of this blockchain -# Recommended to use something starting with 7, since it is squatted by the DoD and is unroutable on the internet -# For example: "7.7.7" -CHAIN_IP_PREFIX=$4 - -# Default: 26657 -RPC_PORT=$5 -# Default: 9090 -GRPC_PORT=$6 - -# Get number of nodes from length of mnemonics array -NODES=$(jq '. | length' <<< "$MNEMONICS") - -for i in $(seq 0 $(($NODES - 1))); -do - # add this ip for loopback dialing - ip addr add $CHAIN_IP_PREFIX.$i/32 dev eth0 || true # allowed to fail - - GAIA_HOME="--home /$CHAIN_ID/validator$i" - - RPC_ADDRESS="--rpc.laddr tcp://$CHAIN_IP_PREFIX.$i:26658" - GRPC_ADDRESS="--grpc.address $CHAIN_IP_PREFIX.$i:9091" - LISTEN_ADDRESS="--address tcp://$CHAIN_IP_PREFIX.$i:26655" - P2P_ADDRESS="--p2p.laddr tcp://$CHAIN_IP_PREFIX.$i:26656" - LOG_LEVEL="--log_level info" - ENABLE_WEBGRPC="--grpc-web.enable=false" - - # only add validator1 as persistent peer, and don't add it to itself since nodes seem to error when given themselves as persistent peers - PERSISTENT_PEERS="" - if [ $i -gt 0 ]; then - PERSISTENT_PEERS="--p2p.persistent_peers $(paste -sd ',' <<< $(jq -r '.body.memo' /$CHAIN_ID/validator0/config/gentx/*))" - fi - - # SEED=$(paste -sd ',' <<< $(jq -r '.body.memo' /$CHAIN_ID/seed/config/gentx/*)) - - ARGS="$GAIA_HOME $LISTEN_ADDRESS $RPC_ADDRESS $GRPC_ADDRESS $LOG_LEVEL $P2P_ADDRESS $ENABLE_WEBGRPC $PERSISTENT_PEERS" - $BIN $ARGS start &> /$CHAIN_ID/validator$i/logs & -done From 596f7aa5845fa5623df1a99e481f5b35ccb6c81d Mon Sep 17 00:00:00 2001 From: Jehan Tremback Date: Tue, 15 Feb 2022 16:24:39 -0800 Subject: [PATCH 2/9] try to use persistent peers instead of seed node --- testnet-scripts/start-chain/start-chain.sh | 32 +++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/testnet-scripts/start-chain/start-chain.sh b/testnet-scripts/start-chain/start-chain.sh index 3275120..c3b7670 100644 --- a/testnet-scripts/start-chain/start-chain.sh +++ b/testnet-scripts/start-chain/start-chain.sh @@ -121,21 +121,6 @@ done # START VALIDATOR NODES -# Set up seed node -$BIN init --home /$CHAIN_ID/seed --chain-id=$CHAIN_ID seed -cp /$CHAIN_ID/genesis.json /$CHAIN_ID/seed/config/genesis.json -SEED_ID=$($BIN tendermint show-node-id --home /$CHAIN_ID/seed) -ip addr add $CHAIN_IP_PREFIX.254/32 dev eth0 || true # allowed to fail -$BIN start \ - --home /$CHAIN_ID/seed \ - --p2p.laddr tcp://$CHAIN_IP_PREFIX.254:26656 \ - --rpc.laddr tcp://$CHAIN_IP_PREFIX.254:26658 \ - --grpc.address $CHAIN_IP_PREFIX.254:9091 \ - --address tcp://$CHAIN_IP_PREFIX.254:26655 \ - --p2p.laddr tcp://$CHAIN_IP_PREFIX.254:26656 \ - --grpc-web.enable=false \ - &> /$CHAIN_ID/seed/logs & - for i in $(seq 0 $(($NODES - 1))); do # add this ip for loopback dialing @@ -149,7 +134,22 @@ do LOG_LEVEL="--log_level info" ENABLE_WEBGRPC="--grpc-web.enable=false" - ARGS="$GAIA_HOME $LISTEN_ADDRESS $RPC_ADDRESS $GRPC_ADDRESS $LOG_LEVEL $P2P_ADDRESS $ENABLE_WEBGRPC --p2p.seeds $SEED_ID@$CHAIN_IP_PREFIX.254:26656" + PERSISTENT_PEERS="" + + for j in $(seq 0 $(($NODES - 1))); + do + if [ $i -ne $j ]; then + NODE_ID=$($BIN tendermint show-node-id --home /$CHAIN_ID/validator$j) + ADDRESS="$NODE_ID@$CHAIN_IP_PREFIX.$j:26656" + # (jq -r '.body.memo' /$CHAIN_ID/validator$j/config/gentx/*) # Getting the address from the gentx should also work + PERSISTENT_PEERS="$PERSISTENT_PEERS,$ADDRESS" + fi + done + + # Remove leading comma and concat to flag + PERSISTENT_PEERS="--p2p.persistent_peers ${PERSISTENT_PEERS:1}" + + ARGS="$GAIA_HOME $LISTEN_ADDRESS $RPC_ADDRESS $GRPC_ADDRESS $LOG_LEVEL $P2P_ADDRESS $ENABLE_WEBGRPC $PERSISTENT_PEERS" $BIN $ARGS start &> /$CHAIN_ID/validator$i/logs & done From 75e47a9445001f3f77c3cc7d7a9227d662263a94 Mon Sep 17 00:00:00 2001 From: Jehan Tremback Date: Wed, 16 Feb 2022 17:09:39 -0800 Subject: [PATCH 3/9] validators can talk --- start-docker.sh | 10 ++-- testnet-scripts/start-chain/start-chain.sh | 62 +++++++++++++--------- tests/actions.go | 4 +- 3 files changed, 46 insertions(+), 30 deletions(-) diff --git a/start-docker.sh b/start-docker.sh index 578d5a2..8213aa2 100644 --- a/start-docker.sh +++ b/start-docker.sh @@ -1,18 +1,20 @@ #!/bin/bash -# set -eux +# If -e is not set then if the build fails, it will use the old container, resulting in a very confusing debugging situation +# Setting -e makes it error out if the build fails +set -eux CONTAINER_NAME=$1 INSTANCE_NAME=$2 # Must be in this format "-p 9090:9090 -p 26657:26657 -p 1317:1317 -p 8545:8545" EXPOSE_PORTS=$3 -# Build the Docker container -docker build -t "$CONTAINER_NAME" . - # Remove existing container instance set +e docker rm -f "$INSTANCE_NAME" set -e +# Build the Docker container +docker build -t "$CONTAINER_NAME" . + # Run new test container instance docker run --name "$INSTANCE_NAME" --cap-add=NET_ADMIN $EXPOSE_PORTS "$CONTAINER_NAME" /bin/bash /testnet-scripts/beacon.sh \ No newline at end of file diff --git a/testnet-scripts/start-chain/start-chain.sh b/testnet-scripts/start-chain/start-chain.sh index c3b7670..30c4ab1 100644 --- a/testnet-scripts/start-chain/start-chain.sh +++ b/testnet-scripts/start-chain/start-chain.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -eux +set -eu # the directory of this script DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" @@ -37,8 +37,8 @@ STAKE_AMOUNT=$9 # Whether to skip collecting gentxs so that the genesis does not have them SKIP_GENTX=${10} - - +# Whether to copy in validator configs from somewhere else +COPY_CONFIGS=${11} # CREATE VALDIATORS AND DO GENESIS CEREMONY @@ -46,20 +46,12 @@ SKIP_GENTX=${10} # Get number of nodes from length of mnemonics array NODES=$(jq '. | length' <<< "$MNEMONICS") - # first we start a genesis.json with validator0 # validator0 will also collect the gentx's once gnerated -# todo add git hash to chain name jq -r ".[0]" <<< "$MNEMONICS" | $BIN init --home /$CHAIN_ID/validator0 --chain-id=$CHAIN_ID validator0 --recover > /dev/null - -## Modify generated genesis.json to our liking by editing fields using jq -## we could keep a hardcoded genesis file around but that would prevent us from -## testing the generated one with the default values provided by the module. - -# Apply transformations to genesis file +# Apply jq transformations to genesis file jq "$GENESIS_TRANSFORM" /$CHAIN_ID/validator0/config/genesis.json > /$CHAIN_ID/edited-genesis.json - mv /$CHAIN_ID/edited-genesis.json /$CHAIN_ID/genesis.json @@ -68,40 +60,60 @@ mv /$CHAIN_ID/edited-genesis.json /$CHAIN_ID/genesis.json for i in $(seq 0 $(($NODES - 1))); do # TODO: we need to pass in an identifier to identify the validator folder and other things instead of - # using the index + # using the index. The current code WILL BREAK if you supply validators in any other order than 0,1,2 etc # make the folders for this validator mkdir -p /$CHAIN_ID/validator$i/config/ - - ARGS="--home /$CHAIN_ID/validator$i --keyring-backend test" - # Generate a validator key, orchestrator key, and eth key for each validator - jq -r ".[$((i-1))]" <<< "$MNEMONICS" | $BIN keys add $ARGS validator$i --recover > /$CHAIN_ID/validator$i/mnemonic - - echo "validator$i keys:" - $BIN keys show validator$i $ARGS + # Generate an application key for each validator + jq -r ".[$((i-1))]" <<< "$MNEMONICS" | $BIN keys add validator$i \ + --home /$CHAIN_ID/validator$i \ + --keyring-backend test \ + --recover > /dev/null + # Give validators their initial token allocations # move the genesis in mv /$CHAIN_ID/genesis.json /$CHAIN_ID/validator$i/config/genesis.json - $BIN add-genesis-account $ARGS validator$i $ALLOCATION - + # give this validator some money + $BIN add-genesis-account validator$i $ALLOCATION \ + --home /$CHAIN_ID/validator$i \ + --keyring-backend test # move the genesis back out mv /$CHAIN_ID/validator$i/config/genesis.json /$CHAIN_ID/genesis.json done +# echo "BEFORE GENTXS" +# find /$CHAIN_ID/ -print for i in $(seq 0 $(($NODES - 1))); do + # Copy in the genesis.json cp /$CHAIN_ID/genesis.json /$CHAIN_ID/validator$i/config/genesis.json - $BIN gentx validator$i "$STAKE_AMOUNT" --home /$CHAIN_ID/validator$i --keyring-backend test --moniker validator$i --chain-id=$CHAIN_ID --ip $CHAIN_IP_PREFIX.$i - - # obviously we don't need to copy validator0's gentx to itself + # Make a gentx (this command also sets up validator state on disk even if we are not going to use the gentx for anything) + $BIN gentx validator$i "$STAKE_AMOUNT" \ + --home /$CHAIN_ID/validator$i \ + --keyring-backend test \ + --moniker validator$i \ + --chain-id=$CHAIN_ID \ + --ip $CHAIN_IP_PREFIX.$i + + # Copy gentxs to validator0 for possible future collection. + # Obviously we don't need to copy validator0's gentx to itself if [ $i -gt 0 ]; then cp /$CHAIN_ID/validator$i/config/gentx/* /$CHAIN_ID/validator0/config/gentx/ fi + + # Copy in keys from another chain. This is used to start a consumer chain + if [ "$COPY_CONFIGS" != "" ] ; then + cp /$COPY_CONFIGS/validator$i/config/priv_validator_key.json /$CHAIN_ID/validator$i/config/ + cp /$COPY_CONFIGS/validator$i/config/node_key.json /$CHAIN_ID/validator$i/config/ + fi done +# echo "AFTER GENTXS" +# find /$CHAIN_ID/ -print + if [ "$SKIP_GENTX" = "false" ] ; then # make the final genesis.json $BIN collect-gentxs --home /$CHAIN_ID/validator0 diff --git a/tests/actions.go b/tests/actions.go index ce2e023..f98216c 100644 --- a/tests/actions.go +++ b/tests/actions.go @@ -17,6 +17,7 @@ type StartChainAction struct { validators []uint genesisChanges string skipGentx bool + copyConfigs string } type StartConsumerChainAction struct { @@ -115,7 +116,7 @@ func (s System) startChain( cmd := exec.Command("docker", "exec", s.containerConfig.instanceName, "/bin/bash", "/testnet-scripts/start-chain/start-chain.sh", s.containerConfig.binaryName, string(mnz), chainConfig.chainId, chainConfig.ipPrefix, fmt.Sprint(chainConfig.rpcPort), fmt.Sprint(chainConfig.grpcPort), genesisChanges, - chainConfig.initialAllocation, chainConfig.stakeAmount, fmt.Sprint(action.skipGentx)) + chainConfig.initialAllocation, chainConfig.stakeAmount, fmt.Sprint(action.skipGentx), action.copyConfigs) cmdReader, err := cmd.StdoutPipe() if err != nil { @@ -264,6 +265,7 @@ func (s System) startConsumerChain(action StartConsumerChainAction) { validators: action.validators, genesisChanges: ".app_state.ccvchild = " + string(bz), skipGentx: true, + copyConfigs: s.chainConfigs[action.providerChain].chainId, }) } From 2e99a41575fb4006c0304132e6c4e4010cca63a4 Mon Sep 17 00:00:00 2001 From: Jehan Tremback Date: Wed, 16 Feb 2022 17:14:08 -0800 Subject: [PATCH 4/9] tiny cleanup --- testnet-scripts/start-chain/start-chain.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/testnet-scripts/start-chain/start-chain.sh b/testnet-scripts/start-chain/start-chain.sh index 30c4ab1..cb234f0 100644 --- a/testnet-scripts/start-chain/start-chain.sh +++ b/testnet-scripts/start-chain/start-chain.sh @@ -117,16 +117,16 @@ done if [ "$SKIP_GENTX" = "false" ] ; then # make the final genesis.json $BIN collect-gentxs --home /$CHAIN_ID/validator0 -fi -# and copy it to the root -cp /$CHAIN_ID/validator0/config/genesis.json /$CHAIN_ID/genesis.json + # and copy it to the root + cp /$CHAIN_ID/validator0/config/genesis.json /$CHAIN_ID/genesis.json -# put the now final genesis.json into the correct folders -for i in $(seq 1 $(($NODES - 1))); -do - cp /$CHAIN_ID/genesis.json /$CHAIN_ID/validator$i/config/genesis.json -done + # put the now final genesis.json into the correct folders + for i in $(seq 1 $(($NODES - 1))); + do + cp /$CHAIN_ID/genesis.json /$CHAIN_ID/validator$i/config/genesis.json + done +fi From 4bb5e1257314e870552553d992ce9f558fa9cec9 Mon Sep 17 00:00:00 2001 From: Jehan Tremback Date: Tue, 22 Feb 2022 17:17:09 -0800 Subject: [PATCH 5/9] valattr json array seems to work and corrected insane numbering "-1" scheme --- interchain-security | 2 +- testnet-scripts/start-chain/start-chain.sh | 77 ++++++++++++---------- tests/actions.go | 22 +++++-- tests/config.go | 41 +++++++++++- 4 files changed, 99 insertions(+), 43 deletions(-) diff --git a/interchain-security b/interchain-security index 1ce43a7..aee9cc6 160000 --- a/interchain-security +++ b/interchain-security @@ -1 +1 @@ -Subproject commit 1ce43a79a81bef24b112e74d87ba2e0960b8d445 +Subproject commit aee9cc6600c79941c0e4ddd93e0065b2bea68f39 diff --git a/testnet-scripts/start-chain/start-chain.sh b/testnet-scripts/start-chain/start-chain.sh index cb234f0..1c85d3a 100644 --- a/testnet-scripts/start-chain/start-chain.sh +++ b/testnet-scripts/start-chain/start-chain.sh @@ -1,14 +1,16 @@ #!/bin/bash set -eu -# the directory of this script -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - # The gaiad binary BIN=$1 -# Mnemonics with which to start nodes -MNEMONICS=$2 +# JSON array of validator information +# [{ +# mnemonic: "crackle snap pop ... etc", +# allocation: "10000000000stake,10000000000footoken", +# stake: "5000000000stake", +# }, ... ] +VALIDATORS=$2 # The chain ID CHAIN_ID=$3 @@ -18,45 +20,34 @@ CHAIN_ID=$3 # For example: "7.7.7" CHAIN_IP_PREFIX=$4 -# Default: 26657 -RPC_PORT=$5 - -# Default: 9090 -GRPC_PORT=$6 - # A transformation to apply to the genesis file, as a jq string -GENESIS_TRANSFORM=$7 - -# How much coin to give each validator on start -# Default: "10000000000stake,10000000000footoken" -ALLOCATION=$8 - -# Amount for each validator to stake -STAKE_AMOUNT=$9 +GENESIS_TRANSFORM=$5 # Whether to skip collecting gentxs so that the genesis does not have them -SKIP_GENTX=${10} +SKIP_GENTX=$6 # Whether to copy in validator configs from somewhere else -COPY_CONFIGS=${11} +COPY_KEYS=$7 -# CREATE VALDIATORS AND DO GENESIS CEREMONY -# Get number of nodes from length of mnemonics array -NODES=$(jq '. | length' <<< "$MNEMONICS") +# CREATE VALIDATORS AND DO GENESIS CEREMONY + +# Get number of nodes from length of validators array +NODES=$(jq '. | length' <<< "$VALIDATORS") # first we start a genesis.json with validator0 # validator0 will also collect the gentx's once gnerated -jq -r ".[0]" <<< "$MNEMONICS" | $BIN init --home /$CHAIN_ID/validator0 --chain-id=$CHAIN_ID validator0 --recover > /dev/null +jq -r ".[0].mnemonic" <<< "$VALIDATORS" | $BIN init --home /$CHAIN_ID/validator0 --chain-id=$CHAIN_ID validator0 --recover > /dev/null # Apply jq transformations to genesis file jq "$GENESIS_TRANSFORM" /$CHAIN_ID/validator0/config/genesis.json > /$CHAIN_ID/edited-genesis.json mv /$CHAIN_ID/edited-genesis.json /$CHAIN_ID/genesis.json -# Sets up an arbitrary number of validators on a single machine by manipulating -# the --home parameter on gaiad + +# CREATE VALIDATOR HOME FOLDERS ETC + for i in $(seq 0 $(($NODES - 1))); do # TODO: we need to pass in an identifier to identify the validator folder and other things instead of @@ -66,18 +57,32 @@ do mkdir -p /$CHAIN_ID/validator$i/config/ # Generate an application key for each validator - jq -r ".[$((i-1))]" <<< "$MNEMONICS" | $BIN keys add validator$i \ + # Sets up an arbitrary number of validators on a single machine by manipulating + # the --home parameter on gaiad + echo "NODE NUMMMMBBBBEBEBRBERBEBREBRBERER" + # echo $i + jq -r ".[$i].mnemonic" <<< "$VALIDATORS" + + jq -r ".[$i].mnemonic" <<< "$VALIDATORS" | $BIN keys add validator$i \ --home /$CHAIN_ID/validator$i \ --keyring-backend test \ --recover > /dev/null - + + echo "validator$i keys:" + $BIN keys show validator$i \ + --home /$CHAIN_ID/validator$i \ + --keyring-backend test \ + # Give validators their initial token allocations # move the genesis in mv /$CHAIN_ID/genesis.json /$CHAIN_ID/validator$i/config/genesis.json - # give this validator some money + + # give this validator some money + ALLOCATION=$(jq -r ".[$i].allocation" <<< "$VALIDATORS") $BIN add-genesis-account validator$i $ALLOCATION \ --home /$CHAIN_ID/validator$i \ --keyring-backend test + # move the genesis back out mv /$CHAIN_ID/validator$i/config/genesis.json /$CHAIN_ID/genesis.json done @@ -91,6 +96,7 @@ do cp /$CHAIN_ID/genesis.json /$CHAIN_ID/validator$i/config/genesis.json # Make a gentx (this command also sets up validator state on disk even if we are not going to use the gentx for anything) + STAKE_AMOUNT=$(jq -r ".[$i].stake" <<< "$VALIDATORS") $BIN gentx validator$i "$STAKE_AMOUNT" \ --home /$CHAIN_ID/validator$i \ --keyring-backend test \ @@ -105,15 +111,20 @@ do fi # Copy in keys from another chain. This is used to start a consumer chain - if [ "$COPY_CONFIGS" != "" ] ; then - cp /$COPY_CONFIGS/validator$i/config/priv_validator_key.json /$CHAIN_ID/validator$i/config/ - cp /$COPY_CONFIGS/validator$i/config/node_key.json /$CHAIN_ID/validator$i/config/ + if [ "$COPY_KEYS" != "" ] ; then + cp /$COPY_KEYS/validator$i/config/priv_validator_key.json /$CHAIN_ID/validator$i/config/ + cp /$COPY_KEYS/validator$i/config/node_key.json /$CHAIN_ID/validator$i/config/ fi done # echo "AFTER GENTXS" # find /$CHAIN_ID/ -print + + + +# COLLECT GENTXS IF WE ARE STARTING A NEW CHAIN + if [ "$SKIP_GENTX" = "false" ] ; then # make the final genesis.json $BIN collect-gentxs --home /$CHAIN_ID/validator0 diff --git a/tests/actions.go b/tests/actions.go index f98216c..4d76dec 100644 --- a/tests/actions.go +++ b/tests/actions.go @@ -71,6 +71,7 @@ type CreateChildChainProposalJSON struct { } func (s System) sendTokens(action SendTokensAction) { + println("FROM ADDRESS", action.from, s.validatorConfigs[action.from].delAddress) bz, err := exec.Command("docker", "exec", s.containerConfig.instanceName, s.containerConfig.binaryName, "tx", "bank", "send", @@ -95,13 +96,22 @@ func (s System) startChain( action StartChainAction, ) { chainConfig := s.chainConfigs[action.chain] - var mnemonics []string + type jsonValAttrs struct { + Mnemonic string `json:"mnemonic"` + Allocation string `json:"allocation"` + Stake string `json:"stake"` + } + var validators []jsonValAttrs for _, val := range action.validators { - mnemonics = append(mnemonics, s.validatorConfigs[val].mnemonic) + validators = append(validators, jsonValAttrs{ + Mnemonic: s.validatorConfigs[val].mnemonic, + Allocation: chainConfig.initialAllocation, + Stake: chainConfig.stakeAmount, + }) } - mnz, err := json.Marshal(mnemonics) + vals, err := json.Marshal(validators) if err != nil { log.Fatal(err) } @@ -114,9 +124,9 @@ func (s System) startChain( } cmd := exec.Command("docker", "exec", s.containerConfig.instanceName, "/bin/bash", - "/testnet-scripts/start-chain/start-chain.sh", s.containerConfig.binaryName, string(mnz), chainConfig.chainId, chainConfig.ipPrefix, - fmt.Sprint(chainConfig.rpcPort), fmt.Sprint(chainConfig.grpcPort), genesisChanges, - chainConfig.initialAllocation, chainConfig.stakeAmount, fmt.Sprint(action.skipGentx), action.copyConfigs) + "/testnet-scripts/start-chain/start-chain.sh", s.containerConfig.binaryName, string(vals), + chainConfig.chainId, chainConfig.ipPrefix, genesisChanges, + fmt.Sprint(action.skipGentx), action.copyConfigs) cmdReader, err := cmd.StdoutPipe() if err != nil { diff --git a/tests/config.go b/tests/config.go index 0d66648..45ec238 100644 --- a/tests/config.go +++ b/tests/config.go @@ -54,15 +54,15 @@ func DefaultSystemConfig() System { validatorConfigs: []ValidatorConfig{ { mnemonic: "pave immune ethics wrap gain ceiling always holiday employ earth tumble real ice engage false unable carbon equal fresh sick tattoo nature pupil nuclear", - delAddress: "cosmos19hz4m226ztankqramvt4a7t0shejv4dc79gp9u", + delAddress: "cosmos19pe9pg5dv9k5fzgzmsrgnw9rl9asf7ddwhu7lm", //"cosmos19hz4m226ztankqramvt4a7t0shejv4dc79gp9u", }, { mnemonic: "glass trip produce surprise diamond spin excess gaze wash drum human solve dress minor artefact canoe hard ivory orange dinner hybrid moral potato jewel", - delAddress: "cosmos19pe9pg5dv9k5fzgzmsrgnw9rl9asf7ddwhu7lm", + delAddress: "cosmos1dkas8mu4kyhl5jrh4nzvm65qz588hy9qcz08la", //"cosmos19pe9pg5dv9k5fzgzmsrgnw9rl9asf7ddwhu7lm", }, { mnemonic: "sight similar better jar bitter laptop solve fashion father jelly scissors chest uniform play unhappy convince silly clump another conduct behave reunion marble animal", - delAddress: "cosmos1dkas8mu4kyhl5jrh4nzvm65qz588hy9qcz08la", + delAddress: "cosmos19hz4m226ztankqramvt4a7t0shejv4dc79gp9u", //"cosmos1dkas8mu4kyhl5jrh4nzvm65qz588hy9qcz08la", }, }, chainConfigs: []ChainConfig{ @@ -89,3 +89,38 @@ func DefaultSystemConfig() System { }, } } + +// { +// mnemonic: "pave immune ethics wrap gain ceiling always holiday employ earth tumble real ice engage false unable carbon equal fresh sick tattoo nature pupil nuclear", +// delAddress: "cosmos1dkas8mu4kyhl5jrh4nzvm65qz588hy9qcz08la", //"cosmos19hz4m226ztankqramvt4a7t0shejv4dc79gp9u", +// }, +// { +// mnemonic: "glass trip produce surprise diamond spin excess gaze wash drum human solve dress minor artefact canoe hard ivory orange dinner hybrid moral potato jewel", +// delAddress: "cosmos19hz4m226ztankqramvt4a7t0shejv4dc79gp9u", //"cosmos19pe9pg5dv9k5fzgzmsrgnw9rl9asf7ddwhu7lm", +// }, +// { +// mnemonic: "sight similar better jar bitter laptop solve fashion father jelly scissors chest uniform play unhappy convince silly clump another conduct behave reunion marble animal", +// delAddress: "cosmos19pe9pg5dv9k5fzgzmsrgnw9rl9asf7ddwhu7lm", //"cosmos1dkas8mu4kyhl5jrh4nzvm65qz588hy9qcz08la", +// }, + +// Working run (-1) +// startChain: sight similar better jar bitter laptop solve fashion father jelly scissors chest uniform play unhappy convince silly clump another conduct behave reunion marble animal +// startChain: +// startChain: validator0 keys: +// startChain: - name: validator0 +// startChain: address: cosmos19hz4m226ztankqramvt4a7t0shejv4dc79gp9u +// startChain: pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"Ao3lig9JxOHZXJG32wgfdzxcaGLcxlnWJYkYT8vftcfa"}' + +// startChain: pave immune ethics wrap gain ceiling always holiday employ earth tumble real ice engage false unable carbon equal fresh sick tattoo nature pupil nuclear +// startChain: +// startChain: validator1 keys: +// startChain: - name: validator1 +// startChain: address: cosmos19pe9pg5dv9k5fzgzmsrgnw9rl9asf7ddwhu7lm +// startChain: pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"AsFC8tmbGGQSHthsVStbsQ13/+Yza9IT8KCSXXEN7y9f"}' + +// startChain: glass trip produce surprise diamond spin excess gaze wash drum human solve dress minor artefact canoe hard ivory orange dinner hybrid moral potato jewel +// startChain: +// startChain: validator2 keys: +// startChain: - name: validator2 +// startChain: address: cosmos1dkas8mu4kyhl5jrh4nzvm65qz588hy9qcz08la +// startChain: pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"ArCv6pseaIkP8SbRqnT4kKylCz5mgAyhwXp8V1q/zU3p"}' From 636c911bd937ac37d2f4427ca9dbee9e2924f63b Mon Sep 17 00:00:00 2001 From: Jehan Tremback Date: Tue, 22 Feb 2022 17:19:36 -0800 Subject: [PATCH 6/9] cleanup --- testnet-scripts/start-chain/start-chain.sh | 10 +++--- tests/config.go | 41 ++-------------------- 2 files changed, 7 insertions(+), 44 deletions(-) diff --git a/testnet-scripts/start-chain/start-chain.sh b/testnet-scripts/start-chain/start-chain.sh index 1c85d3a..2459262 100644 --- a/testnet-scripts/start-chain/start-chain.sh +++ b/testnet-scripts/start-chain/start-chain.sh @@ -59,8 +59,6 @@ do # Generate an application key for each validator # Sets up an arbitrary number of validators on a single machine by manipulating # the --home parameter on gaiad - echo "NODE NUMMMMBBBBEBEBRBERBEBREBRBERER" - # echo $i jq -r ".[$i].mnemonic" <<< "$VALIDATORS" jq -r ".[$i].mnemonic" <<< "$VALIDATORS" | $BIN keys add validator$i \ @@ -68,10 +66,10 @@ do --keyring-backend test \ --recover > /dev/null - echo "validator$i keys:" - $BIN keys show validator$i \ - --home /$CHAIN_ID/validator$i \ - --keyring-backend test \ + # echo "validator$i keys:" + # $BIN keys show validator$i \ + # --home /$CHAIN_ID/validator$i \ + # --keyring-backend test \ # Give validators their initial token allocations # move the genesis in diff --git a/tests/config.go b/tests/config.go index 45ec238..640a4d0 100644 --- a/tests/config.go +++ b/tests/config.go @@ -54,15 +54,15 @@ func DefaultSystemConfig() System { validatorConfigs: []ValidatorConfig{ { mnemonic: "pave immune ethics wrap gain ceiling always holiday employ earth tumble real ice engage false unable carbon equal fresh sick tattoo nature pupil nuclear", - delAddress: "cosmos19pe9pg5dv9k5fzgzmsrgnw9rl9asf7ddwhu7lm", //"cosmos19hz4m226ztankqramvt4a7t0shejv4dc79gp9u", + delAddress: "cosmos19pe9pg5dv9k5fzgzmsrgnw9rl9asf7ddwhu7lm", }, { mnemonic: "glass trip produce surprise diamond spin excess gaze wash drum human solve dress minor artefact canoe hard ivory orange dinner hybrid moral potato jewel", - delAddress: "cosmos1dkas8mu4kyhl5jrh4nzvm65qz588hy9qcz08la", //"cosmos19pe9pg5dv9k5fzgzmsrgnw9rl9asf7ddwhu7lm", + delAddress: "cosmos1dkas8mu4kyhl5jrh4nzvm65qz588hy9qcz08la", }, { mnemonic: "sight similar better jar bitter laptop solve fashion father jelly scissors chest uniform play unhappy convince silly clump another conduct behave reunion marble animal", - delAddress: "cosmos19hz4m226ztankqramvt4a7t0shejv4dc79gp9u", //"cosmos1dkas8mu4kyhl5jrh4nzvm65qz588hy9qcz08la", + delAddress: "cosmos19hz4m226ztankqramvt4a7t0shejv4dc79gp9u", }, }, chainConfigs: []ChainConfig{ @@ -89,38 +89,3 @@ func DefaultSystemConfig() System { }, } } - -// { -// mnemonic: "pave immune ethics wrap gain ceiling always holiday employ earth tumble real ice engage false unable carbon equal fresh sick tattoo nature pupil nuclear", -// delAddress: "cosmos1dkas8mu4kyhl5jrh4nzvm65qz588hy9qcz08la", //"cosmos19hz4m226ztankqramvt4a7t0shejv4dc79gp9u", -// }, -// { -// mnemonic: "glass trip produce surprise diamond spin excess gaze wash drum human solve dress minor artefact canoe hard ivory orange dinner hybrid moral potato jewel", -// delAddress: "cosmos19hz4m226ztankqramvt4a7t0shejv4dc79gp9u", //"cosmos19pe9pg5dv9k5fzgzmsrgnw9rl9asf7ddwhu7lm", -// }, -// { -// mnemonic: "sight similar better jar bitter laptop solve fashion father jelly scissors chest uniform play unhappy convince silly clump another conduct behave reunion marble animal", -// delAddress: "cosmos19pe9pg5dv9k5fzgzmsrgnw9rl9asf7ddwhu7lm", //"cosmos1dkas8mu4kyhl5jrh4nzvm65qz588hy9qcz08la", -// }, - -// Working run (-1) -// startChain: sight similar better jar bitter laptop solve fashion father jelly scissors chest uniform play unhappy convince silly clump another conduct behave reunion marble animal -// startChain: -// startChain: validator0 keys: -// startChain: - name: validator0 -// startChain: address: cosmos19hz4m226ztankqramvt4a7t0shejv4dc79gp9u -// startChain: pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"Ao3lig9JxOHZXJG32wgfdzxcaGLcxlnWJYkYT8vftcfa"}' - -// startChain: pave immune ethics wrap gain ceiling always holiday employ earth tumble real ice engage false unable carbon equal fresh sick tattoo nature pupil nuclear -// startChain: -// startChain: validator1 keys: -// startChain: - name: validator1 -// startChain: address: cosmos19pe9pg5dv9k5fzgzmsrgnw9rl9asf7ddwhu7lm -// startChain: pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"AsFC8tmbGGQSHthsVStbsQ13/+Yza9IT8KCSXXEN7y9f"}' - -// startChain: glass trip produce surprise diamond spin excess gaze wash drum human solve dress minor artefact canoe hard ivory orange dinner hybrid moral potato jewel -// startChain: -// startChain: validator2 keys: -// startChain: - name: validator2 -// startChain: address: cosmos1dkas8mu4kyhl5jrh4nzvm65qz588hy9qcz08la -// startChain: pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"ArCv6pseaIkP8SbRqnT4kKylCz5mgAyhwXp8V1q/zU3p"}' From 2f98e5674a0dd96f8940a89fcc9e40433bdea705 Mon Sep 17 00:00:00 2001 From: Jehan Tremback Date: Wed, 23 Feb 2022 14:46:31 -0800 Subject: [PATCH 7/9] make jq syntax a little nicer --- testnet-scripts/start-chain/start-chain.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/testnet-scripts/start-chain/start-chain.sh b/testnet-scripts/start-chain/start-chain.sh index 2459262..d7b28f6 100644 --- a/testnet-scripts/start-chain/start-chain.sh +++ b/testnet-scripts/start-chain/start-chain.sh @@ -9,6 +9,7 @@ BIN=$1 # mnemonic: "crackle snap pop ... etc", # allocation: "10000000000stake,10000000000footoken", # stake: "5000000000stake", +# number: "0" # }, ... ] VALIDATORS=$2 @@ -34,11 +35,11 @@ COPY_KEYS=$7 # CREATE VALIDATORS AND DO GENESIS CEREMONY # Get number of nodes from length of validators array -NODES=$(jq '. | length' <<< "$VALIDATORS") +NODES=$(echo "$VALIDATORS" | jq '. | length') # first we start a genesis.json with validator0 # validator0 will also collect the gentx's once gnerated -jq -r ".[0].mnemonic" <<< "$VALIDATORS" | $BIN init --home /$CHAIN_ID/validator0 --chain-id=$CHAIN_ID validator0 --recover > /dev/null +echo "$VALIDATORS" | jq -r ".[0].mnemonic" | $BIN init --home /$CHAIN_ID/validator0 --chain-id=$CHAIN_ID validator0 --recover > /dev/null # Apply jq transformations to genesis file jq "$GENESIS_TRANSFORM" /$CHAIN_ID/validator0/config/genesis.json > /$CHAIN_ID/edited-genesis.json @@ -59,9 +60,7 @@ do # Generate an application key for each validator # Sets up an arbitrary number of validators on a single machine by manipulating # the --home parameter on gaiad - jq -r ".[$i].mnemonic" <<< "$VALIDATORS" - - jq -r ".[$i].mnemonic" <<< "$VALIDATORS" | $BIN keys add validator$i \ + echo "$VALIDATORS" | jq -r ".[$i].mnemonic" | $BIN keys add validator$i \ --home /$CHAIN_ID/validator$i \ --keyring-backend test \ --recover > /dev/null @@ -76,7 +75,7 @@ do mv /$CHAIN_ID/genesis.json /$CHAIN_ID/validator$i/config/genesis.json # give this validator some money - ALLOCATION=$(jq -r ".[$i].allocation" <<< "$VALIDATORS") + ALLOCATION=$(echo "$VALIDATORS" | jq -r ".[$i].allocation") $BIN add-genesis-account validator$i $ALLOCATION \ --home /$CHAIN_ID/validator$i \ --keyring-backend test @@ -94,7 +93,7 @@ do cp /$CHAIN_ID/genesis.json /$CHAIN_ID/validator$i/config/genesis.json # Make a gentx (this command also sets up validator state on disk even if we are not going to use the gentx for anything) - STAKE_AMOUNT=$(jq -r ".[$i].stake" <<< "$VALIDATORS") + STAKE_AMOUNT=$(echo "$VALIDATORS" | jq -r ".[$i].stake") $BIN gentx validator$i "$STAKE_AMOUNT" \ --home /$CHAIN_ID/validator$i \ --keyring-backend test \ From 199c42f9460c65647486612c1c836152a30a485c Mon Sep 17 00:00:00 2001 From: Jehan Tremback Date: Wed, 23 Feb 2022 16:28:16 -0800 Subject: [PATCH 8/9] allow passing validators in arbitrary order --- testnet-scripts/start-chain/start-chain.sh | 81 +++++++++++----------- tests/actions.go | 2 + tests/steps.go | 4 +- 3 files changed, 46 insertions(+), 41 deletions(-) diff --git a/testnet-scripts/start-chain/start-chain.sh b/testnet-scripts/start-chain/start-chain.sh index d7b28f6..151a616 100644 --- a/testnet-scripts/start-chain/start-chain.sh +++ b/testnet-scripts/start-chain/start-chain.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -eu +set -eux # The gaiad binary BIN=$1 @@ -37,12 +37,13 @@ COPY_KEYS=$7 # Get number of nodes from length of validators array NODES=$(echo "$VALIDATORS" | jq '. | length') -# first we start a genesis.json with validator0 -# validator0 will also collect the gentx's once gnerated -echo "$VALIDATORS" | jq -r ".[0].mnemonic" | $BIN init --home /$CHAIN_ID/validator0 --chain-id=$CHAIN_ID validator0 --recover > /dev/null +# first we start a genesis.json with the first validator +# the first validator will also collect the gentx's once gnerated +FIRST_VAL_ID=$(echo "$VALIDATORS" | jq -r ".[0].number") +echo "$VALIDATORS" | jq -r ".[0].mnemonic" | $BIN init --home /$CHAIN_ID/validator$FIRST_VAL_ID --chain-id=$CHAIN_ID validator$FIRST_VAL_ID --recover > /dev/null # Apply jq transformations to genesis file -jq "$GENESIS_TRANSFORM" /$CHAIN_ID/validator0/config/genesis.json > /$CHAIN_ID/edited-genesis.json +jq "$GENESIS_TRANSFORM" /$CHAIN_ID/validator$FIRST_VAL_ID/config/genesis.json > /$CHAIN_ID/edited-genesis.json mv /$CHAIN_ID/edited-genesis.json /$CHAIN_ID/genesis.json @@ -51,17 +52,15 @@ mv /$CHAIN_ID/edited-genesis.json /$CHAIN_ID/genesis.json for i in $(seq 0 $(($NODES - 1))); do - # TODO: we need to pass in an identifier to identify the validator folder and other things instead of - # using the index. The current code WILL BREAK if you supply validators in any other order than 0,1,2 etc - + VAL_ID=$(echo "$VALIDATORS" | jq -r ".[$i].number") # make the folders for this validator - mkdir -p /$CHAIN_ID/validator$i/config/ + mkdir -p /$CHAIN_ID/validator$VAL_ID/config/ # Generate an application key for each validator # Sets up an arbitrary number of validators on a single machine by manipulating # the --home parameter on gaiad - echo "$VALIDATORS" | jq -r ".[$i].mnemonic" | $BIN keys add validator$i \ - --home /$CHAIN_ID/validator$i \ + echo "$VALIDATORS" | jq -r ".[$i].mnemonic" | $BIN keys add validator$VAL_ID \ + --home /$CHAIN_ID/validator$VAL_ID \ --keyring-backend test \ --recover > /dev/null @@ -72,16 +71,16 @@ do # Give validators their initial token allocations # move the genesis in - mv /$CHAIN_ID/genesis.json /$CHAIN_ID/validator$i/config/genesis.json + mv /$CHAIN_ID/genesis.json /$CHAIN_ID/validator$VAL_ID/config/genesis.json # give this validator some money ALLOCATION=$(echo "$VALIDATORS" | jq -r ".[$i].allocation") - $BIN add-genesis-account validator$i $ALLOCATION \ - --home /$CHAIN_ID/validator$i \ + $BIN add-genesis-account validator$VAL_ID $ALLOCATION \ + --home /$CHAIN_ID/validator$VAL_ID \ --keyring-backend test # move the genesis back out - mv /$CHAIN_ID/validator$i/config/genesis.json /$CHAIN_ID/genesis.json + mv /$CHAIN_ID/validator$VAL_ID/config/genesis.json /$CHAIN_ID/genesis.json done # echo "BEFORE GENTXS" @@ -89,28 +88,29 @@ done for i in $(seq 0 $(($NODES - 1))); do + VAL_ID=$(echo "$VALIDATORS" | jq -r ".[$i].number") # Copy in the genesis.json - cp /$CHAIN_ID/genesis.json /$CHAIN_ID/validator$i/config/genesis.json + cp /$CHAIN_ID/genesis.json /$CHAIN_ID/validator$VAL_ID/config/genesis.json # Make a gentx (this command also sets up validator state on disk even if we are not going to use the gentx for anything) STAKE_AMOUNT=$(echo "$VALIDATORS" | jq -r ".[$i].stake") - $BIN gentx validator$i "$STAKE_AMOUNT" \ - --home /$CHAIN_ID/validator$i \ + $BIN gentx validator$VAL_ID "$STAKE_AMOUNT" \ + --home /$CHAIN_ID/validator$VAL_ID \ --keyring-backend test \ - --moniker validator$i \ + --moniker validator$VAL_ID \ --chain-id=$CHAIN_ID \ - --ip $CHAIN_IP_PREFIX.$i + --ip $CHAIN_IP_PREFIX.$VAL_ID - # Copy gentxs to validator0 for possible future collection. - # Obviously we don't need to copy validator0's gentx to itself - if [ $i -gt 0 ]; then - cp /$CHAIN_ID/validator$i/config/gentx/* /$CHAIN_ID/validator0/config/gentx/ + # Copy gentxs to the first validator for possible future collection. + # Obviously we don't need to copy the first validator's gentx to itself + if [ $VAL_ID != $FIRST_VAL_ID ]; then + cp /$CHAIN_ID/validator$VAL_ID/config/gentx/* /$CHAIN_ID/validator$FIRST_VAL_ID/config/gentx/ fi # Copy in keys from another chain. This is used to start a consumer chain if [ "$COPY_KEYS" != "" ] ; then - cp /$COPY_KEYS/validator$i/config/priv_validator_key.json /$CHAIN_ID/validator$i/config/ - cp /$COPY_KEYS/validator$i/config/node_key.json /$CHAIN_ID/validator$i/config/ + cp /$COPY_KEYS/validator$VAL_ID/config/priv_validator_key.json /$CHAIN_ID/validator$VAL_ID/config/ + cp /$COPY_KEYS/validator$VAL_ID/config/node_key.json /$CHAIN_ID/validator$VAL_ID/config/ fi done @@ -124,15 +124,16 @@ done if [ "$SKIP_GENTX" = "false" ] ; then # make the final genesis.json - $BIN collect-gentxs --home /$CHAIN_ID/validator0 + $BIN collect-gentxs --home /$CHAIN_ID/validator$FIRST_VAL_ID # and copy it to the root - cp /$CHAIN_ID/validator0/config/genesis.json /$CHAIN_ID/genesis.json + cp /$CHAIN_ID/validator$FIRST_VAL_ID/config/genesis.json /$CHAIN_ID/genesis.json # put the now final genesis.json into the correct folders for i in $(seq 1 $(($NODES - 1))); do - cp /$CHAIN_ID/genesis.json /$CHAIN_ID/validator$i/config/genesis.json + VAL_ID=$(echo "$VALIDATORS" | jq -r ".[$i].number") + cp /$CHAIN_ID/genesis.json /$CHAIN_ID/validator$VAL_ID/config/genesis.json done fi @@ -143,14 +144,15 @@ fi for i in $(seq 0 $(($NODES - 1))); do + VAL_ID=$(echo "$VALIDATORS" | jq -r ".[$i].number") # add this ip for loopback dialing - ip addr add $CHAIN_IP_PREFIX.$i/32 dev eth0 || true # allowed to fail + ip addr add $CHAIN_IP_PREFIX.$VAL_ID/32 dev eth0 || true # allowed to fail - GAIA_HOME="--home /$CHAIN_ID/validator$i" - RPC_ADDRESS="--rpc.laddr tcp://$CHAIN_IP_PREFIX.$i:26658" - GRPC_ADDRESS="--grpc.address $CHAIN_IP_PREFIX.$i:9091" - LISTEN_ADDRESS="--address tcp://$CHAIN_IP_PREFIX.$i:26655" - P2P_ADDRESS="--p2p.laddr tcp://$CHAIN_IP_PREFIX.$i:26656" + GAIA_HOME="--home /$CHAIN_ID/validator$VAL_ID" + RPC_ADDRESS="--rpc.laddr tcp://$CHAIN_IP_PREFIX.$VAL_ID:26658" + GRPC_ADDRESS="--grpc.address $CHAIN_IP_PREFIX.$VAL_ID:9091" + LISTEN_ADDRESS="--address tcp://$CHAIN_IP_PREFIX.$VAL_ID:26655" + P2P_ADDRESS="--p2p.laddr tcp://$CHAIN_IP_PREFIX.$VAL_ID:26656" LOG_LEVEL="--log_level info" ENABLE_WEBGRPC="--grpc-web.enable=false" @@ -159,8 +161,9 @@ do for j in $(seq 0 $(($NODES - 1))); do if [ $i -ne $j ]; then - NODE_ID=$($BIN tendermint show-node-id --home /$CHAIN_ID/validator$j) - ADDRESS="$NODE_ID@$CHAIN_IP_PREFIX.$j:26656" + PEER_VAL_ID=$(echo "$VALIDATORS" | jq -r ".[$j].number") + NODE_ID=$($BIN tendermint show-node-id --home /$CHAIN_ID/validator$PEER_VAL_ID) + ADDRESS="$NODE_ID@$CHAIN_IP_PREFIX.$PEER_VAL_ID:26656" # (jq -r '.body.memo' /$CHAIN_ID/validator$j/config/gentx/*) # Getting the address from the gentx should also work PERSISTENT_PEERS="$PERSISTENT_PEERS,$ADDRESS" fi @@ -170,7 +173,7 @@ do PERSISTENT_PEERS="--p2p.persistent_peers ${PERSISTENT_PEERS:1}" ARGS="$GAIA_HOME $LISTEN_ADDRESS $RPC_ADDRESS $GRPC_ADDRESS $LOG_LEVEL $P2P_ADDRESS $ENABLE_WEBGRPC $PERSISTENT_PEERS" - $BIN $ARGS start &> /$CHAIN_ID/validator$i/logs & + $BIN $ARGS start &> /$CHAIN_ID/validator$VAL_ID/logs & done @@ -178,7 +181,7 @@ done # poll for chain start set +e -until interchain-securityd query block --node "tcp://$CHAIN_IP_PREFIX.0:26658" | grep -q -v '{"block_id":{"hash":"","parts":{"total":0,"hash":""}},"block":null}'; do sleep 0.3 ; done +until interchain-securityd query block --node "tcp://$CHAIN_IP_PREFIX.$FIRST_VAL_ID:26658" | grep -q -v '{"block_id":{"hash":"","parts":{"total":0,"hash":""}},"block":null}'; do sleep 0.3 ; done set -e echo "done!!!!!!!!" diff --git a/tests/actions.go b/tests/actions.go index 4d76dec..28ab410 100644 --- a/tests/actions.go +++ b/tests/actions.go @@ -100,6 +100,7 @@ func (s System) startChain( Mnemonic string `json:"mnemonic"` Allocation string `json:"allocation"` Stake string `json:"stake"` + Number string `json:"number"` } var validators []jsonValAttrs @@ -108,6 +109,7 @@ func (s System) startChain( Mnemonic: s.validatorConfigs[val].mnemonic, Allocation: chainConfig.initialAllocation, Stake: chainConfig.stakeAmount, + Number: fmt.Sprint(val), }) } diff --git a/tests/steps.go b/tests/steps.go index 8267157..3071775 100644 --- a/tests/steps.go +++ b/tests/steps.go @@ -75,7 +75,7 @@ var exampleSteps1 = []Step{ { action: StartChainAction{ chain: 0, - validators: []uint{0, 1, 2}, + validators: []uint{1, 0, 2}, }, state: State{ 0: ChainState{ @@ -158,7 +158,7 @@ var exampleSteps1 = []Step{ action: StartConsumerChainAction{ consumerChain: 1, providerChain: 0, - validators: []uint{0, 1, 2}, + validators: []uint{2, 1, 0}, }, state: State{ 0: ChainState{ From c794ecfde7667c9a8763f0b2524a6765551a160d Mon Sep 17 00:00:00 2001 From: Jehan Tremback Date: Wed, 23 Feb 2022 16:59:32 -0800 Subject: [PATCH 9/9] comment cleanup --- testnet-scripts/start-chain/start-chain.sh | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/testnet-scripts/start-chain/start-chain.sh b/testnet-scripts/start-chain/start-chain.sh index 151a616..e37b0f2 100644 --- a/testnet-scripts/start-chain/start-chain.sh +++ b/testnet-scripts/start-chain/start-chain.sh @@ -48,6 +48,7 @@ mv /$CHAIN_ID/edited-genesis.json /$CHAIN_ID/genesis.json + # CREATE VALIDATOR HOME FOLDERS ETC for i in $(seq 0 $(($NODES - 1))); @@ -64,11 +65,6 @@ do --keyring-backend test \ --recover > /dev/null - # echo "validator$i keys:" - # $BIN keys show validator$i \ - # --home /$CHAIN_ID/validator$i \ - # --keyring-backend test \ - # Give validators their initial token allocations # move the genesis in mv /$CHAIN_ID/genesis.json /$CHAIN_ID/validator$VAL_ID/config/genesis.json @@ -83,8 +79,9 @@ do mv /$CHAIN_ID/validator$VAL_ID/config/genesis.json /$CHAIN_ID/genesis.json done -# echo "BEFORE GENTXS" -# find /$CHAIN_ID/ -print + + +# MAKE GENTXS AND SET UP LOCAL VALIDATOR STATE for i in $(seq 0 $(($NODES - 1))); do @@ -114,9 +111,6 @@ do fi done -# echo "AFTER GENTXS" -# find /$CHAIN_ID/ -print -