evm.sh


Overview

[evm.sh](/projects/291/69100) is a Bash script utility designed to assist in Ethereum blockchain node synchronization validation. Its primary purpose is to compare the latest block numbers reported by multiple reference Ethereum nodes (via JSON-RPC calls) and determine the "best" or highest block number among them. Additionally, it validates whether a given service's current block height is synchronized within a specified tolerance relative to this best reference block number.

This script is useful in blockchain environments where multiple nodes or services need to be monitored for sync status against reliable reference nodes to ensure data consistency and network health.


Functions

1. get_best_reference_block_number()

Purpose

Queries multiple Ethereum JSON-RPC endpoints to fetch their latest block numbers (`eth_blockNumber`) and returns the highest block number found among them.

Parameters

Behavior

Return Value

Usage Example

best_block=$(get_best_reference_block_number "http://node1:8545" "http://node2:8545")
echo "Highest block among references: $best_block"

2. reference_validation()

Purpose

Validates if a given service/node's current block number is synchronized within an acceptable block height tolerance relative to the best reference block number.

Parameters

Parameter Name

Description

Type

`service`

Name or identifier of the service/node being validated

String

`current_block_number`

The current block number the service/node reports

Integer

`best_reference_block_number`

The highest block number from reference nodes

Integer

`block_height_tolerance`

Allowed difference (tolerance) in block numbers

Integer

Behavior

Return Value

Usage Example

reference_validation "my-eth-node" 1234567 1234570 5
# Output: my-eth-node is synced within block height tolerance of reference node

Implementation Details and Algorithms


Interaction with Other Parts of the System


Visual Diagram

flowchart TD
    A[Start: Input Ethereum JSON-RPC URLs] --> B[get_best_reference_block_number]
    B --> C{For each URL}
    C -->|Send JSON-RPC eth_blockNumber| D[curl POST Request]
    D --> E[Parse JSON response with jq]
    E --> F[Extract and convert block number to decimal]
    F --> G{Is current block number > best_reference_block_number?}
    G -- Yes --> H[Update best_reference_block_number]
    G -- No --> I[Keep current best_reference_block_number]
    H --> C
    I --> C
    C --> J[Return best_reference_block_number]

    J --> K[reference_validation]
    K --> L[Calculate nominal_block_number = best_reference_block_number - tolerance]
    L --> M{Is current_block_number >= nominal_block_number?}
    M -- Yes --> N[Print synced within tolerance; Exit 0]
    M -- No --> O[Print synced but outside tolerance; Exit 1]

Summary

The [evm.sh](/projects/291/69100) script is a lightweight and effective tool for Ethereum node synchronization validation purposes. It leverages standard CLI tools (`curl`, `jq`) to communicate with Ethereum nodes and perform block height comparisons, providing clear feedback on synchronization status relative to reference nodes. This makes it valuable for operational monitoring and ensuring Ethereum infrastructure reliability.