readiness.sh


Overview

`readiness.sh` is a Bash script designed as a readiness probe for a blockchain daemon node, specifically targeting an Ethereum-compatible node running locally (on `localhost:8545`). Its primary purpose is to determine whether the node is sufficiently synchronized and connected to peers to be considered "ready" for operation.

The script performs the following key checks:

This ensures that the node is not only synced locally but also in alignment with the broader blockchain network, preventing premature readiness signals.


Detailed Explanation

Constants and Variables

Name

Description

DISABLE_READINESS_PROBE

File path `/data/disable_readiness`, presence disables the readiness check.

BLOCK_HEIGHT_TOLERANCE

Allowed difference in block heights between the local node and reference nodes (default: 15 blocks).


Script Logic Flow

  1. Disable Check
    If the file /data/disable_readiness exists, the script immediately exits with status 0, indicating readiness probe is disabled.

  2. Environment Setup
    Sources /evm.sh for environment variables or helper functions (expected to define functions such as get_best_reference_block_number and reference_validation).

  3. Node Status Queries
    Uses curl to query local node JSON-RPC endpoints:

    • eth_syncing to check if the node is syncing.

    • net_peerCount to get the number of connected peers.

  4. Readiness Decision

    • If syncing is false and there is at least one peer connected:

      • Retrieves the current block number from the local node.

      • Calls get_best_reference_block_number with a randomized choice of Binance Smart Chain public RPC nodes to get the highest block number among them.

      • Calls reference_validation to compare local block number and reference block number within tolerance.

      • Exits with 0 if checks pass.

    • If synced but no peers, exits with 1.

    • If syncing is still ongoing, exits with 1.


Functions and Methods

The script references two external functions that must be defined in `/evm.sh` or sourced elsewhere:

get_best_reference_block_number

best_reference_block_number=$(get_best_reference_block_number https://node1 https://node2 https://node3)

reference_validation

reference_validation daemon 12345678 12345690 15

Important Implementation Details


Interaction with Other System Components


Usage Example

# Run readiness check manually
./readiness.sh

# Output examples:
# readiness probe disabled
# daemon is synced, with 5 peers
# daemon is synced, but has no peers
# daemon is still syncing

Mermaid Flowchart Diagram

The following flowchart illustrates the main decision workflow of the `readiness.sh` script:

flowchart TD
    Start([Start])

    CheckDisable{File /data/disable_readiness exists?}
    ExitDisabled[echo "readiness probe disabled"\nexit 0]

    QuerySyncing[Query eth_syncing]
    QueryPeers[Query net_peerCount]

    IsSyncing{Syncing == false?}
    HasPeers{PeerCount > 0?}

    GetLocalBlock[Get local eth_blockNumber]
    GetReferenceBlock[Get best reference block number\n(from public nodes)]

    ValidateBlocks[reference_validation\n(local vs reference)]

    Ready[echo "daemon is synced, with $PEER_COUNT peers"\nexit 0]
    NoPeers[echo "daemon is synced, but has no peers"\nexit 1]
    Syncing[echo "daemon is still syncing"\nexit 1]

    ErrorExit1[exit 1 on curl failure]

    Start --> CheckDisable
    CheckDisable -- Yes --> ExitDisabled
    CheckDisable -- No --> QuerySyncing
    QuerySyncing -- Fail --> ErrorExit1
    QuerySyncing -- Success --> QueryPeers
    QueryPeers -- Fail --> ErrorExit1
    QueryPeers -- Success --> IsSyncing

    IsSyncing -- No --> Syncing
    IsSyncing -- Yes --> HasPeers
    HasPeers -- No --> NoPeers
    HasPeers -- Yes --> GetLocalBlock
    GetLocalBlock --> GetReferenceBlock
    GetReferenceBlock --> ValidateBlocks
    ValidateBlocks --> Ready

Summary

`readiness.sh` is a critical readiness probe script for an Ethereum-compatible blockchain node. It robustly checks the node's sync status and peer connectivity, validates synchronization against external reference nodes, and integrates with orchestration platforms to signal operational readiness. Its modular design, leveraging external utility scripts and public RPC endpoints, ensures accuracy and scalability within blockchain infrastructure deployments.