From 150931950dd2dd531d0643314ae9e3c46503cdf3 Mon Sep 17 00:00:00 2001 From: Akihito Nakano Date: Wed, 26 Jan 2022 23:14:20 +0000 Subject: [PATCH] Fix errors from local testnet scripts on MacOS (#2919) ## Issue Addressed Resolves https://github.com/sigp/lighthouse/issues/2763 ## Proposed Changes - Add a workflow which tests that local testnet starts successfully - Added `set` option into the scripts in order to fail fast so that we can notice errors during starting local testnet. - Fix errors on MacOS - The redirect `&>>` is supported since bash v4 but the version bundled in macOS(11.6.1) is v3. https://github.com/sigp/lighthouse/pull/2919/commits/a54f119c9b1839fd0909792d219858e727e120a2 --- .github/workflows/local-testnet.yml | 50 ++++++++++++++++++++ scripts/local_testnet/beacon_node.sh | 2 + scripts/local_testnet/bootnode.sh | 2 + scripts/local_testnet/clean.sh | 2 + scripts/local_testnet/ganache_test_node.sh | 2 + scripts/local_testnet/kill_processes.sh | 2 + scripts/local_testnet/print_logs.sh | 17 +++++++ scripts/local_testnet/reset_genesis_time.sh | 2 + scripts/local_testnet/start_local_testnet.sh | 8 ++-- scripts/local_testnet/stop_local_testnet.sh | 2 + scripts/local_testnet/validator_client.sh | 2 + scripts/local_testnet/vars.env | 3 ++ 12 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/local-testnet.yml create mode 100755 scripts/local_testnet/print_logs.sh diff --git a/.github/workflows/local-testnet.yml b/.github/workflows/local-testnet.yml new file mode 100644 index 000000000..f97b271c3 --- /dev/null +++ b/.github/workflows/local-testnet.yml @@ -0,0 +1,50 @@ +# Test that local testnet starts successfully. +name: local testnet + +on: + push: + branches: + - unstable + pull_request: + +jobs: + run-local-testnet: + strategy: + matrix: + os: + - ubuntu-18.04 + - macos-latest + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v1 + + - name: Install ganache + run: npm install ganache-cli@latest --global + + # https://github.com/actions/cache/blob/main/examples.md#rust---cargo + - uses: actions/cache@v2 + id: cache-cargo + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + + - name: Install lighthouse + if: steps.cache-cargo.outputs.cache-hit != 'true' + run: make && make install-lcli + + - name: Start local testnet + run: ./start_local_testnet.sh + working-directory: scripts/local_testnet + + - name: Print logs + run: ./print_logs.sh + working-directory: scripts/local_testnet + + - name: Stop local testnet + run: ./stop_local_testnet.sh + working-directory: scripts/local_testnet diff --git a/scripts/local_testnet/beacon_node.sh b/scripts/local_testnet/beacon_node.sh index 883c66602..8151aac24 100755 --- a/scripts/local_testnet/beacon_node.sh +++ b/scripts/local_testnet/beacon_node.sh @@ -4,6 +4,8 @@ # Starts a beacon node based upon a genesis state created by `./setup.sh`. # +set -Eeuo pipefail + source ./vars.env SUBSCRIBE_ALL_SUBNETS= diff --git a/scripts/local_testnet/bootnode.sh b/scripts/local_testnet/bootnode.sh index bef207a69..ca02a2414 100755 --- a/scripts/local_testnet/bootnode.sh +++ b/scripts/local_testnet/bootnode.sh @@ -5,6 +5,8 @@ # Starts a bootnode from the generated enr. # +set -Eeuo pipefail + source ./vars.env echo "Generating bootnode enr" diff --git a/scripts/local_testnet/clean.sh b/scripts/local_testnet/clean.sh index bc4db74c6..b01b1a2df 100755 --- a/scripts/local_testnet/clean.sh +++ b/scripts/local_testnet/clean.sh @@ -4,6 +4,8 @@ # Deletes all files associated with the local testnet. # +set -Eeuo pipefail + source ./vars.env if [ -d $DATADIR ]; then diff --git a/scripts/local_testnet/ganache_test_node.sh b/scripts/local_testnet/ganache_test_node.sh index 762700dbd..69edc1e77 100755 --- a/scripts/local_testnet/ganache_test_node.sh +++ b/scripts/local_testnet/ganache_test_node.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +set -Eeuo pipefail + source ./vars.env exec ganache-cli \ diff --git a/scripts/local_testnet/kill_processes.sh b/scripts/local_testnet/kill_processes.sh index c729a1645..4f52a5f25 100755 --- a/scripts/local_testnet/kill_processes.sh +++ b/scripts/local_testnet/kill_processes.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash # Kill processes +set -Eeuo pipefail + # First parameter is the file with # one pid per line. if [ -f "$1" ]; then diff --git a/scripts/local_testnet/print_logs.sh b/scripts/local_testnet/print_logs.sh new file mode 100755 index 000000000..2a9e7822a --- /dev/null +++ b/scripts/local_testnet/print_logs.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# Print the tail of all the logs output from local testnet + +set -Eeuo pipefail + +source ./vars.env + +for f in "$TESTNET_DIR"/*.log +do + [[ -e "$f" ]] || break # handle the case of no *.log files + echo "=============================================================================" + echo "$f" + echo "=============================================================================" + tail "$f" + echo "" +done diff --git a/scripts/local_testnet/reset_genesis_time.sh b/scripts/local_testnet/reset_genesis_time.sh index c7332e327..68c8fb6b4 100755 --- a/scripts/local_testnet/reset_genesis_time.sh +++ b/scripts/local_testnet/reset_genesis_time.sh @@ -4,6 +4,8 @@ # Resets the beacon state genesis time to now. # +set -Eeuo pipefail + source ./vars.env NOW=$(date +%s) diff --git a/scripts/local_testnet/start_local_testnet.sh b/scripts/local_testnet/start_local_testnet.sh index cdae9b2ba..7126e4c5d 100755 --- a/scripts/local_testnet/start_local_testnet.sh +++ b/scripts/local_testnet/start_local_testnet.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash # Start all processes necessary to create a local testnet +set -Eeuo pipefail + source ./vars.env # VC_COUNT is defaulted in vars.env @@ -49,7 +51,7 @@ for (( bn=1; bn<=$BN_COUNT; bn++ )); do done for (( vc=1; vc<=$VC_COUNT; vc++ )); do touch $LOG_DIR/validator_node_$vc.log -done +done # Sleep with a message sleeping() { @@ -67,7 +69,7 @@ execute_command() { EX_NAME=$2 shift shift - CMD="$EX_NAME $@ &>> $LOG_DIR/$LOG_NAME" + CMD="$EX_NAME $@ >> $LOG_DIR/$LOG_NAME 2>&1" echo "executing: $CMD" echo "$CMD" > "$LOG_DIR/$LOG_NAME" eval "$CMD &" @@ -89,7 +91,7 @@ execute_command_add_PID() { # Delay to let ganache-cli to get started execute_command_add_PID ganache_test_node.log ./ganache_test_node.sh -sleeping 2 +sleeping 10 # Delay to get data setup execute_command setup.log ./setup.sh diff --git a/scripts/local_testnet/stop_local_testnet.sh b/scripts/local_testnet/stop_local_testnet.sh index 47f390ba7..b1c3188ee 100755 --- a/scripts/local_testnet/stop_local_testnet.sh +++ b/scripts/local_testnet/stop_local_testnet.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash # Stop all processes that were started with start_local_testnet.sh +set -Eeuo pipefail + source ./vars.env PID_FILE=$TESTNET_DIR/PIDS.pid diff --git a/scripts/local_testnet/validator_client.sh b/scripts/local_testnet/validator_client.sh index 6755384be..5aa75dfe2 100755 --- a/scripts/local_testnet/validator_client.sh +++ b/scripts/local_testnet/validator_client.sh @@ -6,6 +6,8 @@ # # Usage: ./validator_client.sh +set -Eeuo pipefail + source ./vars.env DEBUG_LEVEL=${3:-info} diff --git a/scripts/local_testnet/vars.env b/scripts/local_testnet/vars.env index f88e9eb71..208fbb6d8 100644 --- a/scripts/local_testnet/vars.env +++ b/scripts/local_testnet/vars.env @@ -43,3 +43,6 @@ SECONDS_PER_SLOT=3 # Seconds per Eth1 block SECONDS_PER_ETH1_BLOCK=1 + +# Command line arguments for validator client +VC_ARGS=""