readiness.sh


Overview

`readiness.sh` is a lightweight shell script designed to check the synchronization status of a local Ethereum beacon node daemon (commonly referred to as `daemon-beacon`). Its primary purpose is to determine if the beacon node has fully synced with the Ethereum network, which is critical for ensuring readiness before the node can participate in or serve data reliably.

The script queries the beacon node's REST API endpoint, inspects the syncing status, and returns an appropriate exit code and message based on the node's synchronization state. This behavior makes it suitable for use as a readiness probe in container orchestration systems (e.g., Kubernetes), monitoring tools, or automation workflows that depend on the node being fully synced.


Detailed Explanation

Script Behavior

  1. Fetch Syncing Status
    The script sends a silent HTTP GET request to the local beacon node's sync status endpoint:

    http://localhost:5052/eth/v1/node/syncing
    

    It captures the JSON response. If the request fails (e.g., service not reachable), the script exits immediately with code 1.

  2. Parse Syncing Flag
    Using jq, a lightweight JSON processor, the script extracts the boolean field .data.is_syncing from the JSON response.

  3. Check Sync Status

    • If .data.is_syncing is false, it indicates the beacon node is fully synced:

      • Prints: "daemon-beacon is synced"

      • Exits with status code 0 (success).

    • Otherwise, it prints "daemon-beacon is still syncing" and exits with status code 1 (failure).


Explanation of Script Components

This script is a simple linear flow without functions or classes. Below is a breakdown of the main steps and commands.

Step

Command/Concept

Purpose

1

`curl -sf http://localhost:5052/eth/v1/node/syncing`

Silent HTTP request to beacon node API endpoint

2

`

3

`jq -r '.data.is_syncing'`

Parse JSON field `is_syncing` from response

4

`if [[ $IS_SYNCING == false ]]`

Branch based on syncing status

5

`echo "daemon-beacon is synced"` and `exit 0`

Success message and exit code

6

`echo "daemon-beacon is still syncing"` and `exit 1`

Failure message and exit code


Usage Examples

Basic usage in CLI or script

./readiness.sh

Integration with Kubernetes Readiness Probe

This script is well-suited for Kubernetes readiness probes. Example snippet in a Pod manifest:

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

The container will be marked ready only once the script exits with `0`, i.e., after the beacon node finishes syncing.


Important Implementation Details


Interaction with Other System Components


Visual Diagram

The following flowchart represents the workflow of `readiness.sh`:

flowchart TD
    Start([Start])
    CurlReq["Send HTTP GET request to\nhttp://localhost:5052/eth/v1/node/syncing"]
    CurlFail{"Request Success?"}
    ParseSync["Parse JSON response:\n.data.is_syncing"]
    IsSyncing{"Is .data.is_syncing == false?"}
    Synced["Print 'daemon-beacon is synced'\nExit with code 0"]
    Syncing["Print 'daemon-beacon is still syncing'\nExit with code 1"]
    CurlFailNo["Exit with code 1"]

    Start --> CurlReq
    CurlReq --> CurlFail
    CurlFail -- No --> CurlFailNo
    CurlFail -- Yes --> ParseSync
    ParseSync --> IsSyncing
    IsSyncing -- Yes --> Synced
    IsSyncing -- No --> Syncing

Summary