Skip to content

Conversation

@Cordtus
Copy link

@Cordtus Cordtus commented Dec 5, 2025

Description

Ref: #15463

This PR extends the GetSyncingResponse in cosmos.base.tendermint.v1beta1.Service to include block height information that is essential for indexers and tooling.

Problem

Indexers need to know which blocks are available on a node before attempting to fetch them. Currently, this information is only available via CometBFT's /status RPC endpoint (sync_info.earliest_block_height), requiring clients to query two different endpoints.

When an indexer tries to fetch a pruned block, it gets an error like:

height 60 is not available, lowest height is 28566001

Discovering available block heights proactively via gRPC would be more efficient.

Solution

Add two new fields to GetSyncingResponse:

  • earliest_block_height - The earliest block height available on this node
  • latest_block_height - The latest block height available on this node

These fields expose the same information as CometBFT's SyncInfo struct, making it available via the existing gRPC endpoint without requiring a separate RPC call.

Changes

File Change
proto/cosmos/base/tendermint/v1beta1/query.proto Add new fields to GetSyncingResponse
client/grpc/cmtservice/query.pb.go Generated code with new fields
client/grpc/cmtservice/service.go Populate new fields from SyncInfo
tests/systemtests/cometbft_service_test.go Add systemtest with pruning verification

API

message GetSyncingResponse {
  bool syncing = 1;
  int64 earliest_block_height = 2;  // NEW
  int64 latest_block_height = 3;    // NEW
}

Testing

Systemtest added (TestCometBFTGetSyncingGRPC and TestCometBFTGetSyncingWithBlockRetention) that:

  1. Verifies gRPC endpoint returns valid block heights
  2. Confirms latest_block_height increases over time
  3. Confirms earliest_block_height is stable on unpruned chains
  4. Verifies pruning behavior: Configures min-retain-blocks=5 and max_age_num_blocks=5 (in genesis), then confirms earliest_block_height increases as blocks are pruned

The pruning test required modifying both app.toml (via EditToml) and genesis params (via ModifyGenesisJSON) because CometBFT's block retention is the minimum of min-retain-blocks and max_age_num_blocks. Default max_age_num_blocks=100000 would prevent pruning in tests.

=== RUN   TestCometBFTGetSyncingWithBlockRetention
    Initial state: earliest=1, latest=5
    Waiting for 15 blocks to trigger block pruning (minRetainBlocks=5)...
    After 15 blocks: earliest=15, latest=20
    Block range: 5 (latest 20 - earliest 15)
--- PASS: TestCometBFTGetSyncingWithBlockRetention (56.35s)

Backward Compatibility

This is a non-breaking change - it only adds new optional fields to an existing response message. Existing clients will continue to work unchanged.

Use Case

// Before: Need to query CometBFT RPC separately
status, _ := rpcClient.Status(ctx)
earliest := status.SyncInfo.EarliestBlockHeight

// After: Available via gRPC
resp, _ := cmtClient.GetSyncing(ctx, &GetSyncingRequest{})
earliest := resp.EarliestBlockHeight

@github-actions github-actions bot added the C:CLI label Dec 5, 2025
@Cordtus Cordtus marked this pull request as draft December 5, 2025 18:45
@Cordtus Cordtus force-pushed the feat/earliest-block-height-grpc branch from c24cdcc to b6db48e Compare December 5, 2025 18:45
Extend the GetSyncingResponse in cosmos.base.tendermint.v1beta1.Service
to include earliest_block_height and latest_block_height fields.

This enables gRPC clients (like indexers) to discover block availability
without needing to query the CometBFT RPC separately. The fields expose
the same information as the /status RPC endpoint's sync_info.

Changes:
- Add earliest_block_height field to GetSyncingResponse proto
- Add latest_block_height field to GetSyncingResponse proto
- Update service implementation to populate new fields from SyncInfo
@Cordtus Cordtus force-pushed the feat/earliest-block-height-grpc branch from b6db48e to dc48552 Compare December 6, 2025 00:11
@Cordtus Cordtus marked this pull request as ready for review December 6, 2025 00:12
@fmorency
Copy link
Contributor

fmorency commented Dec 8, 2025

This would be useful for manifest-network/yaci#28

@codecov
Copy link

codecov bot commented Dec 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.43%. Comparing base (18e85de) to head (117246f).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #25648      +/-   ##
==========================================
+ Coverage   70.40%   70.43%   +0.03%     
==========================================
  Files         830      830              
  Lines       54050    54052       +2     
==========================================
+ Hits        38052    38070      +18     
+ Misses      15998    15982      -16     
Files with missing lines Coverage Δ
client/grpc/cmtservice/service.go 84.05% <100.00%> (+0.23%) ⬆️

... and 2 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

aljo242 and others added 5 commits December 8, 2025 15:06
…5659)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: aljo242 <[email protected]>
Add systemtest coverage for the GetSyncing gRPC endpoint to verify
earliest_block_height and latest_block_height fields work correctly.

Tests include:
- Basic gRPC connectivity and field validation
- latest_block_height increases over time
- earliest_block_height stable on unpruned chain
- Block pruning scenario: configures min-retain-blocks=5 and
  max_age_num_blocks=5 in genesis to trigger actual pruning,
  verifying earliest_block_height increases as blocks are pruned
@Cordtus
Copy link
Author

Cordtus commented Dec 10, 2025

Added a systemtest. Run with:

cd tests/systemtests && go test -tags='system_test' -v --run 'TestCometBFT' --wait-time=120s --nodes-count=1

The pruning test configures min-retain-blocks=5 in app.toml and max_age_num_blocks=5 in genesis (Comet block retention uses the minimum of both), waits 15 blocks, then confirms earliest_block_height increases from 1 to 15 as blocks get pruned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants