Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve optimism probes #830

Merged
merged 7 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go/coinstacks/osmosis/daemon/liveness.sh
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion node/Dockerfile.probe
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions node/coinstacks/bnbsmartchain/daemon/liveness.sh
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
50 changes: 10 additions & 40 deletions node/coinstacks/bnbsmartchain/daemon/readiness.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions node/coinstacks/bnbsmartchain/pulumi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export = async (): Promise<Outputs> => {
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 },
Expand Down
2 changes: 1 addition & 1 deletion node/coinstacks/optimism/daemon/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

apk add curl jq
apk add bash curl jq

DATA_DIR=/data
CHAINDATA_DIR=$DATA_DIR/geth/chaindata
Expand Down
24 changes: 24 additions & 0 deletions node/coinstacks/optimism/daemon/liveness.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/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
echo "daemon is running"
exit 0
fi

echo "daemon is stalled"
exit 1
26 changes: 26 additions & 0 deletions node/coinstacks/optimism/daemon/readiness.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/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')

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))

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 node is reporting synced, double check against reference nodes
reference_validation daemon $current_block_number $best_reference_block_number $BLOCK_HEIGHT_TOLERANCE

echo "daemon is synced"
exit 0
fi

echo "daemon is still syncing"
exit 1
13 changes: 13 additions & 0 deletions node/coinstacks/optimism/daemon/startup.sh
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions node/coinstacks/optimism/op-node/liveness.sh
Original file line number Diff line number Diff line change
@@ -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
21 changes: 12 additions & 9 deletions node/coinstacks/optimism/op-node/readiness.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions node/coinstacks/optimism/op-node/startup.sh
Original file line number Diff line number Diff line change
@@ -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
21 changes: 18 additions & 3 deletions node/coinstacks/optimism/pulumi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@ export = async (): Promise<Outputs> => {
'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, failureThreshold: 5, timeoutSeconds: 10 },
readinessProbe: { periodSeconds: 30, failureThreshold: 10, timeoutSeconds: 10 },
}

case 'op-node':
Expand All @@ -33,7 +42,13 @@ export = async (): Promise<Outputs> => {
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':
Expand Down
5 changes: 3 additions & 2 deletions node/coinstacks/polygon/daemon/liveness.sh
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
48 changes: 9 additions & 39 deletions node/coinstacks/polygon/daemon/readiness.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Loading