From 2c826504e6be19ac52008b6ba04cac92cfa60df8 Mon Sep 17 00:00:00 2001 From: kaladinlight <35275952+kaladinlight@users.noreply.github.com> Date: Wed, 2 Aug 2023 16:07:30 -0600 Subject: [PATCH 1/7] chore: optimism daemon probes --- node/coinstacks/optimism/daemon/init.sh | 2 +- node/coinstacks/optimism/daemon/liveness.sh | 23 ++++++++ node/coinstacks/optimism/daemon/readiness.sh | 56 ++++++++++++++++++++ node/coinstacks/optimism/daemon/startup.sh | 13 +++++ node/coinstacks/optimism/pulumi/index.ts | 3 ++ 5 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 node/coinstacks/optimism/daemon/liveness.sh create mode 100755 node/coinstacks/optimism/daemon/readiness.sh create mode 100644 node/coinstacks/optimism/daemon/startup.sh diff --git a/node/coinstacks/optimism/daemon/init.sh b/node/coinstacks/optimism/daemon/init.sh index 4a0e46416..ea4e0c2c3 100755 --- a/node/coinstacks/optimism/daemon/init.sh +++ b/node/coinstacks/optimism/daemon/init.sh @@ -2,7 +2,7 @@ set -e -apk add curl jq +apk add bash curl jq DATA_DIR=/data CHAINDATA_DIR=$DATA_DIR/geth/chaindata diff --git a/node/coinstacks/optimism/daemon/liveness.sh b/node/coinstacks/optimism/daemon/liveness.sh new file mode 100644 index 000000000..95ee68861 --- /dev/null +++ b/node/coinstacks/optimism/daemon/liveness.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +FILE=/data/block_number + +ETH_BLOCK_NUMBER=$(curl -sf -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' http://localhost:8545 -H 'Content-Type: application/json') || exit 1 + +CURRENT_BLOCK_NUMBER_HEX=$(echo $ETH_BLOCK_NUMBER | jq -r '.result') +CURRENT_BLOCK_NUMBER=$(($CURRENT_BLOCK_NUMBER_HEX)) + +if [[ ! -f "$FILE" ]]; then + echo $CURRENT_BLOCK_NUMBER > $FILE + exit 1 +fi + +PREVIOUS_BLOCK_NUMBER=$(cat $FILE) +echo $CURRENT_BLOCK_NUMBER > $FILE + +if (( $CURRENT_BLOCK_NUMBER > $PREVIOUS_BLOCK_NUMBER )); then + exit 0 +fi + +echo "daemon is stalled..." +exit 1 \ No newline at end of file diff --git a/node/coinstacks/optimism/daemon/readiness.sh b/node/coinstacks/optimism/daemon/readiness.sh new file mode 100755 index 000000000..e60fe863c --- /dev/null +++ b/node/coinstacks/optimism/daemon/readiness.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +BLOCK_HEIGHT_TOLERANCE=25 + +ETH_SYNCING=$(curl -sf -d '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}' http://localhost:8545 -H 'Content-Type: application/json') || exit 1 + +SYNCING=$(echo $ETH_SYNCING | jq -r '.result') + +get_best_block_number() { + local best_block_number=0 + + for reference_url in "$@"; do + local eth_blockNumber=$(curl -sf -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' -H 'Content-Type: application/json' $reference_url) + + if [[ $eth_blockNumber != "" ]]; then + local current_block_number_hex=$(echo $eth_blockNumber | jq -r '.result') + local current_block_number=$(($current_block_number_hex)) + + if (( $current_block_number > $best_block_number )); then + best_block_number=$current_block_number + fi + fi + done + + echo $best_block_number +} + +reference_validation() { + local best_block_number=$(get_best_block_number https://mainnet.optimism.io https://optimism.publicnode.com https://opt-mainnet.g.alchemy.com/v2/demo) + local eth_blockNumber=$(curl -sf -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' -H 'Content-Type: application/json' http://localhost:8545) || exit 1 + local current_block_number_hex=$(echo $eth_blockNumber | jq -r '.result') + local current_block_number=$(($current_block_number_hex)) + + if (( $best_block_number > 0 )); then + local nominal_block_number=$(( $best_block_number - $BLOCK_HEIGHT_TOLERANCE )) + + if (( $current_block_number >= $nominal_block_number )); then + echo "daemon is synced, and within block height tolerance of reference node" + exit 0 + fi + + echo "daemon is synced, but not within block height tolerance of reference node" + exit 1 + fi +} + +if [[ $SYNCING == false ]]; then + # if node is reporting synced, double check against reference nodes + reference_validation + + echo "daemon is synced" + exit 0 +fi + +echo "daemon is still syncing" +exit 1 diff --git a/node/coinstacks/optimism/daemon/startup.sh b/node/coinstacks/optimism/daemon/startup.sh new file mode 100644 index 000000000..28e2ac789 --- /dev/null +++ b/node/coinstacks/optimism/daemon/startup.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +NET_LISTENING=$(curl -sf -d '{"jsonrpc":"2.0","method":"net_listening","params":[],"id":1}' http://localhost:8545 -H 'Content-Type: application/json') || exit 1 + +LISTENING=$(echo $NET_LISTENING | jq -r '.result') + +if [[ $LISTENING == true ]]; then + echo "daemon is listening" + exit 0 +fi + +echo "daemon is not listening" +exit 1 diff --git a/node/coinstacks/optimism/pulumi/index.ts b/node/coinstacks/optimism/pulumi/index.ts index 72490402e..816f43e3c 100644 --- a/node/coinstacks/optimism/pulumi/index.ts +++ b/node/coinstacks/optimism/pulumi/index.ts @@ -23,6 +23,9 @@ export = async (): Promise => { }, configMapData: { 'jwt.hex': readFileSync('../daemon/jwt.hex').toString() }, volumeMounts: [{ name: 'config-map', mountPath: '/jwt.hex', subPath: 'jwt.hex' }], + startupProbe: { periodSeconds: 30, failureThreshold: 60, timeoutSeconds: 10 }, + livenessProbe: { periodSeconds: 30, timeoutSeconds: 10 }, + readinessProbe: { periodSeconds: 30, failureThreshold: 10, timeoutSeconds: 10 }, } case 'op-node': From eaa5a50b8fd9a4cb3e95a6b7214e3b4743c3afca Mon Sep 17 00:00:00 2001 From: kaladinlight <35275952+kaladinlight@users.noreply.github.com> Date: Wed, 2 Aug 2023 16:08:16 -0600 Subject: [PATCH 2/7] make file location more standard --- go/coinstacks/osmosis/daemon/liveness.sh | 2 +- node/coinstacks/bnbsmartchain/daemon/liveness.sh | 2 +- node/coinstacks/polygon/daemon/liveness.sh | 2 +- node/coinstacks/polygon/heimdall/liveness.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go/coinstacks/osmosis/daemon/liveness.sh b/go/coinstacks/osmosis/daemon/liveness.sh index 091a0f8c9..75bf9945d 100755 --- a/go/coinstacks/osmosis/daemon/liveness.sh +++ b/go/coinstacks/osmosis/daemon/liveness.sh @@ -1,6 +1,6 @@ #!/bin/bash -FILE=/root/.osmosisd/.latest_block_height +FILE=/root/.latest_block_height STATUS=$(curl -sf http://localhost:26657/status) || exit 1 diff --git a/node/coinstacks/bnbsmartchain/daemon/liveness.sh b/node/coinstacks/bnbsmartchain/daemon/liveness.sh index 90005f4f3..3dc5d15b7 100644 --- a/node/coinstacks/bnbsmartchain/daemon/liveness.sh +++ b/node/coinstacks/bnbsmartchain/daemon/liveness.sh @@ -1,6 +1,6 @@ #!/bin/bash -FILE=/data/geth/.block_number +FILE=/data/.block_number ETH_BLOCK_NUMBER=$(curl -sf -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' http://localhost:8545 -H 'Content-Type: application/json') || exit 1 diff --git a/node/coinstacks/polygon/daemon/liveness.sh b/node/coinstacks/polygon/daemon/liveness.sh index eb5c9ca42..3dc5d15b7 100644 --- a/node/coinstacks/polygon/daemon/liveness.sh +++ b/node/coinstacks/polygon/daemon/liveness.sh @@ -1,6 +1,6 @@ #!/bin/bash -FILE=/data/bor/.block_number +FILE=/data/.block_number ETH_BLOCK_NUMBER=$(curl -sf -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' http://localhost:8545 -H 'Content-Type: application/json') || exit 1 diff --git a/node/coinstacks/polygon/heimdall/liveness.sh b/node/coinstacks/polygon/heimdall/liveness.sh index 37e5bc530..209c9192b 100755 --- a/node/coinstacks/polygon/heimdall/liveness.sh +++ b/node/coinstacks/polygon/heimdall/liveness.sh @@ -1,6 +1,6 @@ #!/bin/bash -FILE=/root/.heimdalld/.latest_block_height +FILE=/root/.latest_block_height STATUS=$(curl -sf http://localhost:26657/status) || exit 1 From 5245a43fad7f3dd815695ff3ba3c70f04b2426e8 Mon Sep 17 00:00:00 2001 From: kaladinlight <35275952+kaladinlight@users.noreply.github.com> Date: Thu, 3 Aug 2023 12:17:18 -0600 Subject: [PATCH 3/7] add scripts --- node/Dockerfile.probe | 2 +- node/scripts/evm.sh | 39 +++++++++++++++++++++++++++++++++++++ node/{ => scripts}/probe.sh | 0 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 node/scripts/evm.sh rename node/{ => scripts}/probe.sh (100%) diff --git a/node/Dockerfile.probe b/node/Dockerfile.probe index 7953f98f5..946301443 100644 --- a/node/Dockerfile.probe +++ b/node/Dockerfile.probe @@ -2,6 +2,6 @@ FROM node:18.12.1-alpine RUN apk add --no-cache curl jq bash -COPY ./probe.sh /probe.sh +COPY ./scripts/probe.sh /probe.sh CMD /probe.sh \ No newline at end of file diff --git a/node/scripts/evm.sh b/node/scripts/evm.sh new file mode 100644 index 000000000..b4d79f164 --- /dev/null +++ b/node/scripts/evm.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +get_best_reference_block_number() { + local best_reference_block_number=0 + + for reference_url in "$@"; do + local eth_blockNumber=$(curl -sf -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' -H 'Content-Type: application/json' $reference_url) + + if [[ $eth_blockNumber != "" ]]; then + local current_block_number_hex=$(echo $eth_blockNumber | jq -r '.result') + local current_block_number=$(($current_block_number_hex)) + + if (( $current_block_number > $best_reference_block_number )); then + best_reference_block_number=$current_block_number + fi + fi + done + + echo $best_reference_block_number +} + +reference_validation() { + local service=$1 + local current_block_number=$2 + local best_reference_block_number=$3 + local block_height_tolerance=$4 + + if (( $best_reference_block_number > 0 )); then + local nominal_block_number=$(( $best_reference_block_number - $block_height_tolerance )) + + if (( $current_block_number >= $nominal_block_number )); then + echo "$service is synced within block height tolerance of reference node" + exit 0 + fi + + echo "$service is synced, but not within block height tolerance of reference node" + exit 1 + fi +} \ No newline at end of file diff --git a/node/probe.sh b/node/scripts/probe.sh similarity index 100% rename from node/probe.sh rename to node/scripts/probe.sh From e1d9e37ef8cb67783b02209b09984f4b34e7b6c6 Mon Sep 17 00:00:00 2001 From: kaladinlight <35275952+kaladinlight@users.noreply.github.com> Date: Thu, 3 Aug 2023 12:17:50 -0600 Subject: [PATCH 4/7] use common evm scripts --- .../bnbsmartchain/daemon/readiness.sh | 50 ++++--------------- node/coinstacks/bnbsmartchain/pulumi/index.ts | 2 + node/coinstacks/polygon/daemon/readiness.sh | 48 ++++-------------- node/coinstacks/polygon/pulumi/index.ts | 2 + 4 files changed, 23 insertions(+), 79 deletions(-) diff --git a/node/coinstacks/bnbsmartchain/daemon/readiness.sh b/node/coinstacks/bnbsmartchain/daemon/readiness.sh index 333452869..8e3db485d 100755 --- a/node/coinstacks/bnbsmartchain/daemon/readiness.sh +++ b/node/coinstacks/bnbsmartchain/daemon/readiness.sh @@ -1,5 +1,7 @@ #!/bin/bash +source /evm.sh + BLOCK_HEIGHT_TOLERANCE=15 ETH_SYNCING=$(curl -sf -d '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}' http://localhost:8545 -H 'Content-Type: application/json') || exit 1 @@ -9,49 +11,17 @@ SYNCING=$(echo $ETH_SYNCING | jq -r '.result') PEER_COUNT_HEX=$(echo $NET_PEER_COUNT | jq -r '.result') PEER_COUNT=$(($PEER_COUNT_HEX)) -get_best_block_number() { - local best_block_number=0 - - for reference_url in "$@"; do - local eth_blockNumber=$(curl -sf -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' -H 'Content-Type: application/json' $reference_url) - - if [[ $eth_blockNumber != "" ]]; then - local current_block_number_hex=$(echo $eth_blockNumber | jq -r '.result') - local current_block_number=$(($current_block_number_hex)) - - if (( $current_block_number > $best_block_number )); then - best_block_number=$current_block_number - fi - fi - done - - echo $best_block_number -} - -reference_validation() { - # budget load balance across available public node replicas: https://docs.bscscan.com/misc-tools-and-utilities/public-rpc-nodes - local best_block_number=$(get_best_block_number https://bsc-dataseed$(((RANDOM%4)+1)).binance.org https://bsc-dataseed$(((RANDOM%4)+1)).defibit.io https://bsc-dataseed$(((RANDOM%4)+1)).ninicoin.io) - local eth_blockNumber=$(curl -sf -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' -H 'Content-Type: application/json' http://localhost:8545) || exit 1 - local current_block_number_hex=$(echo $eth_blockNumber | jq -r '.result') - local current_block_number=$(($current_block_number_hex)) - - if (( $best_block_number > 0 )); then - local nominal_block_number=$(( $best_block_number - $BLOCK_HEIGHT_TOLERANCE )) - - if (( $current_block_number >= $nominal_block_number )); then - echo "daemon is synced with $PEER_COUNT peers, and within block height tolerance of reference node" - exit 0 - fi - - echo "daemon is synced with $PEER_COUNT peers, but not within block height tolerance of reference node" - exit 1 - fi -} - if [[ $SYNCING == false ]]; then if (( $PEER_COUNT > 0 )); then + eth_blockNumber=$(curl -sf -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' -H 'Content-Type: application/json' http://localhost:8545) || exit 1 + current_block_number_hex=$(echo $eth_blockNumber | jq -r '.result') + current_block_number=$(($current_block_number_hex)) + + # budget load balance across available public node replicas: https://docs.bscscan.com/misc-tools-and-utilities/public-rpc-nodes + best_reference_block_number=$(get_best_reference_block_number https://bsc-dataseed$(((RANDOM%4)+1)).binance.org https://bsc-dataseed$(((RANDOM%4)+1)).defibit.io https://bsc-dataseed$(((RANDOM%4)+1)).ninicoin.io) + # if node is reporting synced, double check against reference nodes - reference_validation + reference_validation daemon $current_block_number $best_reference_block_number $BLOCK_HEIGHT_TOLERANCE echo "daemon is synced, with $PEER_COUNT peers" exit 0 diff --git a/node/coinstacks/bnbsmartchain/pulumi/index.ts b/node/coinstacks/bnbsmartchain/pulumi/index.ts index 1eb52fd88..02cd27c14 100644 --- a/node/coinstacks/bnbsmartchain/pulumi/index.ts +++ b/node/coinstacks/bnbsmartchain/pulumi/index.ts @@ -22,6 +22,8 @@ export = async (): Promise => { env: { SNAPSHOT: 'https://pub-c0627345c16f47ab858c9469133073a8.r2.dev/geth-20230719.tar.lz4', }, + configMapData: { 'evm.sh': readFileSync('../../../scripts/evm.sh').toString() }, + volumeMounts: [{ name: 'config-map', mountPath: '/evm.sh', subPath: 'evm.sh' }], startupProbe: { periodSeconds: 30, failureThreshold: 60, timeoutSeconds: 10 }, livenessProbe: { periodSeconds: 30, timeoutSeconds: 10 }, readinessProbe: { periodSeconds: 30, failureThreshold: 10 }, diff --git a/node/coinstacks/polygon/daemon/readiness.sh b/node/coinstacks/polygon/daemon/readiness.sh index c7969e3cf..1b72a9ef7 100755 --- a/node/coinstacks/polygon/daemon/readiness.sh +++ b/node/coinstacks/polygon/daemon/readiness.sh @@ -1,5 +1,7 @@ #!/bin/bash +source /evm.sh + BLOCK_HEIGHT_TOLERANCE=15 ETH_SYNCING=$(curl -sf -d '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}' http://localhost:8545 -H 'Content-Type: application/json') || exit 1 @@ -9,48 +11,16 @@ SYNCING=$(echo $ETH_SYNCING | jq -r '.result') PEER_COUNT_HEX=$(echo $NET_PEER_COUNT | jq -r '.result') PEER_COUNT=$(($PEER_COUNT_HEX)) -get_best_block_number() { - local best_block_number=0 - - for reference_url in "$@"; do - local eth_blockNumber=$(curl -sf -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' -H 'Content-Type: application/json' $reference_url) - - if [[ $eth_blockNumber != "" ]]; then - local current_block_number_hex=$(echo $eth_blockNumber | jq -r '.result') - local current_block_number=$(($current_block_number_hex)) - - if (( $current_block_number > $best_block_number )); then - best_block_number=$current_block_number - fi - fi - done - - echo $best_block_number -} - -reference_validation() { - local best_block_number=$(get_best_block_number https://polygon-rpc.com https://polygon-bor.publicnode.com https://polygon-mainnet.g.alchemy.com/v2/demo) - local eth_blockNumber=$(curl -sf -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' -H 'Content-Type: application/json' http://localhost:8545) || exit 1 - local current_block_number_hex=$(echo $eth_blockNumber | jq -r '.result') - local current_block_number=$(($current_block_number_hex)) - - if (( $best_block_number > 0 )); then - local nominal_block_number=$(( $best_block_number - $BLOCK_HEIGHT_TOLERANCE )) - - if (( $current_block_number >= $nominal_block_number )); then - echo "daemon is synced with $PEER_COUNT peers and within block height tolerance of reference node" - exit 0 - fi - - echo "daemon is synced with $PEER_COUNT peers, but not within block height tolerance of reference node" - exit 1 - fi -} - if [[ $SYNCING == false ]]; then if (( $PEER_COUNT > 0 )); then + eth_blockNumber=$(curl -sf -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' -H 'Content-Type: application/json' http://localhost:8545) || exit 1 + current_block_number_hex=$(echo $eth_blockNumber | jq -r '.result') + current_block_number=$(($current_block_number_hex)) + + best_reference_block_number=$(get_best_reference_block_number https://polygon-rpc.com https://polygon-bor.publicnode.com https://polygon-mainnet.g.alchemy.com/v2/demo) + # if node is reporting synced, double check against reference nodes - reference_validation + reference_validation daemon $current_block_number $best_reference_block_number $BLOCK_HEIGHT_TOLERANCE echo "daemon is synced, with $PEER_COUNT peers" exit 0 diff --git a/node/coinstacks/polygon/pulumi/index.ts b/node/coinstacks/polygon/pulumi/index.ts index 86c2c1f72..c52c5ceb5 100644 --- a/node/coinstacks/polygon/pulumi/index.ts +++ b/node/coinstacks/polygon/pulumi/index.ts @@ -23,6 +23,8 @@ export = async (): Promise => { 'daemon-rpc': { port: 8545 }, 'daemon-ws': { port: 8546, pathPrefix: '/websocket', stripPathPrefix: true }, }, + configMapData: { 'evm.sh': readFileSync('../../../scripts/evm.sh').toString() }, + volumeMounts: [{ name: 'config-map', mountPath: '/evm.sh', subPath: 'evm.sh' }], startupProbe: { periodSeconds: 30, failureThreshold: 60, timeoutSeconds: 10 }, livenessProbe: { periodSeconds: 30, failureThreshold: 5, timeoutSeconds: 10 }, readinessProbe: { periodSeconds: 30, failureThreshold: 10, timeoutSeconds: 10 }, From 2a6308cf1f2d124e158cc62bfac402143765d78e Mon Sep 17 00:00:00 2001 From: kaladinlight <35275952+kaladinlight@users.noreply.github.com> Date: Thu, 3 Aug 2023 12:18:11 -0600 Subject: [PATCH 5/7] add op-node probes and update daemon probes --- node/coinstacks/optimism/daemon/init.sh | 1 + node/coinstacks/optimism/daemon/liveness.sh | 3 +- node/coinstacks/optimism/daemon/readiness.sh | 46 ++++--------------- node/coinstacks/optimism/op-node/liveness.sh | 28 +++++++++++ node/coinstacks/optimism/op-node/readiness.sh | 21 +++++---- node/coinstacks/optimism/op-node/startup.sh | 13 ++++++ node/coinstacks/optimism/pulumi/index.ts | 20 ++++++-- 7 files changed, 80 insertions(+), 52 deletions(-) create mode 100644 node/coinstacks/optimism/op-node/liveness.sh create mode 100644 node/coinstacks/optimism/op-node/startup.sh diff --git a/node/coinstacks/optimism/daemon/init.sh b/node/coinstacks/optimism/daemon/init.sh index ea4e0c2c3..d5a638933 100755 --- a/node/coinstacks/optimism/daemon/init.sh +++ b/node/coinstacks/optimism/daemon/init.sh @@ -34,6 +34,7 @@ start() { --txlookuplimit 0 \ --cache 4096 \ --maxpeers 0 \ + --snapshot='false' \ --nodiscover & PID="$!" } diff --git a/node/coinstacks/optimism/daemon/liveness.sh b/node/coinstacks/optimism/daemon/liveness.sh index 95ee68861..181be3805 100644 --- a/node/coinstacks/optimism/daemon/liveness.sh +++ b/node/coinstacks/optimism/daemon/liveness.sh @@ -16,8 +16,9 @@ PREVIOUS_BLOCK_NUMBER=$(cat $FILE) echo $CURRENT_BLOCK_NUMBER > $FILE if (( $CURRENT_BLOCK_NUMBER > $PREVIOUS_BLOCK_NUMBER )); then + echo "daemon is running" exit 0 fi -echo "daemon is stalled..." +echo "daemon is stalled" exit 1 \ No newline at end of file diff --git a/node/coinstacks/optimism/daemon/readiness.sh b/node/coinstacks/optimism/daemon/readiness.sh index e60fe863c..0c71c7f3d 100755 --- a/node/coinstacks/optimism/daemon/readiness.sh +++ b/node/coinstacks/optimism/daemon/readiness.sh @@ -1,52 +1,22 @@ #!/bin/bash +source /evm.sh + BLOCK_HEIGHT_TOLERANCE=25 ETH_SYNCING=$(curl -sf -d '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}' http://localhost:8545 -H 'Content-Type: application/json') || exit 1 SYNCING=$(echo $ETH_SYNCING | jq -r '.result') -get_best_block_number() { - local best_block_number=0 - - for reference_url in "$@"; do - local eth_blockNumber=$(curl -sf -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' -H 'Content-Type: application/json' $reference_url) - - if [[ $eth_blockNumber != "" ]]; then - local current_block_number_hex=$(echo $eth_blockNumber | jq -r '.result') - local current_block_number=$(($current_block_number_hex)) - - if (( $current_block_number > $best_block_number )); then - best_block_number=$current_block_number - fi - fi - done - - echo $best_block_number -} - -reference_validation() { - local best_block_number=$(get_best_block_number https://mainnet.optimism.io https://optimism.publicnode.com https://opt-mainnet.g.alchemy.com/v2/demo) - local eth_blockNumber=$(curl -sf -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' -H 'Content-Type: application/json' http://localhost:8545) || exit 1 - local current_block_number_hex=$(echo $eth_blockNumber | jq -r '.result') - local current_block_number=$(($current_block_number_hex)) - - if (( $best_block_number > 0 )); then - local nominal_block_number=$(( $best_block_number - $BLOCK_HEIGHT_TOLERANCE )) - - if (( $current_block_number >= $nominal_block_number )); then - echo "daemon is synced, and within block height tolerance of reference node" - exit 0 - fi +if [[ $SYNCING == false ]]; then + eth_blockNumber=$(curl -sf -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' -H 'Content-Type: application/json' http://localhost:8545) || exit 1 + current_block_number_hex=$(echo $eth_blockNumber | jq -r '.result') + current_block_number=$(($current_block_number_hex)) - echo "daemon is synced, but not within block height tolerance of reference node" - exit 1 - fi -} + best_reference_block_number=$(get_best_reference_block_number https://mainnet.optimism.io https://optimism.publicnode.com https://opt-mainnet.g.alchemy.com/v2/demo) -if [[ $SYNCING == false ]]; then # if node is reporting synced, double check against reference nodes - reference_validation + reference_validation daemon $current_block_number $best_reference_block_number $BLOCK_HEIGHT_TOLERANCE echo "daemon is synced" exit 0 diff --git a/node/coinstacks/optimism/op-node/liveness.sh b/node/coinstacks/optimism/op-node/liveness.sh new file mode 100644 index 000000000..996102407 --- /dev/null +++ b/node/coinstacks/optimism/op-node/liveness.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +FILE=/data/.block_number + +SYNC_STATUS=$(curl -sf -d '{"jsonrpc":"2.0","method":"optimism_syncStatus","params":[],"id":1}' http://localhost:9545 -H 'Content-Type: application/json') || exit 1 + +CURRENT_L1_BLOCK_NUMBER=$(echo $SYNC_STATUS | jq -r .result.current_l1.number) +CURRENT_L2_BLOCK_NUMBER=$(echo $SYNC_STATUS | jq -r .result.unsafe_l2.number) + +JSON="{\"l1\": $CURRENT_L1_BLOCK_NUMBER, \"l2\": $CURRENT_L2_BLOCK_NUMBER}" + +if [[ ! -f "$FILE" ]]; then + echo $JSON > $FILE + exit 1 +fi + +PREVIOUS_L1_BLOCK_NUMBER=$(cat $FILE | jq -r '.l1') +PREVIOUS_L2_BLOCK_NUMBER=$(cat $FILE | jq -r '.l2') + +echo $JSON > $FILE + +if (( $CURRENT_L1_BLOCK_NUMBER > $PREVIOUS_L1_BLOCK_NUMBER && $CURRENT_L2_BLOCK_NUMBER > $PREVIOUS_L2_BLOCK_NUMBER )); then + echo "op-node is running" + exit 0 +fi + +echo "op-node is stalled" +exit 1 \ No newline at end of file diff --git a/node/coinstacks/optimism/op-node/readiness.sh b/node/coinstacks/optimism/op-node/readiness.sh index 2b0a520c5..b99aee5e1 100755 --- a/node/coinstacks/optimism/op-node/readiness.sh +++ b/node/coinstacks/optimism/op-node/readiness.sh @@ -1,19 +1,22 @@ #!/bin/bash -# ethereum block height -L1_HEIGHT_HEX=$(curl -s -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' $L1_RPC_ENDPOINT -H 'Content-Type: application/json' | jq -r .result) -L1_HEIGHT=$(echo $(($L1_HEIGHT_HEX))) +source /evm.sh + +BLOCK_HEIGHT_TOLERANCE=5 SYNC_STATUS=$(curl -s -d '{"jsonrpc":"2.0","method":"optimism_syncStatus","params":[],"id":1}' http://localhost:9545 -H 'Content-Type: application/json') -# op-node L1 block height -CURRENT_L1_HEIGHT=$(echo $SYNC_STATUS | jq -r .result.current_l1.number) -# op-node l2 blocks still left to sync + QUEUED_UNSAFE_L2_HEIGHT=$(echo $SYNC_STATUS | jq -r .result.queued_unsafe_l2.number) -if [[ $L1_HEIGHT -eq $CURRENT_L1_HEIGHT && QUEUED_UNSAFE_L2_HEIGHT -eq 0 ]]; then - echo "node is synced" +if (( $QUEUED_UNSAFE_L2_HEIGHT == 0 )); then + current_l1_block_number=$(echo $SYNC_STATUS | jq -r .result.current_l1.number) + best_reference_block_number=$(get_best_reference_block_number $L1_RPC_ENDPOINT https://ethereum.publicnode.com https://eth-mainnet.g.alchemy.com/v2/demo) + + reference_validation op-node $current_l1_block_number $best_reference_block_number $BLOCK_HEIGHT_TOLERANCE + + echo "op-node is synced" exit 0 fi -echo "node is still syncing" +echo "op-node is still syncing" exit 1 \ No newline at end of file diff --git a/node/coinstacks/optimism/op-node/startup.sh b/node/coinstacks/optimism/op-node/startup.sh new file mode 100644 index 000000000..294e430ba --- /dev/null +++ b/node/coinstacks/optimism/op-node/startup.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +VERSION=$(curl -sf -d '{"jsonrpc":"2.0","method":"optimism_version","params":[],"id":1}' http://localhost:9545 -H 'Content-Type: application/json') || exit 1 + +RESULT=$(echo $VERSION | jq -r '.result') + +if [[ result != "" ]]; then + echo "op-node started" + exit 0 +fi + +echo "op-node not started" +exit 1 \ No newline at end of file diff --git a/node/coinstacks/optimism/pulumi/index.ts b/node/coinstacks/optimism/pulumi/index.ts index 816f43e3c..2c1ceb25f 100644 --- a/node/coinstacks/optimism/pulumi/index.ts +++ b/node/coinstacks/optimism/pulumi/index.ts @@ -21,10 +21,16 @@ export = async (): Promise => { 'daemon-ws': { port: 8546, pathPrefix: '/websocket', stripPathPrefix: true }, 'daemon-auth': { port: 8551, ingressRoute: false }, }, - configMapData: { 'jwt.hex': readFileSync('../daemon/jwt.hex').toString() }, - volumeMounts: [{ name: 'config-map', mountPath: '/jwt.hex', subPath: 'jwt.hex' }], + configMapData: { + 'jwt.hex': readFileSync('../daemon/jwt.hex').toString(), + 'evm.sh': readFileSync('../../../scripts/evm.sh').toString(), + }, + volumeMounts: [ + { name: 'config-map', mountPath: '/jwt.hex', subPath: 'jwt.hex' }, + { name: 'config-map', mountPath: '/evm.sh', subPath: 'evm.sh' }, + ], startupProbe: { periodSeconds: 30, failureThreshold: 60, timeoutSeconds: 10 }, - livenessProbe: { periodSeconds: 30, timeoutSeconds: 10 }, + livenessProbe: { periodSeconds: 30, failureThreshold: 5, timeoutSeconds: 10 }, readinessProbe: { periodSeconds: 30, failureThreshold: 10, timeoutSeconds: 10 }, } @@ -36,7 +42,13 @@ export = async (): Promise => { L1_RPC_ENDPOINT: `http://ethereum-svc.${namespace}.svc.cluster.local:8332`, }, ports: { 'op-node-rpc': { port: 9545 } }, - volumeMounts: [{ name: 'config-map', mountPath: '/jwt.hex', subPath: 'jwt.hex' }], + configMapData: { 'evm.sh': readFileSync('../../../scripts/evm.sh').toString() }, + volumeMounts: [ + { name: 'config-map', mountPath: '/jwt.hex', subPath: 'jwt.hex' }, + { name: 'config-map', mountPath: '/evm.sh', subPath: 'evm.sh' }, + ], + startupProbe: { periodSeconds: 30, failureThreshold: 60, timeoutSeconds: 10 }, + livenessProbe: { periodSeconds: 30, failureThreshold: 5, timeoutSeconds: 10 }, readinessProbe: { periodSeconds: 30, failureThreshold: 10 }, } case 'indexer': From 527344f928bb63cf08fec9d2d4b38b69e78956c6 Mon Sep 17 00:00:00 2001 From: kaladinlight <35275952+kaladinlight@users.noreply.github.com> Date: Thu, 3 Aug 2023 12:18:40 -0600 Subject: [PATCH 6/7] log success and use correct service name --- node/coinstacks/bnbsmartchain/daemon/liveness.sh | 3 ++- node/coinstacks/polygon/daemon/liveness.sh | 3 ++- node/coinstacks/polygon/heimdall/liveness.sh | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/node/coinstacks/bnbsmartchain/daemon/liveness.sh b/node/coinstacks/bnbsmartchain/daemon/liveness.sh index 3dc5d15b7..814ed323d 100644 --- a/node/coinstacks/bnbsmartchain/daemon/liveness.sh +++ b/node/coinstacks/bnbsmartchain/daemon/liveness.sh @@ -16,8 +16,9 @@ PREVIOUS_BLOCK_NUMBER=$(cat $FILE) echo $CURRENT_BLOCK_NUMBER > $FILE if (( $CURRENT_BLOCK_NUMBER > $PREVIOUS_BLOCK_NUMBER )); then + echo "daemon is running" exit 0 fi -echo "daemon is stalled..." +echo "daemon is stalled" exit 1 \ No newline at end of file diff --git a/node/coinstacks/polygon/daemon/liveness.sh b/node/coinstacks/polygon/daemon/liveness.sh index 3dc5d15b7..814ed323d 100644 --- a/node/coinstacks/polygon/daemon/liveness.sh +++ b/node/coinstacks/polygon/daemon/liveness.sh @@ -16,8 +16,9 @@ PREVIOUS_BLOCK_NUMBER=$(cat $FILE) echo $CURRENT_BLOCK_NUMBER > $FILE if (( $CURRENT_BLOCK_NUMBER > $PREVIOUS_BLOCK_NUMBER )); then + echo "daemon is running" exit 0 fi -echo "daemon is stalled..." +echo "daemon is stalled" exit 1 \ No newline at end of file diff --git a/node/coinstacks/polygon/heimdall/liveness.sh b/node/coinstacks/polygon/heimdall/liveness.sh index 209c9192b..f220ac70d 100755 --- a/node/coinstacks/polygon/heimdall/liveness.sh +++ b/node/coinstacks/polygon/heimdall/liveness.sh @@ -15,8 +15,9 @@ PREVIOUS_BLOCK_HEIGHT=$(cat $FILE) echo $LATEST_BLOCK_HEIGHT > $FILE if (( $LATEST_BLOCK_HEIGHT > $PREVIOUS_BLOCK_HEIGHT )); then + echo "heimdall is running" exit 0 fi -echo "node is stalled..." +echo "heimdall is stalled" exit 1 \ No newline at end of file From b7c3fd2dc51f792c6320035f1318f4ec67e2d289 Mon Sep 17 00:00:00 2001 From: kaladinlight <35275952+kaladinlight@users.noreply.github.com> Date: Thu, 3 Aug 2023 12:20:14 -0600 Subject: [PATCH 7/7] don't check in snapshot false --- node/coinstacks/optimism/daemon/init.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/node/coinstacks/optimism/daemon/init.sh b/node/coinstacks/optimism/daemon/init.sh index d5a638933..ea4e0c2c3 100755 --- a/node/coinstacks/optimism/daemon/init.sh +++ b/node/coinstacks/optimism/daemon/init.sh @@ -34,7 +34,6 @@ start() { --txlookuplimit 0 \ --cache 4096 \ --maxpeers 0 \ - --snapshot='false' \ --nodiscover & PID="$!" }