Skip to content

Commit 662a5ab

Browse files
authored
Use forked version of tendermint-rpc for finalize block events (#291)
* Use forked version of tendermint-rpc for finalize block events * Update changelog
1 parent 19558a5 commit 662a5ab

File tree

8 files changed

+132
-60
lines changed

8 files changed

+132
-60
lines changed

packages/node/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Changed
9+
- Use tendermint-rpc fork to allow support for finalizeBlockEvents (#291)
810

911
## [4.1.2] - 2024-09-25
1012
### Fixed

packages/node/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"@cosmjs/cosmwasm-stargate": "^0.32.4",
2323
"@cosmjs/proto-signing": "^0.32.4",
2424
"@cosmjs/stargate": "^0.32.4",
25+
"@cosmjs/tendermint-rpc": "npm:@subql/[email protected]",
2526
"@kyvejs/sdk": "^1.3.2",
2627
"@nestjs/common": "^9.4.0",
2728
"@nestjs/core": "^9.4.0",

packages/node/src/indexer/api.service.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ export class CosmosClient extends CosmWasmClient {
198198
private readonly _cometClient: CometClient,
199199
public registry: Registry,
200200
) {
201-
super(_cometClient);
201+
// Types have diverged with our fork of tendermint-rpc
202+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
203+
super(_cometClient as any);
202204
}
203205

204206
// eslint-disable-next-line @typescript-eslint/require-await
@@ -245,7 +247,9 @@ export class CosmosSafeClient
245247
height: number;
246248

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

packages/node/src/indexer/indexer.manager.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ export class IndexerManager extends BaseIndexerManager<
135135
for (const evt of blockContent.endBlockEvents ?? []) {
136136
await this.indexEvent(evt, dataSources, getVM);
137137
}
138+
139+
for (const evt of blockContent.finalizeBlockEvents ?? []) {
140+
await this.indexEvent(evt, dataSources, getVM);
141+
}
138142
}
139143

140144
private async indexBlockContent(

packages/node/src/indexer/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ export interface BlockContent {
2727
transactions: CosmosTransaction[];
2828
messages: CosmosMessage[];
2929
events: CosmosEvent[];
30+
// Tendermint34,37
3031
beginBlockEvents?: CosmosEvent[];
3132
endBlockEvents?: CosmosEvent[];
33+
34+
// Comet38
35+
finalizeBlockEvents?: CosmosEvent[];
3236
}
3337

3438
export type BestBlocks = Record<number, string>;

packages/node/src/utils/cosmos.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,10 @@ describe('Cosmos 0.50 support', () => {
380380
expect(status.nodeInfo.version).toMatch('0.38.');
381381
});
382382

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

390389
it('correctly parses events', () => {

packages/node/src/utils/cosmos.ts

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ import { toHex } from '@cosmjs/encoding';
88
import { DecodeObject, decodeTxRaw, Registry } from '@cosmjs/proto-signing';
99
import { fromTendermintEvent } from '@cosmjs/stargate';
1010
import { Log, parseRawLog } from '@cosmjs/stargate/build/logs';
11-
import { toRfc3339WithNanoseconds } from '@cosmjs/tendermint-rpc';
11+
import {
12+
toRfc3339WithNanoseconds,
13+
tendermint34,
14+
tendermint37,
15+
comet38,
16+
} from '@cosmjs/tendermint-rpc';
17+
1218
import {
1319
IBlock,
1420
getLogger,
@@ -494,6 +500,7 @@ export class LazyBlockContent implements BlockContent {
494500
private _wrappedEvent?: CosmosEvent[];
495501
private _wrappedBeginBlockEvents?: CosmosEvent[];
496502
private _wrappedEndBlockEvents?: CosmosEvent[];
503+
private _wrappedFinalizedBlockEvents?: CosmosEvent[];
497504
private _eventIdx = 0; //To maintain a valid count over begin block events, tx events and end block events
498505

499506
constructor(
@@ -543,10 +550,17 @@ export class LazyBlockContent implements BlockContent {
543550
}
544551

545552
get beginBlockEvents(): CosmosEvent[] {
553+
const results = this._results as
554+
| tendermint34.BlockResultsResponse
555+
| tendermint37.BlockResultsResponse;
556+
if (!results.beginBlockEvents?.length) {
557+
return [];
558+
}
559+
546560
if (!this._wrappedBeginBlockEvents) {
547561
this._wrappedBeginBlockEvents = wrapBlockBeginAndEndEvents(
548562
this.block,
549-
[...this._results.beginBlockEvents],
563+
[...results.beginBlockEvents],
550564
this._eventIdx,
551565
);
552566
this._eventIdx += this._wrappedBeginBlockEvents.length;
@@ -556,17 +570,42 @@ export class LazyBlockContent implements BlockContent {
556570
}
557571

558572
get endBlockEvents(): CosmosEvent[] {
573+
const results = this._results as
574+
| tendermint34.BlockResultsResponse
575+
| tendermint37.BlockResultsResponse;
576+
if (!results.endBlockEvents?.length) {
577+
return [];
578+
}
579+
559580
if (!this._wrappedEndBlockEvents) {
560581
this._wrappedEndBlockEvents = wrapBlockBeginAndEndEvents(
561582
this.block,
562-
[...this._results.endBlockEvents],
583+
[...results.endBlockEvents],
563584
this._eventIdx,
564585
);
565586
this._eventIdx += this._wrappedEndBlockEvents.length;
566587
}
567588

568589
return this._wrappedEndBlockEvents;
569590
}
591+
592+
get finalizeBlockEvents(): CosmosEvent[] {
593+
const results = this._results as comet38.BlockResultsResponse;
594+
if (!results.finalizeBlockEvents?.length) {
595+
return [];
596+
}
597+
598+
if (!this._wrappedFinalizedBlockEvents) {
599+
this._wrappedFinalizedBlockEvents = wrapBlockBeginAndEndEvents(
600+
this.block,
601+
[...results.finalizeBlockEvents],
602+
this._eventIdx,
603+
);
604+
this._eventIdx += this._wrappedFinalizedBlockEvents.length;
605+
}
606+
607+
return this._wrappedFinalizedBlockEvents;
608+
}
570609
}
571610

572611
export function calcInterval(api: CosmosClient): number {

yarn.lock

Lines changed: 70 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2298,6 +2298,21 @@ __metadata:
22982298
languageName: node
22992299
linkType: hard
23002300

2301+
"@cosmjs/crypto@npm:0.32.4, @cosmjs/crypto@npm:^0.32.4":
2302+
version: 0.32.4
2303+
resolution: "@cosmjs/crypto@npm:0.32.4"
2304+
dependencies:
2305+
"@cosmjs/encoding": ^0.32.4
2306+
"@cosmjs/math": ^0.32.4
2307+
"@cosmjs/utils": ^0.32.4
2308+
"@noble/hashes": ^1
2309+
bn.js: ^5.2.0
2310+
elliptic: ^6.5.4
2311+
libsodium-wrappers-sumo: ^0.7.11
2312+
checksum: 432313296350c070936af9516249a7c96c3c057242ab4a8ca261fcf12a5cfddf151d8b84dabec324e0d51e01643b0d92b798ab652ad4ec16321b691e875c93b3
2313+
languageName: node
2314+
linkType: hard
2315+
23012316
"@cosmjs/crypto@npm:^0.32.3":
23022317
version: 0.32.3
23032318
resolution: "@cosmjs/crypto@npm:0.32.3"
@@ -2313,18 +2328,14 @@ __metadata:
23132328
languageName: node
23142329
linkType: hard
23152330

2316-
"@cosmjs/crypto@npm:^0.32.4":
2331+
"@cosmjs/encoding@npm:0.32.4, @cosmjs/encoding@npm:^0.32.4":
23172332
version: 0.32.4
2318-
resolution: "@cosmjs/crypto@npm:0.32.4"
2333+
resolution: "@cosmjs/encoding@npm:0.32.4"
23192334
dependencies:
2320-
"@cosmjs/encoding": ^0.32.4
2321-
"@cosmjs/math": ^0.32.4
2322-
"@cosmjs/utils": ^0.32.4
2323-
"@noble/hashes": ^1
2324-
bn.js: ^5.2.0
2325-
elliptic: ^6.5.4
2326-
libsodium-wrappers-sumo: ^0.7.11
2327-
checksum: 432313296350c070936af9516249a7c96c3c057242ab4a8ca261fcf12a5cfddf151d8b84dabec324e0d51e01643b0d92b798ab652ad4ec16321b691e875c93b3
2335+
base64-js: ^1.3.0
2336+
bech32: ^1.1.4
2337+
readonly-date: ^1.0.0
2338+
checksum: 9a2a1d87b7fe3fa7ad05a0b049b783b5b08ccfd61ed5bb3a1a37e0ae93a0ad9bc8c6701b1d3112e7c154b2dd48a0c221263a39a4d6878a495dc59ac5eeef6ec2
23282339
languageName: node
23292340
linkType: hard
23302341

@@ -2339,14 +2350,13 @@ __metadata:
23392350
languageName: node
23402351
linkType: hard
23412352

2342-
"@cosmjs/encoding@npm:^0.32.4":
2353+
"@cosmjs/json-rpc@npm:0.32.4, @cosmjs/json-rpc@npm:^0.32.4":
23432354
version: 0.32.4
2344-
resolution: "@cosmjs/encoding@npm:0.32.4"
2355+
resolution: "@cosmjs/json-rpc@npm:0.32.4"
23452356
dependencies:
2346-
base64-js: ^1.3.0
2347-
bech32: ^1.1.4
2348-
readonly-date: ^1.0.0
2349-
checksum: 9a2a1d87b7fe3fa7ad05a0b049b783b5b08ccfd61ed5bb3a1a37e0ae93a0ad9bc8c6701b1d3112e7c154b2dd48a0c221263a39a4d6878a495dc59ac5eeef6ec2
2357+
"@cosmjs/stream": ^0.32.4
2358+
xstream: ^11.14.0
2359+
checksum: 5153d7fbccd7073679d138e351fe02395602346717d34d8bdd761797afa71bc395e82bc6cec797ffdc13aceeab8f508c75a9dd6b15314c1cb8a9757239978d62
23502360
languageName: node
23512361
linkType: hard
23522362

@@ -2360,13 +2370,12 @@ __metadata:
23602370
languageName: node
23612371
linkType: hard
23622372

2363-
"@cosmjs/json-rpc@npm:^0.32.4":
2373+
"@cosmjs/math@npm:0.32.4, @cosmjs/math@npm:^0.32.4":
23642374
version: 0.32.4
2365-
resolution: "@cosmjs/json-rpc@npm:0.32.4"
2375+
resolution: "@cosmjs/math@npm:0.32.4"
23662376
dependencies:
2367-
"@cosmjs/stream": ^0.32.4
2368-
xstream: ^11.14.0
2369-
checksum: 5153d7fbccd7073679d138e351fe02395602346717d34d8bdd761797afa71bc395e82bc6cec797ffdc13aceeab8f508c75a9dd6b15314c1cb8a9757239978d62
2377+
bn.js: ^5.2.0
2378+
checksum: 1269ad0c33a78b05c9f7c1bc7a7222d3b4504263ade3a15b07f95eb18c2620c96e4c79beeab66d7053294828b32cf04d0cc5a71610f755e1d1da06b04d462043
23702379
languageName: node
23712380
linkType: hard
23722381

@@ -2379,15 +2388,6 @@ __metadata:
23792388
languageName: node
23802389
linkType: hard
23812390

2382-
"@cosmjs/math@npm:^0.32.4":
2383-
version: 0.32.4
2384-
resolution: "@cosmjs/math@npm:0.32.4"
2385-
dependencies:
2386-
bn.js: ^5.2.0
2387-
checksum: 1269ad0c33a78b05c9f7c1bc7a7222d3b4504263ade3a15b07f95eb18c2620c96e4c79beeab66d7053294828b32cf04d0cc5a71610f755e1d1da06b04d462043
2388-
languageName: node
2389-
linkType: hard
2390-
23912391
"@cosmjs/proto-signing@npm:^0.32.3":
23922392
version: 0.32.3
23932393
resolution: "@cosmjs/proto-signing@npm:0.32.3"
@@ -2416,27 +2416,27 @@ __metadata:
24162416
languageName: node
24172417
linkType: hard
24182418

2419-
"@cosmjs/socket@npm:^0.32.3":
2420-
version: 0.32.3
2421-
resolution: "@cosmjs/socket@npm:0.32.3"
2419+
"@cosmjs/socket@npm:0.32.4, @cosmjs/socket@npm:^0.32.4":
2420+
version: 0.32.4
2421+
resolution: "@cosmjs/socket@npm:0.32.4"
24222422
dependencies:
2423-
"@cosmjs/stream": ^0.32.3
2423+
"@cosmjs/stream": ^0.32.4
24242424
isomorphic-ws: ^4.0.1
24252425
ws: ^7
24262426
xstream: ^11.14.0
2427-
checksum: 9e695a21b81c7987999c1452f18a341428ad01cda65b392386440d26589c2b53af81954c36156c5be88ddd97982c20db2fb938b4349a04f18f05b65547796556
2427+
checksum: 26125bbf261d5d77bec3c5340a9c60c1e512bee747984b3333521491aa4f4d2a3e2cba7f1e412013b38835eff875066e645d86f752d7936f19f9eae18b9d97e5
24282428
languageName: node
24292429
linkType: hard
24302430

2431-
"@cosmjs/socket@npm:^0.32.4":
2432-
version: 0.32.4
2433-
resolution: "@cosmjs/socket@npm:0.32.4"
2431+
"@cosmjs/socket@npm:^0.32.3":
2432+
version: 0.32.3
2433+
resolution: "@cosmjs/socket@npm:0.32.3"
24342434
dependencies:
2435-
"@cosmjs/stream": ^0.32.4
2435+
"@cosmjs/stream": ^0.32.3
24362436
isomorphic-ws: ^4.0.1
24372437
ws: ^7
24382438
xstream: ^11.14.0
2439-
checksum: 26125bbf261d5d77bec3c5340a9c60c1e512bee747984b3333521491aa4f4d2a3e2cba7f1e412013b38835eff875066e645d86f752d7936f19f9eae18b9d97e5
2439+
checksum: 9e695a21b81c7987999c1452f18a341428ad01cda65b392386440d26589c2b53af81954c36156c5be88ddd97982c20db2fb938b4349a04f18f05b65547796556
24402440
languageName: node
24412441
linkType: hard
24422442

@@ -2476,6 +2476,15 @@ __metadata:
24762476
languageName: node
24772477
linkType: hard
24782478

2479+
"@cosmjs/stream@npm:0.32.4, @cosmjs/stream@npm:^0.32.4":
2480+
version: 0.32.4
2481+
resolution: "@cosmjs/stream@npm:0.32.4"
2482+
dependencies:
2483+
xstream: ^11.14.0
2484+
checksum: fa55d3f29e8a7c56d5da4128989709f0b02fcee5319efa2504f62e4f2b0c64725ccb603d88f435f6fbe308dc6ef76b1fd3ea5aecfcb877a871c111366ddd3489
2485+
languageName: node
2486+
linkType: hard
2487+
24792488
"@cosmjs/stream@npm:^0.32.3":
24802489
version: 0.32.3
24812490
resolution: "@cosmjs/stream@npm:0.32.3"
@@ -2485,12 +2494,21 @@ __metadata:
24852494
languageName: node
24862495
linkType: hard
24872496

2488-
"@cosmjs/stream@npm:^0.32.4":
2497+
"@cosmjs/tendermint-rpc@npm:@subql/x-cosmos-tendermint-rpc@0.32.4":
24892498
version: 0.32.4
2490-
resolution: "@cosmjs/stream@npm:0.32.4"
2491-
dependencies:
2499+
resolution: "@subql/x-cosmos-tendermint-rpc@npm:0.32.4"
2500+
dependencies:
2501+
"@cosmjs/crypto": 0.32.4
2502+
"@cosmjs/encoding": 0.32.4
2503+
"@cosmjs/json-rpc": 0.32.4
2504+
"@cosmjs/math": 0.32.4
2505+
"@cosmjs/socket": 0.32.4
2506+
"@cosmjs/stream": 0.32.4
2507+
"@cosmjs/utils": 0.32.4
2508+
axios: ^1.6.0
2509+
readonly-date: ^1.0.0
24922510
xstream: ^11.14.0
2493-
checksum: fa55d3f29e8a7c56d5da4128989709f0b02fcee5319efa2504f62e4f2b0c64725ccb603d88f435f6fbe308dc6ef76b1fd3ea5aecfcb877a871c111366ddd3489
2511+
checksum: f98853e8a38690921adef946cf6bfd35a6ed9906c353700a24a85631c387961d7a2ad93b437a4c95d56d4452b50161075814fc353bd72a29f85bae154c6ff4f7
24942512
languageName: node
24952513
linkType: hard
24962514

@@ -2530,20 +2548,20 @@ __metadata:
25302548
languageName: node
25312549
linkType: hard
25322550

2551+
"@cosmjs/utils@npm:0.32.4, @cosmjs/utils@npm:^0.32.4":
2552+
version: 0.32.4
2553+
resolution: "@cosmjs/utils@npm:0.32.4"
2554+
checksum: 92f4d0878bedda53d113894ebadd31a6d189fdd45f2f884049ee99c2d7f907703b6dc40c8bc9b88b912443c38f3dbf77a9474183f41b85dec1f9ef3bec9d86c4
2555+
languageName: node
2556+
linkType: hard
2557+
25332558
"@cosmjs/utils@npm:^0.32.3":
25342559
version: 0.32.3
25352560
resolution: "@cosmjs/utils@npm:0.32.3"
25362561
checksum: ef2c101f18b3d134d638f145349130b0ef223b504e53c833180326877b394be757790b5dc8dfc88105dd8cf3b0c293c140432bd1540c4ae935799f654aeee27f
25372562
languageName: node
25382563
linkType: hard
25392564

2540-
"@cosmjs/utils@npm:^0.32.4":
2541-
version: 0.32.4
2542-
resolution: "@cosmjs/utils@npm:0.32.4"
2543-
checksum: 92f4d0878bedda53d113894ebadd31a6d189fdd45f2f884049ee99c2d7f907703b6dc40c8bc9b88b912443c38f3dbf77a9474183f41b85dec1f9ef3bec9d86c4
2544-
languageName: node
2545-
linkType: hard
2546-
25472565
"@cosmology/protobufjs@npm:6.11.6":
25482566
version: 6.11.6
25492567
resolution: "@cosmology/protobufjs@npm:6.11.6"
@@ -4254,6 +4272,7 @@ __metadata:
42544272
"@cosmjs/cosmwasm-stargate": ^0.32.4
42554273
"@cosmjs/proto-signing": ^0.32.4
42564274
"@cosmjs/stargate": ^0.32.4
4275+
"@cosmjs/tendermint-rpc": "npm:@subql/[email protected]"
42574276
"@kyvejs/sdk": ^1.3.2
42584277
"@nestjs/common": ^9.4.0
42594278
"@nestjs/core": ^9.4.0

0 commit comments

Comments
 (0)