From ec9960de17705de04134b4f693bd88468f9c7f7e Mon Sep 17 00:00:00 2001 From: kylezs Date: Wed, 1 Nov 2023 01:20:47 +1100 Subject: [PATCH] refactor: more parameterising of start-engine.sh (#4186) * refactor: pass in env vars to start-engine * refactor: allow for starting engines with different log file * chore: explicit binary root path * chore: comments --- localnet/init/scripts/start-all-engines.sh | 13 +++++++++++++ localnet/init/scripts/start-engine.sh | 16 +++++++--------- localnet/manage.sh | 21 ++++++--------------- 3 files changed, 26 insertions(+), 24 deletions(-) create mode 100755 localnet/init/scripts/start-all-engines.sh diff --git a/localnet/init/scripts/start-all-engines.sh b/localnet/init/scripts/start-all-engines.sh new file mode 100755 index 0000000000..794bf6dda6 --- /dev/null +++ b/localnet/init/scripts/start-all-engines.sh @@ -0,0 +1,13 @@ +# Starts all the engines necessary for the network, or for an upgrade. + +ENGINE_P2P_PORT=3100 +LOG_PORT=30687 +for NODE in $SELECTED_NODES; do + cp -R $LOCALNET_INIT_DIR/keyshare/$NODE_COUNT/$NODE.db /tmp/chainflip/$NODE + BINARY_ROOT_PATH=$BINARY_ROOT_PATH NODE_NAME=$NODE P2P_PORT=$ENGINE_P2P_PORT SC_RPC_PORT=$SC_RPC_PORT LOG_PORT=$LOG_PORT HEALTH_PORT=$HEALTH_PORT LOG_SUFFIX=$LOG_SUFFIX ./$LOCALNET_INIT_DIR/scripts/start-engine.sh + echo "🚗 Starting chainflip-engine of $NODE ..." + ((SC_RPC_PORT++)) + ((ENGINE_P2P_PORT++)) + ((HEALTH_PORT++)) + ((LOG_PORT++)) +done \ No newline at end of file diff --git a/localnet/init/scripts/start-engine.sh b/localnet/init/scripts/start-engine.sh index efdcb9b0d3..3b3e6a692d 100755 --- a/localnet/init/scripts/start-engine.sh +++ b/localnet/init/scripts/start-engine.sh @@ -1,19 +1,17 @@ #!/bin/bash + +# LOG_SUFFIX is optional. It can be used to differentiate between the logs of two engines, potentially with the same owner +# e.g. in the case of an upgrade where we run two engines simultaneously. + set -e -BINARY_ROOT_PATH=$1 -NODE_NAME=$2 -PORT=$3 -HEALTH_PORT=$4 -RPC_PORT=$5 -LOG_PORT=$6 source ./localnet/init/env/cfe.env $BINARY_ROOT_PATH/chainflip-engine \ --config-root=./localnet/init/ \ --eth.private_key_file=./localnet/init/keys/$NODE_NAME/eth_private_key_file \ --state_chain.signing_key_file=./localnet/init/keys/$NODE_NAME/signing_key_file \ - --state_chain.ws_endpoint=ws://localhost:$RPC_PORT \ + --state_chain.ws_endpoint=ws://localhost:$SC_RPC_PORT \ --p2p.node_key_file=./localnet/init/keys/$NODE_NAME/node_key_file \ - --p2p.port=$PORT \ + --p2p.port=$P2P_PORT \ --logging.command_server_port=$LOG_PORT \ --signing.db_file=/tmp/chainflip/$NODE_NAME/$NODE_NAME.db \ - --health_check.port=$HEALTH_PORT > /tmp/chainflip/$NODE_NAME/chainflip-engine.log 2>&1 & + --health_check.port=$HEALTH_PORT > /tmp/chainflip/$NODE_NAME/chainflip-engine$LOG_SUFFIX.log 2>&1 & diff --git a/localnet/manage.sh b/localnet/manage.sh index dbf148626c..9e8f499e2d 100755 --- a/localnet/manage.sh +++ b/localnet/manage.sh @@ -109,8 +109,10 @@ build-localnet() { DOT_GENESIS_HASH=$(echo $REPLY | grep -o '\"result\":\"0x[^"]*' | grep -o '0x.*') + INIT_RPC_PORT=9944 + P2P_PORT=30333 - RPC_PORT=9944 + RPC_PORT=$INIT_RPC_PORT for NODE in "${SELECTED_NODES[@]}"; do echo "🚧 Starting chainflip-node of $NODE ..." DOT_GENESIS_HASH=${DOT_GENESIS_HASH:2} ./$LOCALNET_INIT_DIR/scripts/start-node.sh $BINARY_ROOT_PATH $NODE $P2P_PORT $RPC_PORT $NODE_COUNT @@ -118,28 +120,17 @@ build-localnet() { ((RPC_PORT++)) done - RPC_PORT=9944 + RPC_PORT=$INIT_RPC_PORT for NODE in "${SELECTED_NODES[@]}"; do check_endpoint_health -s -H "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "chain_getBlock"}' "http://localhost:$RPC_PORT" > /dev/null echo "💚 $NODE's chainflip-node is running!" ((RPC_PORT++)) done - RPC_PORT=9944 - ENGINE_PORT=8078 HEALTH_PORT=5555 - LOG_PORT=30687 - for NODE in "${SELECTED_NODES[@]}"; do - cp -R $LOCALNET_INIT_DIR/keyshare/$NODE_COUNT/$NODE.db /tmp/chainflip/$NODE - ./$LOCALNET_INIT_DIR/scripts/start-engine.sh $BINARY_ROOT_PATH $NODE $ENGINE_PORT $HEALTH_PORT $RPC_PORT $LOG_PORT & - echo "🚗 Starting chainflip-engine of $NODE ..." - ((RPC_PORT++)) - ((ENGINE_PORT++)) - ((LOG_PORT++)) - ((HEALTH_PORT++)) - done - HEALTH_PORT=5555 + BINARY_ROOT_PATH=$BINARY_ROOT_PATH SC_RPC_PORT=$INIT_RPC_PORT HEALTH_PORT=$HEALTH_PORT LOCALNET_INIT_DIR=$LOCALNET_INIT_DIR SELECTED_NODES=${SELECTED_NODES[@]} ./$LOCALNET_INIT_DIR/scripts/start-all-engines.sh + for NODE in "${SELECTED_NODES[@]}"; do while true; do output=$(check_endpoint_health "http://localhost:$HEALTH_PORT/health")