readiness.sh


Overview

`readiness.sh` is a shell script designed as a **readiness probe** for an Ethereum Virtual Machine (EVM) compatible blockchain node daemon—specifically targeting Arbitrum in this instance. Its primary purpose is to verify whether the blockchain node is sufficiently synchronized and ready to accept traffic or API requests.

This script performs a series of checks including:

The script ensures Kubernetes only routes traffic to nodes that are properly synchronized, improving reliability and user experience.


Detailed Explanation

Constants and Variables

Name

Purpose

`DISABLE_READINESS_PROBE`

Path to a file (`/data/disable_readiness`) which, if present, disables readiness checks.

`BLOCK_HEIGHT_TOLERANCE`

Integer tolerance for block height difference (set to 15 blocks) allowed between node and network.


Step-by-step Functionality

1. Disable Readiness Probe Check

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

2. Source External Utility Script

source /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

4. Parse Sync Status

SYNCING=$(echo $ETH_SYNCING | jq -r '.result')

5. If Not Syncing, Validate Block Height Against Reference Nodes

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://arb1.arbitrum.io/rpc https://arbitrum-one.publicnode.com https://arb-mainnet.g.alchemy.com/v2/demo)

  reference_validation daemon $current_block_number $best_reference_block_number $BLOCK_HEIGHT_TOLERANCE
fi

6. If Syncing or Validation Fails

echo "daemon is still syncing"
exit 1

Usage Example

This script is typically run by Kubernetes readiness probe configured in the pod spec for the blockchain daemon container, e.g.:

readinessProbe:
  exec:
    command:
    - /bin/bash
    - /path/to/readiness.sh
  initialDelaySeconds: 10
  periodSeconds: 15
  failureThreshold: 3

Operators can manually disable readiness probing by creating `/data/disable_readiness` inside the container or volume mount.


Important Implementation Details


Interaction with Other System Components


Mermaid Diagram - Script Flowchart

flowchart TD
  Start[Start] --> CheckDisableFile{Is /data/disable_readiness present?}
  CheckDisableFile -- Yes --> Disabled[Print "readiness probe disabled"\nExit 0]
  CheckDisableFile -- No --> QuerySync[Query eth_syncing RPC]
  QuerySync --> ParseSync[Parse .result from eth_syncing]
  ParseSync --> IsSyncing{Is syncing == false?}
  IsSyncing -- No --> NotReady[Print "daemon is still syncing"\nExit 1]
  IsSyncing -- Yes --> QueryBlockNumber[Query eth_blockNumber RPC]
  QueryBlockNumber --> ConvertHex[Convert hex block number to decimal]
  ConvertHex --> GetReference[Call get_best_reference_block_number with external RPCs]
  GetReference --> Validate[Call reference_validation with local & reference blocks]
  Validate --> ExitSuccess[Exit 0 if validation passes]
  Validate --> ExitFail[Exit 1 if validation fails]

Summary

The `readiness.sh` script is a critical Kubernetes readiness probe tailored for EVM-compatible blockchain daemons such as Arbitrum. It performs a multi-step synchronization check by querying the local node and validating against trusted external reference nodes, enforcing a block height tolerance to ensure the node is truly ready to serve. The script’s design emphasizes fail-fast behavior, modularity via sourced utility functions, and operational flexibility through the disable file mechanism. This approach helps maintain high availability and correct traffic routing in blockchain node deployments.