readiness.sh


Overview

`readiness.sh` is a Bash script designed to act as a Kubernetes readiness probe or a general health check for an Ethereum-compatible blockchain node daemon. Its primary purpose is to determine whether the local blockchain node is fully synchronized with the network and ready to serve requests.

The script performs the following key tasks:

This script helps orchestrators like Kubernetes decide when to route traffic to the node or restart it if it is not yet ready.


Detailed Explanation

Variables

Variable

Description

DISABLE_READINESS_PROBE

Path to a file ([/data/disable_readiness](/projects/291/68846)) which, if present, disables the readiness probe check.

`BLOCK_HEIGHT_TOLERANCE`

Numeric tolerance (default 25 blocks) used to compare local block height against reference nodes.

ETH_SYNCING

JSON response from the `eth_syncing` JSON-RPC method indicating sync status or syncing details.

`SYNCING`

Extracted `.result` field from [ETH_SYNCING](/projects/291/69231) indicating if the node is syncing (`true`) or not (`false`).


Script Workflow

  1. Disable Check
    The script first checks if the file /data/disable_readiness exists.

    • If present, it prints "readiness probe disabled" and exits with status code 0, indicating readiness regardless of sync status.

  2. Load Environment
    It sources /evm.sh which is assumed to contain environment variables or helper functions like get_best_reference_block_number and reference_validation.

    • These functions are critical for cross-checking block heights against reference nodes.

  3. Check Sync Status
    It performs a JSON-RPC call to the local node at http://localhost:8545 with the eth_syncing method.

    • If the call fails, the script exits with code 1 (not ready).

    • If the node reports false, it means the node is not syncing and is considered fully synced.

  4. Validate Block Height Against Reference Nodes
    When the node reports synced:

    • Retrieves the current block number from the node using eth_blockNumber JSON-RPC call.

    • Converts block number from hex to decimal.

    • Calls get_best_reference_block_number with URLs of external reference RPC endpoints to get the highest block height among them.

    • Calls reference_validation with parameters: "daemon", current block number, best reference block number, and the block height tolerance.

      • This validates the node is within an acceptable range of the reference block height.

      • If validation passes, the script prints "daemon is synced" and exits 0.

      • If validation fails, assumed to exit non-zero internally, causing readiness to fail.

  5. Node Still Syncing
    If eth_syncing returns a syncing status (not false), the script prints "daemon is still syncing" and exits 1.


Functions / Methods

This script depends on external functions presumably defined in `/evm.sh`:

get_best_reference_block_number

**Purpose:** Queries multiple external blockchain RPC endpoints and returns the highest block number among them.

**Parameters:**

**Returns:**

**Usage Example:**

best_block=$(get_best_reference_block_number https://mainnet.base.org https://base-rpc.publicnode.com https://base.llamarpc.com)

reference_validation

**Purpose:** Validates that the local node's block number is within a specified tolerance of the reference block number.

**Parameters:**

**Returns:**

**Usage Example:**

reference_validation daemon 1234567 1234590 25

Important Implementation Details


Interaction with Other System Components


Usage Example

Run the script manually to check readiness:

./readiness.sh

# Possible outputs:
# readiness probe disabled
# daemon is synced
# daemon is still syncing

Exit code 0 indicates ready; exit code 1 indicates not ready.


Mermaid Diagram: Flowchart of Main Functions and Workflow

flowchart TD
    A[Start] --> B{Disable Readiness Probe?}
    B -- Yes --> C[Print "readiness probe disabled"] --> Z[Exit 0]
    B -- No --> D[Source /evm.sh]
    D --> E[Call eth_syncing RPC]
    E --> F{Is SYNCING == false?}
    F -- Yes --> G[Call eth_blockNumber RPC]
    G --> H[Get current block number]
    H --> I[get_best_reference_block_number with reference URLs]
    I --> J[reference_validation daemon current_block best_reference BLOCK_HEIGHT_TOLERANCE]
    J --> K[Print "daemon is synced"] --> Z
    F -- No --> L[Print "daemon is still syncing"] --> Y[Exit 1]
    E -- RPC fail --> Y
    G -- RPC fail --> Y

Summary

`readiness.sh` is a concise, robust readiness probe script tailored for Ethereum-compatible blockchain nodes. It smartly combines local node sync checks with cross-validation against external reliable nodes to ensure accurate readiness reporting. Its design supports disabling via a file flag and relies on external helper scripts for modularity. This script is essential for maintaining high availability and correctness in blockchain node deployments within containerized environments.