138 lines
4.5 KiB
Bash
Executable File
138 lines
4.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Chain 138 — RPC health: parallel head check + per-node peer count + public RPC capability probe.
|
|
# Exit 0 if all HTTP RPCs respond, head spread <= max_blocks_spread, each peer count >= min_peers,
|
|
# and the public RPC capability probe matches the currently documented support matrix.
|
|
#
|
|
# Usage: ./scripts/verify/check-chain138-rpc-health.sh
|
|
# Env: RPC_MAX_HEAD_SPREAD (default 12), RPC_MIN_PEERS (default 10), RPC_TIMEOUT_SEC (default 20),
|
|
# CHAIN138_PUBLIC_RPC_URL (default https://rpc-http-pub.d-bis.org)
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
# shellcheck source=/dev/null
|
|
source "${PROJECT_ROOT}/config/ip-addresses.conf" 2>/dev/null || true
|
|
|
|
MAX_SPREAD="${RPC_MAX_HEAD_SPREAD:-12}"
|
|
MIN_PEERS="${RPC_MIN_PEERS:-10}"
|
|
TO="${RPC_TIMEOUT_SEC:-20}"
|
|
PUBLIC_RPC_URL="${CHAIN138_PUBLIC_RPC_URL:-https://rpc-http-pub.d-bis.org}"
|
|
|
|
# VMID|IP (HTTP :8545)
|
|
RPC_ROWS=(
|
|
"2101|${IP_BESU_RPC_CORE_1:-192.168.11.211}"
|
|
"2102|${IP_BESU_RPC_CORE_2:-192.168.11.212}"
|
|
"2201|${IP_BESU_RPC_PUBLIC_1:-192.168.11.221}"
|
|
"2301|${IP_BESU_RPC_PRIVATE_1:-192.168.11.232}"
|
|
"2303|192.168.11.233"
|
|
"2304|192.168.11.234"
|
|
"2305|192.168.11.235"
|
|
"2306|192.168.11.236"
|
|
"2307|192.168.11.237"
|
|
"2308|192.168.11.238"
|
|
"2400|192.168.11.240"
|
|
"2401|192.168.11.241"
|
|
"2402|192.168.11.242"
|
|
"2403|192.168.11.243"
|
|
)
|
|
|
|
PAYLOAD_BN='{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
|
|
PAYLOAD_PC='{"jsonrpc":"2.0","method":"net_peerCount","params":[],"id":1}'
|
|
|
|
tmpdir=$(mktemp -d)
|
|
trap 'rm -rf "$tmpdir"' EXIT
|
|
|
|
for row in "${RPC_ROWS[@]}"; do
|
|
vmid="${row%%|*}"
|
|
ip="${row#*|}"
|
|
(
|
|
curl -sS -m "$TO" -X POST "http://${ip}:8545" -H "Content-Type: application/json" -d "$PAYLOAD_BN" >"$tmpdir/bn-$vmid.json" 2>/dev/null || echo '{"error":"curl"}' >"$tmpdir/bn-$vmid.json"
|
|
curl -sS -m "$TO" -X POST "http://${ip}:8545" -H "Content-Type: application/json" -d "$PAYLOAD_PC" >"$tmpdir/pc-$vmid.json" 2>/dev/null || echo '{"error":"curl"}' >"$tmpdir/pc-$vmid.json"
|
|
) &
|
|
done
|
|
wait
|
|
|
|
fail=0
|
|
min_b=999999999
|
|
max_b=0
|
|
echo "Chain 138 RPC health (parallel sample)"
|
|
printf '%-5s %-15s %-10s %-8s\n' "VMID" "IP" "block(dec)" "peers"
|
|
echo "------------------------------------------------------------"
|
|
|
|
for row in "${RPC_ROWS[@]}"; do
|
|
vmid="${row%%|*}"
|
|
ip="${row#*|}"
|
|
bh=$(jq -r '.result // empty' "$tmpdir/bn-$vmid.json" 2>/dev/null || true)
|
|
ph=$(jq -r '.result // empty' "$tmpdir/pc-$vmid.json" 2>/dev/null || true)
|
|
if [[ -z "$bh" ]]; then
|
|
printf '%-5s %-15s %-10s %-8s\n' "$vmid" "$ip" "FAIL" "—"
|
|
((fail++)) || true
|
|
continue
|
|
fi
|
|
bd=$((bh))
|
|
pd=$((ph))
|
|
[[ "$bd" -lt "$min_b" ]] && min_b=$bd
|
|
[[ "$bd" -gt "$max_b" ]] && max_b=$bd
|
|
if [[ "$pd" -lt "$MIN_PEERS" ]]; then
|
|
printf '%-5s %-15s %-10s %-8s LOW_PEERS\n' "$vmid" "$ip" "$bd" "$pd"
|
|
((fail++)) || true
|
|
else
|
|
printf '%-5s %-15s %-10s %-8s\n' "$vmid" "$ip" "$bd" "$pd"
|
|
fi
|
|
done
|
|
|
|
spread=$((max_b - min_b))
|
|
echo "------------------------------------------------------------"
|
|
echo "Head spread (max-min): $spread (max allowed $MAX_SPREAD)"
|
|
if [[ "$spread" -gt "$MAX_SPREAD" ]]; then
|
|
echo "FAIL: head spread too large"
|
|
((fail++)) || true
|
|
fi
|
|
|
|
if [[ "$fail" -eq 0 ]]; then
|
|
echo "OK: all RPCs responded, peers >= $MIN_PEERS, spread <= $MAX_SPREAD"
|
|
else
|
|
echo "FAIL: $fail check(s) failed"
|
|
fi
|
|
|
|
echo
|
|
echo "Chain 138 public RPC capability probe ($PUBLIC_RPC_URL)"
|
|
|
|
rpc_request() {
|
|
local method="$1"
|
|
local params="${2:-[]}"
|
|
curl -sS -m "$TO" -X POST "$PUBLIC_RPC_URL" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"jsonrpc\":\"2.0\",\"method\":\"${method}\",\"params\":${params},\"id\":1}"
|
|
}
|
|
|
|
check_supported_method() {
|
|
local method="$1"
|
|
local params="${2:-[]}"
|
|
local response result
|
|
response="$(rpc_request "$method" "$params" || printf '%s' '{"error":"curl"}')"
|
|
result="$(printf '%s' "$response" | jq -r '.result // empty' 2>/dev/null || true)"
|
|
if [[ -n "$result" ]]; then
|
|
printf ' %-32s %s\n' "$method" "OK"
|
|
return 0
|
|
fi
|
|
printf ' %-32s %s\n' "$method" "FAIL"
|
|
((fail++)) || true
|
|
return 1
|
|
}
|
|
|
|
check_supported_method "eth_chainId"
|
|
check_supported_method "eth_gasPrice"
|
|
check_supported_method "eth_maxPriorityFeePerGas"
|
|
check_supported_method "eth_feeHistory" "[\"0x1\", \"latest\", []]"
|
|
check_supported_method "trace_block" "[\"0x1\"]"
|
|
check_supported_method "trace_replayBlockTransactions" "[\"0x1\", [\"trace\"]]"
|
|
|
|
if [[ "$fail" -eq 0 ]]; then
|
|
echo "OK: node health and public RPC capability checks passed"
|
|
exit 0
|
|
fi
|
|
echo "FAIL: $fail check(s) failed"
|
|
exit 1
|