readiness.sh


Overview

`readiness.sh` is a Bash script designed to serve as a readiness probe for a blockchain node service, likely within a containerized or orchestrated environment (e.g., Kubernetes). Its primary function is to determine whether the blockchain node is fully synced and ready to handle requests by comparing the node's current block height against external reference nodes. This check helps prevent traffic routing to nodes that are still syncing and not yet up-to-date.

The script performs the following key tasks:


Detailed Explanations

Constants and Variables


Script Workflow and Key Commands

1. Readiness Probe Disable Check

if [[ -f "$DISABLE_READINESS_PROBE" ]]; then
  echo "readiness probe disabled"
  exit 0
fi

2. Environment Setup

source /evm.sh

*(Note: These functions are not defined within `readiness.sh`, so they must exist in `/evm.sh`.)*

3. Query Local Node Sync Status

ETH_SYNCING=$(curl -sf -d '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}' -H 'Content-Type: application/json' http://localhost:8547) || exit 1
SYNCING=$(echo $ETH_SYNCING | jq -r '.result')

4. If Node Is Not Syncing

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:8547) || 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://nova.arbitrum.io/rpc https://arbitrum-nova.publicnode.com)
  
  reference_validation daemon $current_block_number $best_reference_block_number $BLOCK_HEIGHT_TOLERANCE
fi

5. If Node Is Still Syncing or Validation Fails

echo "daemon is still syncing"
exit 1

Functions and Methods

The script itself does not define its own functions but depends on the following functions presumed to exist in `/evm.sh`:

get_best_reference_block_number

reference_validation


Important Implementation Details


Interaction with Other Parts of the System


Usage Example

If running manually, the script can be executed to check if the node is ready:

./readiness.sh

Mermaid Flowchart Diagram

flowchart TD
    A[Start] --> B{Check disable file?}
    B -- Yes --> C[Print "readiness probe disabled"] --> D[Exit 0]
    B -- No --> E[Source /evm.sh]
    E --> F[Query local node eth_syncing]
    F --> G{Syncing?}
    G -- Yes --> H[Print "daemon is still syncing"] --> I[Exit 1]
    G -- No --> J[Query local node eth_blockNumber]
    J --> K[Get best reference block number]
    K --> L[Call reference_validation with local & ref blocks]
    L --> M{Validation result}
    M -- Pass --> N[Exit 0]
    M -- Fail --> H

Summary

`readiness.sh` is a critical utility script that determines the readiness of a blockchain node by verifying its sync status and block height against trusted reference nodes. It integrates tightly with external helper scripts and Ethereum-compatible RPC endpoints to provide a robust readiness check mechanism suitable for orchestrated environments. Its use of a disable flag and tolerance window provides flexibility and resilience in operational scenarios.