From 66d248d406fc18243d0a6368ee4d578b878bad94 Mon Sep 17 00:00:00 2001 From: CRF1408 <76657627+CRF1408@users.noreply.github.com> Date: Fri, 19 Dec 2025 11:34:38 +0100 Subject: [PATCH] Create check_nethermind_rpc.sh add rpc healthcheck helper script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR adds a small check_nethermind_rpc.sh helper under nethermind/ that can be used as a Docker healthcheck or external probe. It validates that the Nethermind JSON-RPC endpoint responds to eth_syncing and treats both “synced” and “currently syncing” states as healthy, with optional configuration via BASE_NETHERMIND_RPC_URL and BASE_NETHERMIND_RPC_TIMEOUT. --- nethermind/check_nethermind_rpc.sh | 50 ++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 nethermind/check_nethermind_rpc.sh diff --git a/nethermind/check_nethermind_rpc.sh b/nethermind/check_nethermind_rpc.sh new file mode 100644 index 00000000..ec950a29 --- /dev/null +++ b/nethermind/check_nethermind_rpc.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Simple healthcheck for a Nethermind JSON-RPC endpoint. +# Can be used from Docker HEALTHCHECK or external monitoring. +# +# Environment (optional): +# BASE_NETHERMIND_RPC_URL - RPC URL to probe (default: http://localhost:8545) +# BASE_NETHERMIND_RPC_TIMEOUT - curl timeout in seconds (default: 3) + +RPC_URL="${BASE_NETHERMIND_RPC_URL:-http://localhost:8545}" +TIMEOUT="${BASE_NETHERMIND_RPC_TIMEOUT:-3}" + +log_err() { + echo "[nethermind-health] $*" >&2 +} + +if ! command -v curl >/dev/null 2>&1; then + log_err "curl not found in PATH" + exit 1 +fi + +payload='{"jsonrpc":"2.0","id":1,"method":"eth_syncing","params":[]}' + +response="$(curl -sS \ + --max-time "${TIMEOUT}" \ + -H "Content-Type: application/json" \ + -d "${payload}" \ + "${RPC_URL}" 2>/dev/null || true)" + +if [ -z "${response}" ]; then + log_err "empty response from ${RPC_URL}" + exit 1 +fi + +# Consider node healthy if: +# - it reports "result": false (fully synced), or +# - eth_syncing structure contains "currentBlock" (sync in progress). +if echo "${response}" | grep -q '"result":false'; then + echo "ok: nethermind is synced" + exit 0 +fi + +if echo "${response}" | grep -q '"currentBlock"'; then + echo "ok: nethermind is syncing" + exit 0 +fi + +log_err "unexpected eth_syncing response: ${response}" +exit 1