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

Use forked version of tendermint-rpc for finalize block events #291

Merged
merged 2 commits into from
Oct 21, 2024
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
2 changes: 2 additions & 0 deletions packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- Use tendermint-rpc fork to allow support for finalizeBlockEvents (#291)

## [4.1.2] - 2024-09-25
### Fixed
Expand Down
1 change: 1 addition & 0 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@cosmjs/cosmwasm-stargate": "^0.32.4",
"@cosmjs/proto-signing": "^0.32.4",
"@cosmjs/stargate": "^0.32.4",
"@cosmjs/tendermint-rpc": "npm:@subql/[email protected]",
"@kyvejs/sdk": "^1.3.2",
"@nestjs/common": "^9.4.0",
"@nestjs/core": "^9.4.0",
Expand Down
8 changes: 6 additions & 2 deletions packages/node/src/indexer/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ export class CosmosClient extends CosmWasmClient {
private readonly _cometClient: CometClient,
public registry: Registry,
) {
super(_cometClient);
// Types have diverged with our fork of tendermint-rpc
// eslint-disable-next-line @typescript-eslint/no-explicit-any
super(_cometClient as any);
}

// eslint-disable-next-line @typescript-eslint/require-await
Expand Down Expand Up @@ -245,7 +247,9 @@ export class CosmosSafeClient
height: number;

constructor(cometClient: CometClient, height: number) {
super(cometClient);
// Types have diverged with our fork of tendermint-rpc
// eslint-disable-next-line @typescript-eslint/no-explicit-any
super(cometClient as any);
this.height = height;
}

Expand Down
4 changes: 4 additions & 0 deletions packages/node/src/indexer/indexer.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ export class IndexerManager extends BaseIndexerManager<
for (const evt of blockContent.endBlockEvents ?? []) {
await this.indexEvent(evt, dataSources, getVM);
}

for (const evt of blockContent.finalizeBlockEvents ?? []) {
await this.indexEvent(evt, dataSources, getVM);
}
}

private async indexBlockContent(
Expand Down
4 changes: 4 additions & 0 deletions packages/node/src/indexer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ export interface BlockContent {
transactions: CosmosTransaction[];
messages: CosmosMessage[];
events: CosmosEvent[];
// Tendermint34,37
beginBlockEvents?: CosmosEvent[];
endBlockEvents?: CosmosEvent[];

// Comet38
finalizeBlockEvents?: CosmosEvent[];
}

export type BestBlocks = Record<number, string>;
7 changes: 3 additions & 4 deletions packages/node/src/utils/cosmos.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,10 @@ describe('Cosmos 0.50 support', () => {
expect(status.nodeInfo.version).toMatch('0.38.');
});

// TODO requires these changes https://github.com/cosmos/cosmjs/compare/main...bryanchriswhite:cosmjs:main
it('correctly has finalized block events instead of being/end block events', () => {
// Its not yet defined if cosmjs will split finalizedBlockEvents to these to fields or define finalizedBlockEvents
expect(block.beginBlockEvents).toBeDefined();
expect(block.endBlockEvents).toBeDefined();
expect(block.beginBlockEvents?.length).toEqual(0);
expect(block.endBlockEvents?.length).toEqual(0);
expect(block.finalizeBlockEvents?.length).toBeGreaterThan(0);
});

it('correctly parses events', () => {
Expand Down
45 changes: 42 additions & 3 deletions packages/node/src/utils/cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import { toHex } from '@cosmjs/encoding';
import { DecodeObject, decodeTxRaw, Registry } from '@cosmjs/proto-signing';
import { fromTendermintEvent } from '@cosmjs/stargate';
import { Log, parseRawLog } from '@cosmjs/stargate/build/logs';
import { toRfc3339WithNanoseconds } from '@cosmjs/tendermint-rpc';
import {
toRfc3339WithNanoseconds,
tendermint34,
tendermint37,
comet38,
} from '@cosmjs/tendermint-rpc';

import {
IBlock,
getLogger,
Expand Down Expand Up @@ -494,6 +500,7 @@ export class LazyBlockContent implements BlockContent {
private _wrappedEvent?: CosmosEvent[];
private _wrappedBeginBlockEvents?: CosmosEvent[];
private _wrappedEndBlockEvents?: CosmosEvent[];
private _wrappedFinalizedBlockEvents?: CosmosEvent[];
private _eventIdx = 0; //To maintain a valid count over begin block events, tx events and end block events

constructor(
Expand Down Expand Up @@ -543,10 +550,17 @@ export class LazyBlockContent implements BlockContent {
}

get beginBlockEvents(): CosmosEvent[] {
const results = this._results as
| tendermint34.BlockResultsResponse
| tendermint37.BlockResultsResponse;
if (!results.beginBlockEvents?.length) {
return [];
}

if (!this._wrappedBeginBlockEvents) {
this._wrappedBeginBlockEvents = wrapBlockBeginAndEndEvents(
this.block,
[...this._results.beginBlockEvents],
[...results.beginBlockEvents],
this._eventIdx,
);
this._eventIdx += this._wrappedBeginBlockEvents.length;
Expand All @@ -556,17 +570,42 @@ export class LazyBlockContent implements BlockContent {
}

get endBlockEvents(): CosmosEvent[] {
const results = this._results as
| tendermint34.BlockResultsResponse
| tendermint37.BlockResultsResponse;
if (!results.endBlockEvents?.length) {
return [];
}

if (!this._wrappedEndBlockEvents) {
this._wrappedEndBlockEvents = wrapBlockBeginAndEndEvents(
this.block,
[...this._results.endBlockEvents],
[...results.endBlockEvents],
this._eventIdx,
);
this._eventIdx += this._wrappedEndBlockEvents.length;
}

return this._wrappedEndBlockEvents;
}

get finalizeBlockEvents(): CosmosEvent[] {
const results = this._results as comet38.BlockResultsResponse;
if (!results.finalizeBlockEvents?.length) {
return [];
}

if (!this._wrappedFinalizedBlockEvents) {
this._wrappedFinalizedBlockEvents = wrapBlockBeginAndEndEvents(
this.block,
[...results.finalizeBlockEvents],
this._eventIdx,
);
this._eventIdx += this._wrappedFinalizedBlockEvents.length;
}

return this._wrappedFinalizedBlockEvents;
}
}

export function calcInterval(api: CosmosClient): number {
Expand Down
121 changes: 70 additions & 51 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2298,6 +2298,21 @@ __metadata:
languageName: node
linkType: hard

"@cosmjs/crypto@npm:0.32.4, @cosmjs/crypto@npm:^0.32.4":
version: 0.32.4
resolution: "@cosmjs/crypto@npm:0.32.4"
dependencies:
"@cosmjs/encoding": ^0.32.4
"@cosmjs/math": ^0.32.4
"@cosmjs/utils": ^0.32.4
"@noble/hashes": ^1
bn.js: ^5.2.0
elliptic: ^6.5.4
libsodium-wrappers-sumo: ^0.7.11
checksum: 432313296350c070936af9516249a7c96c3c057242ab4a8ca261fcf12a5cfddf151d8b84dabec324e0d51e01643b0d92b798ab652ad4ec16321b691e875c93b3
languageName: node
linkType: hard

"@cosmjs/crypto@npm:^0.32.3":
version: 0.32.3
resolution: "@cosmjs/crypto@npm:0.32.3"
Expand All @@ -2313,18 +2328,14 @@ __metadata:
languageName: node
linkType: hard

"@cosmjs/crypto@npm:^0.32.4":
"@cosmjs/encoding@npm:0.32.4, @cosmjs/encoding@npm:^0.32.4":
version: 0.32.4
resolution: "@cosmjs/crypto@npm:0.32.4"
resolution: "@cosmjs/encoding@npm:0.32.4"
dependencies:
"@cosmjs/encoding": ^0.32.4
"@cosmjs/math": ^0.32.4
"@cosmjs/utils": ^0.32.4
"@noble/hashes": ^1
bn.js: ^5.2.0
elliptic: ^6.5.4
libsodium-wrappers-sumo: ^0.7.11
checksum: 432313296350c070936af9516249a7c96c3c057242ab4a8ca261fcf12a5cfddf151d8b84dabec324e0d51e01643b0d92b798ab652ad4ec16321b691e875c93b3
base64-js: ^1.3.0
bech32: ^1.1.4
readonly-date: ^1.0.0
checksum: 9a2a1d87b7fe3fa7ad05a0b049b783b5b08ccfd61ed5bb3a1a37e0ae93a0ad9bc8c6701b1d3112e7c154b2dd48a0c221263a39a4d6878a495dc59ac5eeef6ec2
languageName: node
linkType: hard

Expand All @@ -2339,14 +2350,13 @@ __metadata:
languageName: node
linkType: hard

"@cosmjs/encoding@npm:^0.32.4":
"@cosmjs/json-rpc@npm:0.32.4, @cosmjs/json-rpc@npm:^0.32.4":
version: 0.32.4
resolution: "@cosmjs/encoding@npm:0.32.4"
resolution: "@cosmjs/json-rpc@npm:0.32.4"
dependencies:
base64-js: ^1.3.0
bech32: ^1.1.4
readonly-date: ^1.0.0
checksum: 9a2a1d87b7fe3fa7ad05a0b049b783b5b08ccfd61ed5bb3a1a37e0ae93a0ad9bc8c6701b1d3112e7c154b2dd48a0c221263a39a4d6878a495dc59ac5eeef6ec2
"@cosmjs/stream": ^0.32.4
xstream: ^11.14.0
checksum: 5153d7fbccd7073679d138e351fe02395602346717d34d8bdd761797afa71bc395e82bc6cec797ffdc13aceeab8f508c75a9dd6b15314c1cb8a9757239978d62
languageName: node
linkType: hard

Expand All @@ -2360,13 +2370,12 @@ __metadata:
languageName: node
linkType: hard

"@cosmjs/json-rpc@npm:^0.32.4":
"@cosmjs/math@npm:0.32.4, @cosmjs/math@npm:^0.32.4":
version: 0.32.4
resolution: "@cosmjs/json-rpc@npm:0.32.4"
resolution: "@cosmjs/math@npm:0.32.4"
dependencies:
"@cosmjs/stream": ^0.32.4
xstream: ^11.14.0
checksum: 5153d7fbccd7073679d138e351fe02395602346717d34d8bdd761797afa71bc395e82bc6cec797ffdc13aceeab8f508c75a9dd6b15314c1cb8a9757239978d62
bn.js: ^5.2.0
checksum: 1269ad0c33a78b05c9f7c1bc7a7222d3b4504263ade3a15b07f95eb18c2620c96e4c79beeab66d7053294828b32cf04d0cc5a71610f755e1d1da06b04d462043
languageName: node
linkType: hard

Expand All @@ -2379,15 +2388,6 @@ __metadata:
languageName: node
linkType: hard

"@cosmjs/math@npm:^0.32.4":
version: 0.32.4
resolution: "@cosmjs/math@npm:0.32.4"
dependencies:
bn.js: ^5.2.0
checksum: 1269ad0c33a78b05c9f7c1bc7a7222d3b4504263ade3a15b07f95eb18c2620c96e4c79beeab66d7053294828b32cf04d0cc5a71610f755e1d1da06b04d462043
languageName: node
linkType: hard

"@cosmjs/proto-signing@npm:^0.32.3":
version: 0.32.3
resolution: "@cosmjs/proto-signing@npm:0.32.3"
Expand Down Expand Up @@ -2416,27 +2416,27 @@ __metadata:
languageName: node
linkType: hard

"@cosmjs/socket@npm:^0.32.3":
version: 0.32.3
resolution: "@cosmjs/socket@npm:0.32.3"
"@cosmjs/socket@npm:0.32.4, @cosmjs/socket@npm:^0.32.4":
version: 0.32.4
resolution: "@cosmjs/socket@npm:0.32.4"
dependencies:
"@cosmjs/stream": ^0.32.3
"@cosmjs/stream": ^0.32.4
isomorphic-ws: ^4.0.1
ws: ^7
xstream: ^11.14.0
checksum: 9e695a21b81c7987999c1452f18a341428ad01cda65b392386440d26589c2b53af81954c36156c5be88ddd97982c20db2fb938b4349a04f18f05b65547796556
checksum: 26125bbf261d5d77bec3c5340a9c60c1e512bee747984b3333521491aa4f4d2a3e2cba7f1e412013b38835eff875066e645d86f752d7936f19f9eae18b9d97e5
languageName: node
linkType: hard

"@cosmjs/socket@npm:^0.32.4":
version: 0.32.4
resolution: "@cosmjs/socket@npm:0.32.4"
"@cosmjs/socket@npm:^0.32.3":
version: 0.32.3
resolution: "@cosmjs/socket@npm:0.32.3"
dependencies:
"@cosmjs/stream": ^0.32.4
"@cosmjs/stream": ^0.32.3
isomorphic-ws: ^4.0.1
ws: ^7
xstream: ^11.14.0
checksum: 26125bbf261d5d77bec3c5340a9c60c1e512bee747984b3333521491aa4f4d2a3e2cba7f1e412013b38835eff875066e645d86f752d7936f19f9eae18b9d97e5
checksum: 9e695a21b81c7987999c1452f18a341428ad01cda65b392386440d26589c2b53af81954c36156c5be88ddd97982c20db2fb938b4349a04f18f05b65547796556
languageName: node
linkType: hard

Expand Down Expand Up @@ -2476,6 +2476,15 @@ __metadata:
languageName: node
linkType: hard

"@cosmjs/stream@npm:0.32.4, @cosmjs/stream@npm:^0.32.4":
version: 0.32.4
resolution: "@cosmjs/stream@npm:0.32.4"
dependencies:
xstream: ^11.14.0
checksum: fa55d3f29e8a7c56d5da4128989709f0b02fcee5319efa2504f62e4f2b0c64725ccb603d88f435f6fbe308dc6ef76b1fd3ea5aecfcb877a871c111366ddd3489
languageName: node
linkType: hard

"@cosmjs/stream@npm:^0.32.3":
version: 0.32.3
resolution: "@cosmjs/stream@npm:0.32.3"
Expand All @@ -2485,12 +2494,21 @@ __metadata:
languageName: node
linkType: hard

"@cosmjs/stream@npm:^0.32.4":
"@cosmjs/tendermint-rpc@npm:@subql/x-cosmos-tendermint-rpc@0.32.4":
version: 0.32.4
resolution: "@cosmjs/stream@npm:0.32.4"
dependencies:
resolution: "@subql/x-cosmos-tendermint-rpc@npm:0.32.4"
dependencies:
"@cosmjs/crypto": 0.32.4
"@cosmjs/encoding": 0.32.4
"@cosmjs/json-rpc": 0.32.4
"@cosmjs/math": 0.32.4
"@cosmjs/socket": 0.32.4
"@cosmjs/stream": 0.32.4
"@cosmjs/utils": 0.32.4
axios: ^1.6.0
readonly-date: ^1.0.0
xstream: ^11.14.0
checksum: fa55d3f29e8a7c56d5da4128989709f0b02fcee5319efa2504f62e4f2b0c64725ccb603d88f435f6fbe308dc6ef76b1fd3ea5aecfcb877a871c111366ddd3489
checksum: f98853e8a38690921adef946cf6bfd35a6ed9906c353700a24a85631c387961d7a2ad93b437a4c95d56d4452b50161075814fc353bd72a29f85bae154c6ff4f7
languageName: node
linkType: hard

Expand Down Expand Up @@ -2530,20 +2548,20 @@ __metadata:
languageName: node
linkType: hard

"@cosmjs/utils@npm:0.32.4, @cosmjs/utils@npm:^0.32.4":
version: 0.32.4
resolution: "@cosmjs/utils@npm:0.32.4"
checksum: 92f4d0878bedda53d113894ebadd31a6d189fdd45f2f884049ee99c2d7f907703b6dc40c8bc9b88b912443c38f3dbf77a9474183f41b85dec1f9ef3bec9d86c4
languageName: node
linkType: hard

"@cosmjs/utils@npm:^0.32.3":
version: 0.32.3
resolution: "@cosmjs/utils@npm:0.32.3"
checksum: ef2c101f18b3d134d638f145349130b0ef223b504e53c833180326877b394be757790b5dc8dfc88105dd8cf3b0c293c140432bd1540c4ae935799f654aeee27f
languageName: node
linkType: hard

"@cosmjs/utils@npm:^0.32.4":
version: 0.32.4
resolution: "@cosmjs/utils@npm:0.32.4"
checksum: 92f4d0878bedda53d113894ebadd31a6d189fdd45f2f884049ee99c2d7f907703b6dc40c8bc9b88b912443c38f3dbf77a9474183f41b85dec1f9ef3bec9d86c4
languageName: node
linkType: hard

"@cosmology/protobufjs@npm:6.11.6":
version: 6.11.6
resolution: "@cosmology/protobufjs@npm:6.11.6"
Expand Down Expand Up @@ -4254,6 +4272,7 @@ __metadata:
"@cosmjs/cosmwasm-stargate": ^0.32.4
"@cosmjs/proto-signing": ^0.32.4
"@cosmjs/stargate": ^0.32.4
"@cosmjs/tendermint-rpc": "npm:@subql/[email protected]"
"@kyvejs/sdk": ^1.3.2
"@nestjs/common": ^9.4.0
"@nestjs/core": ^9.4.0
Expand Down
Loading