Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tendermint-rpc): add earliest block to sync info #1449

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to

## [Unreleased]

### Fixed

- @cosmjs/tendermint-rpc: Add missing `earliest_*` fields to `SyncInfo` record
returned from the `/status` RPC endpoint ([#1448]).

## [0.31.0] - 2023-06-22

### Fixed
Expand Down
19 changes: 18 additions & 1 deletion packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,12 @@ function decodeNodeInfo(data: RpcNodeInfo): responses.NodeInfo {
}

interface RpcSyncInfo {
/** hex encoded */
readonly earliest_app_hash: string;
/** hex encoded */
readonly earliest_block_hash: string;
readonly earliest_block_height: string;
readonly earliest_block_time: string;
/** hex encoded */
readonly latest_block_hash: string;
/** hex encoded */
Expand All @@ -629,7 +635,18 @@ interface RpcSyncInfo {
}

function decodeSyncInfo(data: RpcSyncInfo): responses.SyncInfo {
return {
const earliestBlockHeight = data.earliest_block_height
? apiToSmallInt(data.earliest_block_height)
: undefined;
const earliestBlockTime = data.earliest_block_time
? fromRfc3339WithNanoseconds(data.earliest_block_time)
: undefined;

return {
earliestAppHash: data.earliest_app_hash ? fromHex(data.earliest_app_hash) : undefined,
earliestBlockHash: data.earliest_block_hash ? fromHex(data.earliest_block_hash) : undefined,
earliestBlockHeight: earliestBlockHeight || undefined,
earliestBlockTime: earliestBlockTime?.getTime() ? earliestBlockTime : undefined,
latestBlockHash: fromHex(assertNotEmpty(data.latest_block_hash)),
latestAppHash: fromHex(assertNotEmpty(data.latest_app_hash)),
latestBlockTime: fromRfc3339WithNanoseconds(assertNotEmpty(data.latest_block_time)),
Expand Down
4 changes: 4 additions & 0 deletions packages/tendermint-rpc/src/tendermint34/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ export interface NodeInfo {
}

export interface SyncInfo {
readonly earliestAppHash?: Uint8Array;
readonly earliestBlockHash?: Uint8Array;
readonly earliestBlockHeight?: number;
readonly earliestBlockTime?: ReadonlyDate;
readonly latestBlockHash: Uint8Array;
readonly latestAppHash: Uint8Array;
readonly latestBlockHeight: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,17 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
// sync info
expect(status.syncInfo.catchingUp).toEqual(false);
expect(status.syncInfo.latestBlockHeight).toBeGreaterThanOrEqual(1);
expect(status.syncInfo.latestBlockTime).toBeInstanceOf(Date);
if (status.syncInfo.earliestBlockHeight) {
expect(status.syncInfo.earliestBlockHeight).toBeGreaterThanOrEqual(1);
expect(status.syncInfo.earliestBlockHeight).toBeLessThanOrEqual(status.syncInfo.latestBlockHeight);
}
if (status.syncInfo.earliestBlockTime) {
expect(status.syncInfo.earliestBlockTime).toBeInstanceOf(Date);
expect(status.syncInfo.earliestBlockTime.getTime()).toBeLessThanOrEqual(
status.syncInfo.latestBlockTime.getTime(),
);
}

// validator info
expect(status.validatorInfo.pubkey).toBeTruthy();
Expand Down
19 changes: 18 additions & 1 deletion packages/tendermint-rpc/src/tendermint37/adaptor/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,12 @@ function decodeNodeInfo(data: RpcNodeInfo): responses.NodeInfo {
}

interface RpcSyncInfo {
/** hex encoded */
readonly earliest_app_hash: string;
/** hex encoded */
readonly earliest_block_hash: string;
readonly earliest_block_height: string;
readonly earliest_block_time: string;
/** hex encoded */
readonly latest_block_hash: string;
/** hex encoded */
Expand All @@ -630,7 +636,18 @@ interface RpcSyncInfo {
}

function decodeSyncInfo(data: RpcSyncInfo): responses.SyncInfo {
return {
const earliestBlockHeight = data.earliest_block_height
? apiToSmallInt(data.earliest_block_height)
: undefined;
const earliestBlockTime = data.earliest_block_time
? fromRfc3339WithNanoseconds(data.earliest_block_time)
: undefined;

return {
earliestAppHash: data.earliest_app_hash ? fromHex(data.earliest_app_hash) : undefined,
earliestBlockHash: data.earliest_block_hash ? fromHex(data.earliest_block_hash) : undefined,
earliestBlockHeight: earliestBlockHeight || undefined,
earliestBlockTime: earliestBlockTime?.getTime() ? earliestBlockTime : undefined,
latestBlockHash: fromHex(assertNotEmpty(data.latest_block_hash)),
latestAppHash: fromHex(assertNotEmpty(data.latest_app_hash)),
latestBlockTime: fromRfc3339WithNanoseconds(assertNotEmpty(data.latest_block_time)),
Expand Down
4 changes: 4 additions & 0 deletions packages/tendermint-rpc/src/tendermint37/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ export interface NodeInfo {
}

export interface SyncInfo {
readonly earliestAppHash?: Uint8Array;
readonly earliestBlockHash?: Uint8Array;
readonly earliestBlockHeight?: number;
readonly earliestBlockTime?: ReadonlyDate;
readonly latestBlockHash: Uint8Array;
readonly latestAppHash: Uint8Array;
readonly latestBlockHeight: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,17 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
// sync info
expect(status.syncInfo.catchingUp).toEqual(false);
expect(status.syncInfo.latestBlockHeight).toBeGreaterThanOrEqual(1);
expect(status.syncInfo.latestBlockTime).toBeInstanceOf(Date);
if (status.syncInfo.earliestBlockHeight) {
expect(status.syncInfo.earliestBlockHeight).toBeGreaterThanOrEqual(1);
expect(status.syncInfo.earliestBlockHeight).toBeLessThanOrEqual(status.syncInfo.latestBlockHeight);
}
if (status.syncInfo.earliestBlockTime) {
expect(status.syncInfo.earliestBlockTime).toBeInstanceOf(Date);
expect(status.syncInfo.earliestBlockTime.getTime()).toBeLessThanOrEqual(
status.syncInfo.latestBlockTime.getTime(),
);
}

// validator info
expect(status.validatorInfo.pubkey).toBeTruthy();
Expand Down