tendermint.sh


Overview

`tendermint.sh` is a Bash utility script designed to assist in monitoring and validating the synchronization status of a Tendermint-based blockchain daemon relative to a set of reference nodes. Its primary purpose is to query multiple reference nodes for their latest block heights, determine the best (highest) block height among them, and validate whether the local daemon is sufficiently synced within a configurable tolerance.

This script facilitates automated health checks or monitoring workflows by providing key functions that interact with Tendermint nodes’ REST API endpoints (typically exposed on `/status`) and process their JSON status responses.


Detailed Description of Functions

1. get_best_reference_block_height

**Purpose:** Fetches the latest block height from multiple reference Tendermint node URLs and returns the highest block height found.

**Signature:**

get_best_reference_block_height <reference_node_url_1> [<reference_node_url_2> ...]

**Parameters:**

**Returns:**

**Implementation Details:**

**Usage Example:**

best_height=$(get_best_reference_block_height http://node1:26657 http://node2:26657)
echo "Best reference block height is $best_height"

2. get_best_reference_block_height_eval

**Purpose:** Similar to `get_best_reference_block_height`, but instead of URLs, it accepts shell commands (typically `curl` commands) as arguments, evaluates them, and extracts the best block height from their outputs.

**Signature:**

get_best_reference_block_height_eval <status_curl_command_1> [<status_curl_command_2> ...]

**Parameters:**

**Returns:**

**Implementation Details:**

**Usage Example:**

best_height=$(get_best_reference_block_height_eval "curl -sf -m 3 http://node1:26657/status" "curl -sf -m 3 http://node2:26657/status")
echo "Best reference block height via eval is $best_height"

3. reference_validation

**Purpose:** Validates whether a local Tendermint daemon’s block height is sufficiently synced compared to the best reference block height, considering a tolerance value.

**Signature:**

reference_validation <latest_block_height> <best_reference_block_height> <block_height_tolerance>

**Parameters:**

**Returns:**

**Implementation Details:**

**Usage Example:**

reference_validation 12345 12350 5

Output:

daemon is synced and within block height tolerance of reference node

or

daemon is synced, but not within block height tolerance of reference node

Important Implementation Details


Interaction with Other System Components


Visual Diagram: Flowchart of Main Functions and Workflow

flowchart TD
    Start["Start"]
    GetBestRefBLH[get_best_reference_block_height()]
    GetBestRefBLHEval[get_best_reference_block_height_eval()]
    ReferenceValidation[reference_validation()]
    OutputBestHeight["Output best block height"]
    EvalCmds["Evaluate shell commands"]
    CurlStatus["Curl /status for each reference URL"]
    ParseJSON["Parse JSON for latest_block_height"]
    CompareHeights["Compare & store max block height"]
    CalculateNominal["Calculate nominal_block_height = best - tolerance"]
    CheckSync["Check if local height >= nominal"]
    ExitSuccess["Exit 0 (synced & within tolerance)"]
    ExitWarning["Exit 1 (synced but outside tolerance)"]

    Start --> GetBestRefBLH --> CurlStatus --> ParseJSON --> CompareHeights --> OutputBestHeight
    Start --> GetBestRefBLHEval --> EvalCmds --> ParseJSON --> CompareHeights --> OutputBestHeight
    OutputBestHeight --> ReferenceValidation --> CalculateNominal --> CheckSync
    CheckSync -- Yes --> ExitSuccess
    CheckSync -- No --> ExitWarning

Summary

The `tendermint.sh` script provides essential utilities for assessing the sync state of a Tendermint daemon by querying multiple reference nodes. Its functions enable robust, automated detection of synchronization status while considering tolerance thresholds, making it a valuable tool in blockchain node operations and monitoring toolchains.