Skip to content

Commit b6db48e

Browse files
committed
feat(grpc): add earliest/latest block height to GetSyncing response
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
1 parent 18e85de commit b6db48e

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

client/grpc/cmtservice/query.pb.go

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/grpc/cmtservice/service.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ func (s queryServer) GetSyncing(ctx context.Context, _ *GetSyncingRequest) (*Get
5555
}
5656

5757
return &GetSyncingResponse{
58-
Syncing: status.SyncInfo.CatchingUp,
58+
Syncing: status.SyncInfo.CatchingUp,
59+
EarliestBlockHeight: status.SyncInfo.EarliestBlockHeight,
60+
LatestBlockHeight: status.SyncInfo.LatestBlockHeight,
5961
}, nil
6062
}
6163

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package cmtservice
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
)
8+
9+
func TestGetSyncingResponseFields(t *testing.T) {
10+
// Verify the struct has the expected fields
11+
resp := &GetSyncingResponse{
12+
Syncing: true,
13+
EarliestBlockHeight: 1000,
14+
LatestBlockHeight: 2000,
15+
}
16+
17+
require.True(t, resp.GetSyncing())
18+
require.Equal(t, int64(1000), resp.GetEarliestBlockHeight())
19+
require.Equal(t, int64(2000), resp.GetLatestBlockHeight())
20+
}
21+
22+
func TestGetSyncingResponseDefaults(t *testing.T) {
23+
// Verify zero values work correctly
24+
resp := &GetSyncingResponse{}
25+
26+
require.False(t, resp.GetSyncing())
27+
require.Equal(t, int64(0), resp.GetEarliestBlockHeight())
28+
require.Equal(t, int64(0), resp.GetLatestBlockHeight())
29+
}
30+
31+
func TestGetSyncingResponseNil(t *testing.T) {
32+
// Verify nil receiver doesn't panic
33+
var resp *GetSyncingResponse
34+
35+
require.False(t, resp.GetSyncing())
36+
require.Equal(t, int64(0), resp.GetEarliestBlockHeight())
37+
require.Equal(t, int64(0), resp.GetLatestBlockHeight())
38+
}

proto/cosmos/base/tendermint/v1beta1/query.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ message GetSyncingRequest {}
126126
// GetSyncingResponse is the response type for the Query/GetSyncing RPC method.
127127
message GetSyncingResponse {
128128
bool syncing = 1;
129+
// earliest_block_height is the earliest block height available on this node.
130+
int64 earliest_block_height = 2;
131+
// latest_block_height is the latest block height available on this node.
132+
int64 latest_block_height = 3;
129133
}
130134

131135
// GetNodeInfoRequest is the request type for the Query/GetNodeInfo RPC method.

0 commit comments

Comments
 (0)