From 0dfafb204993000d91284e9a7b50e212f3dfecfd Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Tue, 14 Mar 2023 16:23:15 +0000 Subject: [PATCH 01/25] Add check_bootnode script and github action --- .github/workflows/check-bootnodes.yml | 18 ++++ scripts/ci/github/check_bootnodes.sh | 113 ++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 .github/workflows/check-bootnodes.yml create mode 100755 scripts/ci/github/check_bootnodes.sh diff --git a/.github/workflows/check-bootnodes.yml b/.github/workflows/check-bootnodes.yml new file mode 100644 index 000000000000..f66ac6220385 --- /dev/null +++ b/.github/workflows/check-bootnodes.yml @@ -0,0 +1,18 @@ +# checks all runtimes we care about (kusama, polkadot, westend) and ensures +# the bootnodes in their respective chainspecs are contactable + +name: Check all bootnodes +on: push + +jobs: + check_bootnodes: + strategy: + matrix: + runtime: [westend, kusama, polkadot] + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v3 + - name: Check ${{ matrix.runtime }} bootnodes + shell: bash + run: scripts/ci/github/check_bootnodes.sh ${{ matrix.runtime }} \ No newline at end of file diff --git a/scripts/ci/github/check_bootnodes.sh b/scripts/ci/github/check_bootnodes.sh new file mode 100755 index 000000000000..361ad794af86 --- /dev/null +++ b/scripts/ci/github/check_bootnodes.sh @@ -0,0 +1,113 @@ +#!/usr/bin/env bash + +# In this script, we check each bootnode for each runtime and ensure they are contactable. +# We do this by removing every bootnode from the chainspec with the exception of the one +# we want to check. Then we spin up a node using this new chainspec, wait a little while +# and then check our local node's RPC endpoint for the number of peers. If the node hasn't +# been able to contact any other nodes, we can reason that the bootnode we used is not well-connected +# or is otherwise uncontactable. + +# Root of the polkadot dir +ROOT="$(dirname "${0}")/../../.." +RUNTIME="$1" + +trap cleanup EXIT INT TERM + +cleanup(){ + echo "[+] Script interrupted or ended. Cleaning up..." + # Kill all the polkadot processes + killall polkadot > /dev/null 2>&1 +} + +check_bootnode(){ + BOOTNODE_INDEX=$1 + TMP_CHAINSPEC_FILE="$RUNTIME.$BOOTNODE_INDEX.tmp.json" + FINAL_CHAINSPEC_FILE="$RUNTIME.$BOOTNODE_INDEX.final.json" + # Copy the chainspec file to a temporary location to avoid weird race conditions when running in parallel + cp "$CHAINSPEC_FILE" "$CHAINSPEC_TMPDIR/$TMP_CHAINSPEC_FILE" + pushd "$CHAINSPEC_TMPDIR" > /dev/null || exit 1 + jq ".bootNodes |= [.[$BOOTNODE_INDEX]] " < "$TMP_CHAINSPEC_FILE" > "$FINAL_CHAINSPEC_FILE" + BOOTNODE=$( jq -r '.bootNodes[0]' < "$FINAL_CHAINSPEC_FILE" ) + # Get the first ephemeral port + BASE_PORT=$(sysctl net.inet.ip.portrange.first | awk '{print $2}') + RPC_PORT=$((BASE_PORT + BOOTNODE_INDEX)) + echo "[+] Checking bootnode $BOOTNODE" + polkadot --chain "$FINAL_CHAINSPEC_FILE" --no-mdns --rpc-port=$RPC_PORT --tmp > /dev/null 2>&1 & + POLKADOT_PID=$! + # We just spun up a bunch of nodes... probably want to wait a bit. + sleep 60 + popd > /dev/null || exit 1 + # Check the health endpoint of the RPC node + PEERS="$(curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"system_health","params":[],"id":1}' http://localhost:$RPC_PORT | jq -r '.result.peers')" + # Clean up the node + kill -9 $POLKADOT_PID + # Sometimes due to machine load or other reasons, we don't get a response from the RPC node + # If $PEERS is an empty variable, mark the node as unreachable + if [ -z "$PEERS" ]; then + PEERS=0 + fi + if [ "$PEERS" -gt 0 ]; then + echo "[+] $PEERS peers found for $BOOTNODE" + echo " Bootnode appears contactable" + GOOD_BOOTNODES+=("$BOOTNODE") + return 0 + else + echo "[!] $PEERS peers found for $BOOTNODE" + echo " Bootnode appears unreachable" + BAD_BOOTNODES+=("$BOOTNODE") + return 1 + fi +} + +# For each runtime +CHAINSPEC_FILE="$ROOT/node/service/chain-specs/$RUNTIME.json" +# count the number of bootnodes +BOOTNODES=$( jq -r '.bootNodes | length' "$CHAINSPEC_FILE" ) +# Make a temporary dir for chainspec files +CHAINSPEC_TMPDIR="$(mktemp -d -t "${RUNTIME}_chainspecs")" +echo "[+] Using $CHAINSPEC_TMPDIR as temporary chainspec dir" +# Store an array of the bad bootnodes +BAD_BOOTNODES=() +GOOD_BOOTNODES=() +PIDS=() +echo "[+] Checking $BOOTNODES bootnodes for $RUNTIME" +for i in $(seq 0 $((BOOTNODES-1))); do + # Check each bootnode in parallel + check_bootnode "$i" & + PIDS+=($!) + # Hold off one second between attempting to spawn nodes + sleep 1 +done +RESPS=() +# Wait for all the nodes to finish +for pid in "${PIDS[@]}"; do + wait "$pid" + RESPS+=($?) +done +echo +# For any bootnodes that failed, add them to the bad bootnodes array +for i in "${!RESPS[@]}"; do + if [ "${RESPS[$i]}" -ne 0 ]; then + BAD_BOOTNODES+=("$( jq -r .bootNodes["$i"] < "$CHAINSPEC_FILE" )") + fi +done +# For any bootnodes that succeeded, add them to the good bootnodes array +for i in "${!RESPS[@]}"; do + if [ "${RESPS[$i]}" -eq 0 ]; then + GOOD_BOOTNODES+=("$( jq -r .bootNodes["$i"] < "$CHAINSPEC_FILE" )") + fi +done + +# If we've got any uncontactable bootnodes for this runtime, print them +if [ ${#BAD_BOOTNODES[@]} -gt 0 ]; then + echo "[!] Bad bootnodes found for $RUNTIME:" + for i in "${BAD_BOOTNODES[@]}"; do + echo " $i" + done + cleanup + exit 1 +else + echo "[+] All bootnodes for $RUNTIME are contactable" + cleanup + exit 0 +fi \ No newline at end of file From 5bb0a9ed10e580319c3f5874a947823773841b64 Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Tue, 14 Mar 2023 16:26:03 +0000 Subject: [PATCH 02/25] fix mktemp for linux machines --- scripts/ci/github/check_bootnodes.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ci/github/check_bootnodes.sh b/scripts/ci/github/check_bootnodes.sh index 361ad794af86..2f9bb8ae19ab 100755 --- a/scripts/ci/github/check_bootnodes.sh +++ b/scripts/ci/github/check_bootnodes.sh @@ -64,7 +64,7 @@ CHAINSPEC_FILE="$ROOT/node/service/chain-specs/$RUNTIME.json" # count the number of bootnodes BOOTNODES=$( jq -r '.bootNodes | length' "$CHAINSPEC_FILE" ) # Make a temporary dir for chainspec files -CHAINSPEC_TMPDIR="$(mktemp -d -t "${RUNTIME}_chainspecs")" +CHAINSPEC_TMPDIR="$(mktemp -d -t "${RUNTIME}_chainspecs_XXXXXX")" echo "[+] Using $CHAINSPEC_TMPDIR as temporary chainspec dir" # Store an array of the bad bootnodes BAD_BOOTNODES=() From 2350fb50b3ceab21e3d4f46ce5b75cf24dc7f337 Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Tue, 14 Mar 2023 17:11:43 +0000 Subject: [PATCH 03/25] Update check_bootnodes.sh show logs to see what's going wrong --- scripts/ci/github/check_bootnodes.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ci/github/check_bootnodes.sh b/scripts/ci/github/check_bootnodes.sh index 2f9bb8ae19ab..e712ee531609 100755 --- a/scripts/ci/github/check_bootnodes.sh +++ b/scripts/ci/github/check_bootnodes.sh @@ -32,7 +32,7 @@ check_bootnode(){ BASE_PORT=$(sysctl net.inet.ip.portrange.first | awk '{print $2}') RPC_PORT=$((BASE_PORT + BOOTNODE_INDEX)) echo "[+] Checking bootnode $BOOTNODE" - polkadot --chain "$FINAL_CHAINSPEC_FILE" --no-mdns --rpc-port=$RPC_PORT --tmp > /dev/null 2>&1 & + polkadot --chain "$FINAL_CHAINSPEC_FILE" --no-mdns --rpc-port=$RPC_PORT --tmp & POLKADOT_PID=$! # We just spun up a bunch of nodes... probably want to wait a bit. sleep 60 From 7470da0b67a52e7f5144686169ce32d309b27964 Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Wed, 15 Mar 2023 12:26:23 +0000 Subject: [PATCH 04/25] fix ephemeral ports and fetch polkadot --- .github/workflows/check-bootnodes.yml | 7 +++++++ scripts/ci/github/check_bootnodes.sh | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-bootnodes.yml b/.github/workflows/check-bootnodes.yml index f66ac6220385..8df873d8ea52 100644 --- a/.github/workflows/check-bootnodes.yml +++ b/.github/workflows/check-bootnodes.yml @@ -13,6 +13,13 @@ jobs: steps: - name: Checkout sources uses: actions/checkout@v3 + - name: Install polkadot + shell: bash + run: | + curl https://api.github.com/repos/paritytech/polkadot/releases/latest\ + | jq -r '.assets | .[] | select(.name == "polkadot").browser_download_url' | sudo tee /usr/local/bin/polkadot + chmod +x /usr/local/bin/polkadot + polkadot --version - name: Check ${{ matrix.runtime }} bootnodes shell: bash run: scripts/ci/github/check_bootnodes.sh ${{ matrix.runtime }} \ No newline at end of file diff --git a/scripts/ci/github/check_bootnodes.sh b/scripts/ci/github/check_bootnodes.sh index 2f9bb8ae19ab..10aa7af0dbce 100755 --- a/scripts/ci/github/check_bootnodes.sh +++ b/scripts/ci/github/check_bootnodes.sh @@ -29,7 +29,13 @@ check_bootnode(){ jq ".bootNodes |= [.[$BOOTNODE_INDEX]] " < "$TMP_CHAINSPEC_FILE" > "$FINAL_CHAINSPEC_FILE" BOOTNODE=$( jq -r '.bootNodes[0]' < "$FINAL_CHAINSPEC_FILE" ) # Get the first ephemeral port - BASE_PORT=$(sysctl net.inet.ip.portrange.first | awk '{print $2}') + if [[ "$OSTYPE" == "darwin"* ]]; then + BASE_PORT=$(sysctl net.inet.ip.portrange.first | awk '{print $2}') + else + BASE_PORT=$(sysctl net.ipv4.ip_local_port_range | awk '{print $3}') + fi + # If we're on a mac, use this instead + # BASE_PORT=$(sysctl net.inet.ip.portrange.first | awk '{print $2}') RPC_PORT=$((BASE_PORT + BOOTNODE_INDEX)) echo "[+] Checking bootnode $BOOTNODE" polkadot --chain "$FINAL_CHAINSPEC_FILE" --no-mdns --rpc-port=$RPC_PORT --tmp > /dev/null 2>&1 & From 134127cebe3decddf999a0cc7930a6e5c79ac37a Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Wed, 15 Mar 2023 12:30:13 +0000 Subject: [PATCH 05/25] fix check-bootnodes.yml --- .github/workflows/check-bootnodes.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/check-bootnodes.yml b/.github/workflows/check-bootnodes.yml index 8df873d8ea52..00c484d7e5b9 100644 --- a/.github/workflows/check-bootnodes.yml +++ b/.github/workflows/check-bootnodes.yml @@ -16,10 +16,11 @@ jobs: - name: Install polkadot shell: bash run: | - curl https://api.github.com/repos/paritytech/polkadot/releases/latest\ - | jq -r '.assets | .[] | select(.name == "polkadot").browser_download_url' | sudo tee /usr/local/bin/polkadot - chmod +x /usr/local/bin/polkadot - polkadot --version + curl -L "$(curl -s https://api.github.com/repos/paritytech/polkadot/releases/latest \ + | jq -r '.assets | .[] | select(.name == "polkadot").browser_download_url')"\ + | sudo tee /usr/local/bin/polkadot > /dev/null + sudo chmod +x /usr/local/bin/polkadot + polkadot --version - name: Check ${{ matrix.runtime }} bootnodes shell: bash run: scripts/ci/github/check_bootnodes.sh ${{ matrix.runtime }} \ No newline at end of file From 1af8d0b857ad00810a59b214f9c1bc45c98bc8b7 Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Wed, 15 Mar 2023 12:57:03 +0000 Subject: [PATCH 06/25] increase node spawn holdoff --- scripts/ci/github/check_bootnodes.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/ci/github/check_bootnodes.sh b/scripts/ci/github/check_bootnodes.sh index 4618d8418143..72562a78ca2d 100755 --- a/scripts/ci/github/check_bootnodes.sh +++ b/scripts/ci/github/check_bootnodes.sh @@ -81,8 +81,8 @@ for i in $(seq 0 $((BOOTNODES-1))); do # Check each bootnode in parallel check_bootnode "$i" & PIDS+=($!) - # Hold off one second between attempting to spawn nodes - sleep 1 + # Hold off 10 seconds between attempting to spawn nodes to stop the machine from getting overloaded + sleep 10 done RESPS=() # Wait for all the nodes to finish From c6682864b34200b3bcb7a7cc6e6ec8d2be11a832 Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Wed, 15 Mar 2023 13:04:46 +0000 Subject: [PATCH 07/25] disable fail-fast --- .github/workflows/check-bootnodes.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-bootnodes.yml b/.github/workflows/check-bootnodes.yml index 00c484d7e5b9..127af4b3a41c 100644 --- a/.github/workflows/check-bootnodes.yml +++ b/.github/workflows/check-bootnodes.yml @@ -7,6 +7,7 @@ on: push jobs: check_bootnodes: strategy: + fail-fast: false matrix: runtime: [westend, kusama, polkadot] runs-on: ubuntu-latest @@ -17,7 +18,7 @@ jobs: shell: bash run: | curl -L "$(curl -s https://api.github.com/repos/paritytech/polkadot/releases/latest \ - | jq -r '.assets | .[] | select(.name == "polkadot").browser_download_url')"\ + | jq -r '.assets | .[] | select(.name == "polkadot").browser_download_url')" \ | sudo tee /usr/local/bin/polkadot > /dev/null sudo chmod +x /usr/local/bin/polkadot polkadot --version From 1cebfd8e7abd8fe5f6719a1157d027056dfa1be0 Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Wed, 15 Mar 2023 14:41:27 +0000 Subject: [PATCH 08/25] refactor, separate out check_bootnodes and make it posix-compliant --- scripts/ci/common/lib.sh | 47 ++++++++++++++++++++++++ scripts/ci/github/check_bootnodes.sh | 54 +++------------------------- 2 files changed, 52 insertions(+), 49 deletions(-) diff --git a/scripts/ci/common/lib.sh b/scripts/ci/common/lib.sh index 93e0392b3e29..36b74e929d2b 100755 --- a/scripts/ci/common/lib.sh +++ b/scripts/ci/common/lib.sh @@ -139,3 +139,50 @@ has_runtime_changes() { return 1 fi } + +# given a bootnode and the path to a chainspec file, this function will create a new chainspec file +# with only the bootnode specified and test whether that bootnode provides peers +# The optional third argument is the index of the bootnode in the list of bootnodes, this is just used to pick an ephemeral +# port for the node to run on. If you're only testing one, it'll just use the first ephemeral port +# BOOTNODE: /dns/polkadot-connect-0.parity.io/tcp/443/wss/p2p/12D3KooWEPmjoRpDSUuiTjvyNDd8fejZ9eNWH5bE965nyBMDrB4o +# CHAINSPEC_FILE: /path/to/polkadot.json +check_bootnode(){ + BOOTNODE=$1 + BASE_CHAINSPEC=$2 + RUNTIME=$(basename "$BASE_CHAINSPEC" | cut -d '.' -f 1) + + # Generate a temporary chainspec file containing only the bootnode we care about + TMP_CHAINSPEC_FILE="$RUNTIME.$(echo "$BOOTNODE" | tr '/' '_').tmp.json" + jq ".bootNodes = [\"$BOOTNODE\"] " < "$CHAINSPEC_FILE" > "$TMP_CHAINSPEC_FILE" + + # Grab an unused port by binding to port 0 and then immediately closing the socket + # This is a bit of a hack, but it's the only way to do it in the shell + RPC_PORT=$(python -c "import socket; s=socket.socket(); s.bind(('', 0)); print(s.getsockname()[1]); s.close()") + + echo "[+] Checking bootnode $BOOTNODE" + polkadot --chain "$TMP_CHAINSPEC_FILE" --no-mdns --rpc-port="$RPC_PORT" --tmp > /dev/null 2>&1 & + POLKADOT_PID=$! + # Wait a little while for the node to start up and attempt to start peering + sleep 60 + # Delete the temporary chainspec file now we're done running the node + rm "$TMP_CHAINSPEC_FILE" + + # Check the health endpoint of the RPC node + PEERS="$(curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"system_health","params":[],"id":1}' http://localhost:"$RPC_PORT" | jq -r '.result.peers')" + # Clean up the node + kill -9 $POLKADOT_PID + # Sometimes due to machine load or other reasons, we don't get a response from the RPC node + # If $PEERS is an empty variable, mark the node as unreachable + if [ -z "$PEERS" ]; then + PEERS=0 + fi + if [ "$PEERS" -gt 0 ]; then + echo "[+] $PEERS peers found for $BOOTNODE" + echo " Bootnode appears contactable" + return 0 + else + echo "[!] $PEERS peers found for $BOOTNODE" + echo " Bootnode appears unreachable" + return 1 + fi +} \ No newline at end of file diff --git a/scripts/ci/github/check_bootnodes.sh b/scripts/ci/github/check_bootnodes.sh index 72562a78ca2d..b5768f788b82 100755 --- a/scripts/ci/github/check_bootnodes.sh +++ b/scripts/ci/github/check_bootnodes.sh @@ -9,6 +9,8 @@ # Root of the polkadot dir ROOT="$(dirname "${0}")/../../.." +# shellcheck source=scripts/ci/common/lib.sh +source "$ROOT/scripts/ci/common/lib.sh" RUNTIME="$1" trap cleanup EXIT INT TERM @@ -19,67 +21,21 @@ cleanup(){ killall polkadot > /dev/null 2>&1 } -check_bootnode(){ - BOOTNODE_INDEX=$1 - TMP_CHAINSPEC_FILE="$RUNTIME.$BOOTNODE_INDEX.tmp.json" - FINAL_CHAINSPEC_FILE="$RUNTIME.$BOOTNODE_INDEX.final.json" - # Copy the chainspec file to a temporary location to avoid weird race conditions when running in parallel - cp "$CHAINSPEC_FILE" "$CHAINSPEC_TMPDIR/$TMP_CHAINSPEC_FILE" - pushd "$CHAINSPEC_TMPDIR" > /dev/null || exit 1 - jq ".bootNodes |= [.[$BOOTNODE_INDEX]] " < "$TMP_CHAINSPEC_FILE" > "$FINAL_CHAINSPEC_FILE" - BOOTNODE=$( jq -r '.bootNodes[0]' < "$FINAL_CHAINSPEC_FILE" ) - # Get the first ephemeral port - if [[ "$OSTYPE" == "darwin"* ]]; then - BASE_PORT=$(sysctl net.inet.ip.portrange.first | awk '{print $2}') - else - BASE_PORT=$(sysctl net.ipv4.ip_local_port_range | awk '{print $3}') - fi - # If we're on a mac, use this instead - # BASE_PORT=$(sysctl net.inet.ip.portrange.first | awk '{print $2}') - RPC_PORT=$((BASE_PORT + BOOTNODE_INDEX)) - echo "[+] Checking bootnode $BOOTNODE" - polkadot --chain "$FINAL_CHAINSPEC_FILE" --no-mdns --rpc-port=$RPC_PORT --tmp > /dev/null 2>&1 & - POLKADOT_PID=$! - # We just spun up a bunch of nodes... probably want to wait a bit. - sleep 60 - popd > /dev/null || exit 1 - # Check the health endpoint of the RPC node - PEERS="$(curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"system_health","params":[],"id":1}' http://localhost:$RPC_PORT | jq -r '.result.peers')" - # Clean up the node - kill -9 $POLKADOT_PID - # Sometimes due to machine load or other reasons, we don't get a response from the RPC node - # If $PEERS is an empty variable, mark the node as unreachable - if [ -z "$PEERS" ]; then - PEERS=0 - fi - if [ "$PEERS" -gt 0 ]; then - echo "[+] $PEERS peers found for $BOOTNODE" - echo " Bootnode appears contactable" - GOOD_BOOTNODES+=("$BOOTNODE") - return 0 - else - echo "[!] $PEERS peers found for $BOOTNODE" - echo " Bootnode appears unreachable" - BAD_BOOTNODES+=("$BOOTNODE") - return 1 - fi -} - # For each runtime CHAINSPEC_FILE="$ROOT/node/service/chain-specs/$RUNTIME.json" # count the number of bootnodes BOOTNODES=$( jq -r '.bootNodes | length' "$CHAINSPEC_FILE" ) # Make a temporary dir for chainspec files -CHAINSPEC_TMPDIR="$(mktemp -d -t "${RUNTIME}_chainspecs_XXXXXX")" -echo "[+] Using $CHAINSPEC_TMPDIR as temporary chainspec dir" # Store an array of the bad bootnodes BAD_BOOTNODES=() GOOD_BOOTNODES=() PIDS=() + echo "[+] Checking $BOOTNODES bootnodes for $RUNTIME" for i in $(seq 0 $((BOOTNODES-1))); do + BOOTNODE=$( jq -r .bootNodes["$i"] < "$CHAINSPEC_FILE" ) # Check each bootnode in parallel - check_bootnode "$i" & + check_bootnode "$BOOTNODE" "$CHAINSPEC_FILE" & PIDS+=($!) # Hold off 10 seconds between attempting to spawn nodes to stop the machine from getting overloaded sleep 10 From 1170e847047953d8f5a34089e09135058f3775e3 Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Wed, 15 Mar 2023 16:31:37 +0000 Subject: [PATCH 09/25] add new job for detecting new bootnodes --- .github/workflows/check-new-bootnodes.yml | 25 ++++++++++++++ scripts/ci/github/check_bootnodes.sh | 16 ++++----- scripts/ci/github/check_new_bootnodes.sh | 41 +++++++++++++++++++++++ 3 files changed, 72 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/check-new-bootnodes.yml create mode 100755 scripts/ci/github/check_new_bootnodes.sh diff --git a/.github/workflows/check-new-bootnodes.yml b/.github/workflows/check-new-bootnodes.yml new file mode 100644 index 000000000000..4c6d4ccd923d --- /dev/null +++ b/.github/workflows/check-new-bootnodes.yml @@ -0,0 +1,25 @@ +# If a chainspec file is updated with new bootnodes, we check to make sure those bootnodes are contactable + +name: Check new bootnodes +on: + pull_request: + paths: + - 'node/service/chain-specs/*.json' + +jobs: + check_bootnodes: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v3 + - name: Install polkadot + shell: bash + run: | + curl -L "$(curl -s https://api.github.com/repos/paritytech/polkadot/releases/latest \ + | jq -r '.assets | .[] | select(.name == "polkadot").browser_download_url')" \ + | sudo tee /usr/local/bin/polkadot > /dev/null + sudo chmod +x /usr/local/bin/polkadot + polkadot --version + - name: Check new bootnodes + shell: bash + run: scripts/ci/github/check_new_bootnodes.sh \ No newline at end of file diff --git a/scripts/ci/github/check_bootnodes.sh b/scripts/ci/github/check_bootnodes.sh index b5768f788b82..e29728c37ad3 100755 --- a/scripts/ci/github/check_bootnodes.sh +++ b/scripts/ci/github/check_bootnodes.sh @@ -7,11 +7,10 @@ # been able to contact any other nodes, we can reason that the bootnode we used is not well-connected # or is otherwise uncontactable. -# Root of the polkadot dir -ROOT="$(dirname "${0}")/../../.." # shellcheck source=scripts/ci/common/lib.sh -source "$ROOT/scripts/ci/common/lib.sh" -RUNTIME="$1" +source "$(dirname "${0}")/../common/lib.sh" +CHAINSPEC_FILE="$1" +RUNTIME=$(basename "$CHAINSPEC_FILE" | cut -d '.' -f 1) trap cleanup EXIT INT TERM @@ -19,10 +18,9 @@ cleanup(){ echo "[+] Script interrupted or ended. Cleaning up..." # Kill all the polkadot processes killall polkadot > /dev/null 2>&1 + exit $1 } -# For each runtime -CHAINSPEC_FILE="$ROOT/node/service/chain-specs/$RUNTIME.json" # count the number of bootnodes BOOTNODES=$( jq -r '.bootNodes | length' "$CHAINSPEC_FILE" ) # Make a temporary dir for chainspec files @@ -66,10 +64,8 @@ if [ ${#BAD_BOOTNODES[@]} -gt 0 ]; then for i in "${BAD_BOOTNODES[@]}"; do echo " $i" done - cleanup - exit 1 + cleanup 1 else echo "[+] All bootnodes for $RUNTIME are contactable" - cleanup - exit 0 + cleanup 0 fi \ No newline at end of file diff --git a/scripts/ci/github/check_new_bootnodes.sh b/scripts/ci/github/check_new_bootnodes.sh new file mode 100755 index 000000000000..550ce2c7ef5c --- /dev/null +++ b/scripts/ci/github/check_new_bootnodes.sh @@ -0,0 +1,41 @@ +#!/bin/bash +ROOT="$(dirname "${0}")/../../.." +source "$ROOT/scripts/ci/common/lib.sh" + +# This script checks any new bootnodes added since the last git commit + +RUNTIMES=( kusama westend polkadot ) + +WAS_ERROR=0 + +for RUNTIME in "${RUNTIMES[@]}"; do + CHAINSPEC_FILE="$ROOT/node/service/chain-specs/$RUNTIME.json" + # Get the bootnodes from master's chainspec + git show origin/master:"$CHAINSPEC_FILE" | jq '{"oldNodes": .bootNodes}' > "$RUNTIME-old-bootnodes.json" + # Get the bootnodes from the current branch's chainspec + git show HEAD:"$CHAINSPEC_FILE" | jq '{"newNodes": .bootNodes}' > "$RUNTIME-new-bootnodes.json" + # Make a chainspec containing only the new bootnodes + jq ".bootNodes = $(jq -rs '.[0] * .[1] | .newNodes-.oldNodes' \ + "$RUNTIME-new-bootnodes.json" "$RUNTIME-old-bootnodes.json")" \ + < "$ROOT/node/service/chain-specs/$RUNTIME.json" \ + > "$RUNTIME-new-chainspec.json" + # exit early if the new chainspec has no bootnodes + if [ "$(jq -r '.bootNodes | length' "$RUNTIME-new-chainspec.json")" -eq 0 ]; then + echo "[+] No new bootnodes for $RUNTIME" + # Clean up the temporary files + rm "$RUNTIME-new-chainspec.json" "$RUNTIME-old-bootnodes.json" "$RUNTIME-new-bootnodes.json" + continue + fi + # Check the new bootnodes + if ! "$ROOT/scripts/ci/github/check_bootnodes.sh" "$RUNTIME-new-chainspec.json"; then + WAS_ERROR=1 + fi + # Clean up the temporary files + rm "$RUNTIME-new-chainspec.json" "$RUNTIME-old-bootnodes.json" "$RUNTIME-new-bootnodes.json" +done + + +if [ $WAS_ERROR -eq 1 ]; then + echo "[!] One of the new bootnodes failed to connect. Please check logs above." + exit 1 +fi From feec2e41c37744befcf9e5016441d13ce953df9b Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Wed, 15 Mar 2023 16:36:53 +0000 Subject: [PATCH 10/25] fix check-bootnodes.yml --- .github/workflows/check-bootnodes.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-bootnodes.yml b/.github/workflows/check-bootnodes.yml index 127af4b3a41c..538e90471791 100644 --- a/.github/workflows/check-bootnodes.yml +++ b/.github/workflows/check-bootnodes.yml @@ -24,4 +24,4 @@ jobs: polkadot --version - name: Check ${{ matrix.runtime }} bootnodes shell: bash - run: scripts/ci/github/check_bootnodes.sh ${{ matrix.runtime }} \ No newline at end of file + run: scripts/ci/github/check_bootnodes.sh node/service/chain-specs/${{ matrix.runtime }}.json From da4da9a4165ee3a0e0cb2f6301484c0562149787 Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Wed, 15 Mar 2023 16:48:05 +0000 Subject: [PATCH 11/25] only check all bootnodes on release --- .github/workflows/check-bootnodes.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-bootnodes.yml b/.github/workflows/check-bootnodes.yml index 538e90471791..22cbe5f7dd86 100644 --- a/.github/workflows/check-bootnodes.yml +++ b/.github/workflows/check-bootnodes.yml @@ -2,7 +2,11 @@ # the bootnodes in their respective chainspecs are contactable name: Check all bootnodes -on: push +on: + push: + branches: + # Catches v1.2.3 and v1.2.3-rc1 + - release-v[0-9]+.[0-9]+.[0-9]+* jobs: check_bootnodes: From 540dd9754a1f8e2d3fef33f7f5a033b8c2aa4dcb Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Wed, 15 Mar 2023 16:48:50 +0000 Subject: [PATCH 12/25] Add test bad bootnode REVERT ME before merging PR. Should cause the test to fail, then when we remove it, we should succeed. Sadly doesn't account for a new successful bootnode, should ask if we have one we can use for testing. --- node/service/chain-specs/westend.json | 1 + 1 file changed, 1 insertion(+) diff --git a/node/service/chain-specs/westend.json b/node/service/chain-specs/westend.json index 43c7333f8a26..8f950fe25acb 100644 --- a/node/service/chain-specs/westend.json +++ b/node/service/chain-specs/westend.json @@ -6,6 +6,7 @@ "/dns/0.westend.paritytech.net/tcp/30334/ws/p2p/12D3KooWKer94o1REDPtAhjtYR4SdLehnSrN8PEhBnZm5NBoCrMC", "/dns/1.westend.paritytech.net/tcp/30333/p2p/12D3KooWPVPzs42GvRBShdUMtFsk4SvnByrSdWqb6aeAAHvLMSLS", "/dns/1.westend.paritytech.net/tcp/30334/ws/p2p/12D3KooWPVPzs42GvRBShdUMtFsk4SvnByrSdWqb6aeAAHvLMSLS", + "/dns/100.westend.ligma-enterprises.net/tcp/30334/ws/p2p/12D3KooWPVPzs42GvRBShdUMtFsk4SvnByrSdWqb6aeAAHvLMSLS", "/dns/2.westend.paritytech.net/tcp/30333/p2p/12D3KooWByVpK92hMi9CzTjyFg9cPHDU5ariTM3EPMq9vdh5S5Po", "/dns/2.westend.paritytech.net/tcp/30334/ws/p2p/12D3KooWByVpK92hMi9CzTjyFg9cPHDU5ariTM3EPMq9vdh5S5Po", "/dns/3.westend.paritytech.net/tcp/30333/p2p/12D3KooWGi1tCpKXLMYED9y28QXLnwgD4neYb1Arqq4QpeV1Sv3K", From 5ee885ad4c58668b06bf2d9edb33aab4850175c1 Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Wed, 15 Mar 2023 16:58:59 +0000 Subject: [PATCH 13/25] fix paths --- scripts/ci/github/check_new_bootnodes.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/ci/github/check_new_bootnodes.sh b/scripts/ci/github/check_new_bootnodes.sh index 550ce2c7ef5c..207dc990cbec 100755 --- a/scripts/ci/github/check_new_bootnodes.sh +++ b/scripts/ci/github/check_new_bootnodes.sh @@ -1,6 +1,6 @@ #!/bin/bash -ROOT="$(dirname "${0}")/../../.." -source "$ROOT/scripts/ci/common/lib.sh" +# shellcheck source=scripts/ci/common/lib.sh +source "../common/lib.sh" # This script checks any new bootnodes added since the last git commit @@ -9,15 +9,15 @@ RUNTIMES=( kusama westend polkadot ) WAS_ERROR=0 for RUNTIME in "${RUNTIMES[@]}"; do - CHAINSPEC_FILE="$ROOT/node/service/chain-specs/$RUNTIME.json" + CHAINSPEC_FILE="node/service/chain-specs/$RUNTIME.json" # Get the bootnodes from master's chainspec - git show origin/master:"$CHAINSPEC_FILE" | jq '{"oldNodes": .bootNodes}' > "$RUNTIME-old-bootnodes.json" + git show master:"$CHAINSPEC_FILE" | jq '{"oldNodes": .bootNodes}' > "$RUNTIME-old-bootnodes.json" # Get the bootnodes from the current branch's chainspec git show HEAD:"$CHAINSPEC_FILE" | jq '{"newNodes": .bootNodes}' > "$RUNTIME-new-bootnodes.json" # Make a chainspec containing only the new bootnodes jq ".bootNodes = $(jq -rs '.[0] * .[1] | .newNodes-.oldNodes' \ "$RUNTIME-new-bootnodes.json" "$RUNTIME-old-bootnodes.json")" \ - < "$ROOT/node/service/chain-specs/$RUNTIME.json" \ + < "node/service/chain-specs/$RUNTIME.json" \ > "$RUNTIME-new-chainspec.json" # exit early if the new chainspec has no bootnodes if [ "$(jq -r '.bootNodes | length' "$RUNTIME-new-chainspec.json")" -eq 0 ]; then @@ -27,7 +27,7 @@ for RUNTIME in "${RUNTIMES[@]}"; do continue fi # Check the new bootnodes - if ! "$ROOT/scripts/ci/github/check_bootnodes.sh" "$RUNTIME-new-chainspec.json"; then + if ! "scripts/ci/github/check_bootnodes.sh" "$RUNTIME-new-chainspec.json"; then WAS_ERROR=1 fi # Clean up the temporary files From 5b465ab97a4ce62b8229ab16dd9fefc298cec82b Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Wed, 15 Mar 2023 17:07:09 +0000 Subject: [PATCH 14/25] fix paths and git... hopefully --- .github/workflows/check-new-bootnodes.yml | 4 +++- scripts/ci/github/check_new_bootnodes.sh | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-new-bootnodes.yml b/.github/workflows/check-new-bootnodes.yml index 4c6d4ccd923d..97665c0adb87 100644 --- a/.github/workflows/check-new-bootnodes.yml +++ b/.github/workflows/check-new-bootnodes.yml @@ -12,6 +12,8 @@ jobs: steps: - name: Checkout sources uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Install polkadot shell: bash run: | @@ -22,4 +24,4 @@ jobs: polkadot --version - name: Check new bootnodes shell: bash - run: scripts/ci/github/check_new_bootnodes.sh \ No newline at end of file + run: scripts/ci/github/check_new_bootnodes.sh diff --git a/scripts/ci/github/check_new_bootnodes.sh b/scripts/ci/github/check_new_bootnodes.sh index 207dc990cbec..d472698b99cc 100755 --- a/scripts/ci/github/check_new_bootnodes.sh +++ b/scripts/ci/github/check_new_bootnodes.sh @@ -1,6 +1,7 @@ #!/bin/bash +set -e # shellcheck source=scripts/ci/common/lib.sh -source "../common/lib.sh" +source "$(dirname "${0}")/../common/lib.sh" # This script checks any new bootnodes added since the last git commit From 9d1a4be0e50b6f0c4f1d2b0eaaa5c481c0e4d2ee Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Wed, 15 Mar 2023 17:10:37 +0000 Subject: [PATCH 15/25] this better work... --- .github/workflows/check-new-bootnodes.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-new-bootnodes.yml b/.github/workflows/check-new-bootnodes.yml index 97665c0adb87..f171d93738e1 100644 --- a/.github/workflows/check-new-bootnodes.yml +++ b/.github/workflows/check-new-bootnodes.yml @@ -24,4 +24,6 @@ jobs: polkadot --version - name: Check new bootnodes shell: bash - run: scripts/ci/github/check_new_bootnodes.sh + run: | + git fetch origin master + scripts/ci/github/check_new_bootnodes.sh From 1e106e7efb23ebb51df855f611996118a6474f1e Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Wed, 15 Mar 2023 17:17:22 +0000 Subject: [PATCH 16/25] fix --- scripts/ci/github/check_new_bootnodes.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ci/github/check_new_bootnodes.sh b/scripts/ci/github/check_new_bootnodes.sh index d472698b99cc..604db6a4e367 100755 --- a/scripts/ci/github/check_new_bootnodes.sh +++ b/scripts/ci/github/check_new_bootnodes.sh @@ -12,7 +12,7 @@ WAS_ERROR=0 for RUNTIME in "${RUNTIMES[@]}"; do CHAINSPEC_FILE="node/service/chain-specs/$RUNTIME.json" # Get the bootnodes from master's chainspec - git show master:"$CHAINSPEC_FILE" | jq '{"oldNodes": .bootNodes}' > "$RUNTIME-old-bootnodes.json" + git show origin/master:"$CHAINSPEC_FILE" | jq '{"oldNodes": .bootNodes}' > "$RUNTIME-old-bootnodes.json" # Get the bootnodes from the current branch's chainspec git show HEAD:"$CHAINSPEC_FILE" | jq '{"newNodes": .bootNodes}' > "$RUNTIME-new-bootnodes.json" # Make a chainspec containing only the new bootnodes From db279611a0db109fb6a7662375601ce61381f450 Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Wed, 15 Mar 2023 17:19:13 +0000 Subject: [PATCH 17/25] test --- .github/workflows/check-new-bootnodes.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/check-new-bootnodes.yml b/.github/workflows/check-new-bootnodes.yml index f171d93738e1..25b2a0a56fe5 100644 --- a/.github/workflows/check-new-bootnodes.yml +++ b/.github/workflows/check-new-bootnodes.yml @@ -25,5 +25,4 @@ jobs: - name: Check new bootnodes shell: bash run: | - git fetch origin master scripts/ci/github/check_new_bootnodes.sh From fc9a45eaa9e03b2e7c60f858d467dac3f806eed3 Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Wed, 15 Mar 2023 17:21:10 +0000 Subject: [PATCH 18/25] last test --- .github/workflows/check-new-bootnodes.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/check-new-bootnodes.yml b/.github/workflows/check-new-bootnodes.yml index 25b2a0a56fe5..dc58fb5253b1 100644 --- a/.github/workflows/check-new-bootnodes.yml +++ b/.github/workflows/check-new-bootnodes.yml @@ -12,8 +12,6 @@ jobs: steps: - name: Checkout sources uses: actions/checkout@v3 - with: - fetch-depth: 0 - name: Install polkadot shell: bash run: | From db701fb9f4840e247cf35b65d00fca648366091e Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Wed, 15 Mar 2023 17:22:31 +0000 Subject: [PATCH 19/25] Revert "Add test bad bootnode" This reverts commit 540dd9754a1f8e2d3fef33f7f5a033b8c2aa4dcb. --- .github/workflows/check-new-bootnodes.yml | 2 ++ node/service/chain-specs/westend.json | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-new-bootnodes.yml b/.github/workflows/check-new-bootnodes.yml index dc58fb5253b1..25b2a0a56fe5 100644 --- a/.github/workflows/check-new-bootnodes.yml +++ b/.github/workflows/check-new-bootnodes.yml @@ -12,6 +12,8 @@ jobs: steps: - name: Checkout sources uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Install polkadot shell: bash run: | diff --git a/node/service/chain-specs/westend.json b/node/service/chain-specs/westend.json index 8f950fe25acb..43c7333f8a26 100644 --- a/node/service/chain-specs/westend.json +++ b/node/service/chain-specs/westend.json @@ -6,7 +6,6 @@ "/dns/0.westend.paritytech.net/tcp/30334/ws/p2p/12D3KooWKer94o1REDPtAhjtYR4SdLehnSrN8PEhBnZm5NBoCrMC", "/dns/1.westend.paritytech.net/tcp/30333/p2p/12D3KooWPVPzs42GvRBShdUMtFsk4SvnByrSdWqb6aeAAHvLMSLS", "/dns/1.westend.paritytech.net/tcp/30334/ws/p2p/12D3KooWPVPzs42GvRBShdUMtFsk4SvnByrSdWqb6aeAAHvLMSLS", - "/dns/100.westend.ligma-enterprises.net/tcp/30334/ws/p2p/12D3KooWPVPzs42GvRBShdUMtFsk4SvnByrSdWqb6aeAAHvLMSLS", "/dns/2.westend.paritytech.net/tcp/30333/p2p/12D3KooWByVpK92hMi9CzTjyFg9cPHDU5ariTM3EPMq9vdh5S5Po", "/dns/2.westend.paritytech.net/tcp/30334/ws/p2p/12D3KooWByVpK92hMi9CzTjyFg9cPHDU5ariTM3EPMq9vdh5S5Po", "/dns/3.westend.paritytech.net/tcp/30333/p2p/12D3KooWGi1tCpKXLMYED9y28QXLnwgD4neYb1Arqq4QpeV1Sv3K", From 1733e63df992ba75328c2662532d7cabdce7c82f Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Thu, 16 Mar 2023 12:58:19 +0000 Subject: [PATCH 20/25] Update check_bootnodes.sh --- scripts/ci/github/check_bootnodes.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/ci/github/check_bootnodes.sh b/scripts/ci/github/check_bootnodes.sh index e29728c37ad3..e9d59fe7fcdc 100755 --- a/scripts/ci/github/check_bootnodes.sh +++ b/scripts/ci/github/check_bootnodes.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# In this script, we check each bootnode for each runtime and ensure they are contactable. +# In this script, we check each bootnode for a given chainspec file and ensure they are contactable. # We do this by removing every bootnode from the chainspec with the exception of the one # we want to check. Then we spin up a node using this new chainspec, wait a little while # and then check our local node's RPC endpoint for the number of peers. If the node hasn't @@ -68,4 +68,4 @@ if [ ${#BAD_BOOTNODES[@]} -gt 0 ]; then else echo "[+] All bootnodes for $RUNTIME are contactable" cleanup 0 -fi \ No newline at end of file +fi From 9f76d0e0f4a4eeca8da1be0bea7aea5a2a14d4d8 Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Thu, 16 Mar 2023 15:10:48 +0000 Subject: [PATCH 21/25] optimisations Begin polling the RPC node right after spawning, allowing us to break early on detecting peers --- .github/workflows/check-bootnodes.yml | 2 ++ scripts/ci/common/lib.sh | 41 +++++++++++++++------------ scripts/ci/github/check_bootnodes.sh | 4 +-- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/.github/workflows/check-bootnodes.yml b/.github/workflows/check-bootnodes.yml index 22cbe5f7dd86..fe83064d3242 100644 --- a/.github/workflows/check-bootnodes.yml +++ b/.github/workflows/check-bootnodes.yml @@ -7,6 +7,8 @@ on: branches: # Catches v1.2.3 and v1.2.3-rc1 - release-v[0-9]+.[0-9]+.[0-9]+* + # TODO: Remove before merging + - mp-bootnode-checker jobs: check_bootnodes: diff --git a/scripts/ci/common/lib.sh b/scripts/ci/common/lib.sh index 36b74e929d2b..07a9e50c4195 100755 --- a/scripts/ci/common/lib.sh +++ b/scripts/ci/common/lib.sh @@ -150,6 +150,7 @@ check_bootnode(){ BOOTNODE=$1 BASE_CHAINSPEC=$2 RUNTIME=$(basename "$BASE_CHAINSPEC" | cut -d '.' -f 1) + MIN_PEERS=1 # Generate a temporary chainspec file containing only the bootnode we care about TMP_CHAINSPEC_FILE="$RUNTIME.$(echo "$BOOTNODE" | tr '/' '_').tmp.json" @@ -160,29 +161,33 @@ check_bootnode(){ RPC_PORT=$(python -c "import socket; s=socket.socket(); s.bind(('', 0)); print(s.getsockname()[1]); s.close()") echo "[+] Checking bootnode $BOOTNODE" - polkadot --chain "$TMP_CHAINSPEC_FILE" --no-mdns --rpc-port="$RPC_PORT" --tmp > /dev/null 2>&1 & + polkadot --chain "$TMP_CHAINSPEC_FILE" --no-mdns --rpc-port="$RPC_PORT" --tmp > /dev/null 2>&1 & + # Wait a few seconds for the node to start up + sleep 5 POLKADOT_PID=$! - # Wait a little while for the node to start up and attempt to start peering - sleep 60 - # Delete the temporary chainspec file now we're done running the node + # Delete the temporary chainspec file now we're done spawning the node rm "$TMP_CHAINSPEC_FILE" + MAX_POLLS=10 + TIME_BETWEEN_POLLS=3 + for _ in $(seq 1 "$MAX_POLLS"); do # Check the health endpoint of the RPC node - PEERS="$(curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"system_health","params":[],"id":1}' http://localhost:"$RPC_PORT" | jq -r '.result.peers')" - # Clean up the node - kill -9 $POLKADOT_PID - # Sometimes due to machine load or other reasons, we don't get a response from the RPC node - # If $PEERS is an empty variable, mark the node as unreachable - if [ -z "$PEERS" ]; then + PEERS="$(curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"system_health","params":[],"id":1}' http://localhost:"$RPC_PORT" | jq -r '.result.peers')" + # Sometimes due to machine load or other reasons, we don't get a response from the RPC node + # If $PEERS is an empty variable, make it 0 so we can still do the comparison + if [ -z "$PEERS" ]; then PEERS=0 - fi - if [ "$PEERS" -gt 0 ]; then + fi + if [ "$PEERS" -ge $MIN_PEERS ]; then echo "[+] $PEERS peers found for $BOOTNODE" echo " Bootnode appears contactable" + kill $POLKADOT_PID return 0 - else - echo "[!] $PEERS peers found for $BOOTNODE" - echo " Bootnode appears unreachable" - return 1 - fi -} \ No newline at end of file + fi + sleep "$TIME_BETWEEN_POLLS" + done + kill $POLKADOT_PID + echo "[!] No peers found for $BOOTNODE" + echo " Bootnode appears unreachable" + return 1 +} diff --git a/scripts/ci/github/check_bootnodes.sh b/scripts/ci/github/check_bootnodes.sh index e29728c37ad3..5490b29288d0 100755 --- a/scripts/ci/github/check_bootnodes.sh +++ b/scripts/ci/github/check_bootnodes.sh @@ -35,8 +35,8 @@ for i in $(seq 0 $((BOOTNODES-1))); do # Check each bootnode in parallel check_bootnode "$BOOTNODE" "$CHAINSPEC_FILE" & PIDS+=($!) - # Hold off 10 seconds between attempting to spawn nodes to stop the machine from getting overloaded - sleep 10 + # Hold off 1 second between attempting to spawn nodes to stop the machine from getting overloaded + sleep 1 done RESPS=() # Wait for all the nodes to finish From 3f9d31b015628f28189aef0461fe357cb9874fd8 Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Thu, 16 Mar 2023 15:17:08 +0000 Subject: [PATCH 22/25] increase holdoff to 5 seconds --- scripts/ci/github/check_bootnodes.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/ci/github/check_bootnodes.sh b/scripts/ci/github/check_bootnodes.sh index 110c977717e7..f98a58cda2c8 100755 --- a/scripts/ci/github/check_bootnodes.sh +++ b/scripts/ci/github/check_bootnodes.sh @@ -35,8 +35,8 @@ for i in $(seq 0 $((BOOTNODES-1))); do # Check each bootnode in parallel check_bootnode "$BOOTNODE" "$CHAINSPEC_FILE" & PIDS+=($!) - # Hold off 1 second between attempting to spawn nodes to stop the machine from getting overloaded - sleep 1 + # Hold off 5 seconds between attempting to spawn nodes to stop the machine from getting overloaded + sleep 5 done RESPS=() # Wait for all the nodes to finish From ea5f71c0fa4923f7c3f16f7a4dd921f4be76652b Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Thu, 16 Mar 2023 15:19:26 +0000 Subject: [PATCH 23/25] dont delete chainspec til we kill the node --- scripts/ci/common/lib.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/ci/common/lib.sh b/scripts/ci/common/lib.sh index 07a9e50c4195..ba5b17148728 100755 --- a/scripts/ci/common/lib.sh +++ b/scripts/ci/common/lib.sh @@ -165,8 +165,6 @@ check_bootnode(){ # Wait a few seconds for the node to start up sleep 5 POLKADOT_PID=$! - # Delete the temporary chainspec file now we're done spawning the node - rm "$TMP_CHAINSPEC_FILE" MAX_POLLS=10 TIME_BETWEEN_POLLS=3 @@ -182,11 +180,15 @@ check_bootnode(){ echo "[+] $PEERS peers found for $BOOTNODE" echo " Bootnode appears contactable" kill $POLKADOT_PID + # Delete the temporary chainspec file now we're done running the node + rm "$TMP_CHAINSPEC_FILE" return 0 fi sleep "$TIME_BETWEEN_POLLS" done kill $POLKADOT_PID + # Delete the temporary chainspec file now we're done running the node + rm "$TMP_CHAINSPEC_FILE" echo "[!] No peers found for $BOOTNODE" echo " Bootnode appears unreachable" return 1 From 45a94cc3c4f574907016ec965ddfe68e6b6eb479 Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Mon, 20 Mar 2023 10:55:53 +0000 Subject: [PATCH 24/25] Update check-bootnodes.yml --- .github/workflows/check-bootnodes.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-bootnodes.yml b/.github/workflows/check-bootnodes.yml index fe83064d3242..4d473e0a5253 100644 --- a/.github/workflows/check-bootnodes.yml +++ b/.github/workflows/check-bootnodes.yml @@ -1,4 +1,4 @@ -# checks all runtimes we care about (kusama, polkadot, westend) and ensures +# checks all networks we care about (kusama, polkadot, westend) and ensures # the bootnodes in their respective chainspecs are contactable name: Check all bootnodes From cce201e3382ab4bd3434f5dbe7c844d909f42305 Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Mon, 20 Mar 2023 11:03:39 +0000 Subject: [PATCH 25/25] Remove checking bootnodes on pushing of this branch --- .github/workflows/check-bootnodes.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/check-bootnodes.yml b/.github/workflows/check-bootnodes.yml index 4d473e0a5253..897a90d3ae92 100644 --- a/.github/workflows/check-bootnodes.yml +++ b/.github/workflows/check-bootnodes.yml @@ -7,8 +7,6 @@ on: branches: # Catches v1.2.3 and v1.2.3-rc1 - release-v[0-9]+.[0-9]+.[0-9]+* - # TODO: Remove before merging - - mp-bootnode-checker jobs: check_bootnodes: