Skip to content

Commit

Permalink
Dockernet Host Chain ID (#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs authored Dec 1, 2022
1 parent 730cf3d commit df2fcea
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 63 deletions.
36 changes: 18 additions & 18 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down Expand Up @@ -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})
```
Expand Down
2 changes: 0 additions & 2 deletions scripts/create_logs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
27 changes: 14 additions & 13 deletions scripts/init_chain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down
19 changes: 10 additions & 9 deletions scripts/register_host.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
11 changes: 2 additions & 9 deletions scripts/start_chain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions scripts/start_network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 &
2 changes: 0 additions & 2 deletions scripts/start_relayers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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) }')
Expand Down
2 changes: 0 additions & 2 deletions scripts/tests/run_all_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

9 changes: 6 additions & 3 deletions scripts/vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit df2fcea

Please sign in to comment.