diff --git a/.yarn/versions/92eab379.yml b/.yarn/versions/92eab379.yml new file mode 100644 index 00000000..e69de29b diff --git a/packages/node/CHANGELOG.md b/packages/node/CHANGELOG.md index add71571..c8803d8c 100644 --- a/packages/node/CHANGELOG.md +++ b/packages/node/CHANGELOG.md @@ -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] +### Fixed +- Filter out transactions that can't be decoded (#280) ### Change - Support bigint filter diff --git a/packages/node/package.json b/packages/node/package.json index 32facef1..0438224e 100644 --- a/packages/node/package.json +++ b/packages/node/package.json @@ -1,6 +1,6 @@ { "name": "@subql/node-cosmos", - "version": "4.1.0", + "version": "4.1.1-0", "description": "", "author": "SubQuery Pte Ltd", "license": "GPL-3.0", @@ -56,5 +56,6 @@ "files": [ "/dist", "/bin" - ] + ], + "stableVersion": "4.1.0" } diff --git a/packages/node/src/utils/cosmos.spec.ts b/packages/node/src/utils/cosmos.spec.ts index 75c3c6d7..bc10ac27 100644 --- a/packages/node/src/utils/cosmos.spec.ts +++ b/packages/node/src/utils/cosmos.spec.ts @@ -406,6 +406,24 @@ describe('Cosmos 0.50 support', () => { expect(event.log.events.length).toEqual(0); }); + + // block.tx when block.block.tx cannot be decoded + // { + // code: 2, + // codespace: 'sdk', + // log: 'tx parse error', + // data: undefined, + // events: [], + // gasWanted: 0n, + // gasUsed: 0n + // } + + it('doesnt throw when a block contains ExtendedCommitInfo in the transactions', async () => { + const [firstBlock] = await fetchBlocksBatches(api, [13_379_322]); // https://www.mintscan.io/neutron/block/13379322 + const block = firstBlock.block; + + expect(block.messages.length).toEqual(4); + }); }); describe('Cosmos bigint support', () => { diff --git a/packages/node/src/utils/cosmos.ts b/packages/node/src/utils/cosmos.ts index 87f8c5c6..680b77bc 100644 --- a/packages/node/src/utils/cosmos.ts +++ b/packages/node/src/utils/cosmos.ts @@ -271,16 +271,30 @@ export function wrapTx( block: CosmosBlock, txResults: TxData[], ): CosmosTransaction[] { - return txResults.map((tx, idx) => ({ - idx, - block: block, - tx, - hash: toHex(sha256(block.block.txs[idx])).toUpperCase(), - get decodedTx() { - delete (this as any).decodedTx; - return ((this.decodedTx as any) = decodeTxRaw(block.block.txs[idx])); - }, - })); + return ( + txResults + .map((tx, idx) => ({ + idx, + block: block, + tx, + hash: toHex(sha256(block.block.txs[idx])).toUpperCase(), + get decodedTx() { + delete (this as any).decodedTx; + try { + return ((this.decodedTx as any) = decodeTxRaw( + block.block.txs[idx], + )); + } catch (e) { + throw new Error( + `Failed to decode transaction idx="${idx}" at height="${block.block.header.height}"`, + { cause: e }, + ); + } + }, + })) + // Somtimes there might be other data types in the transactions, ExtendedCommitInfo, we filter them out here so that `decodedTx` doesn't fail + .filter((tx) => tx.tx.log !== 'tx parse error') + ); } export function wrapCosmosMsg(