diff --git a/packages/node/CHANGELOG.md b/packages/node/CHANGELOG.md index 89b2f9ef..90d410d0 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) ## [4.1.0] - 2024-08-12 ### Added diff --git a/packages/node/src/utils/cosmos.spec.ts b/packages/node/src/utils/cosmos.spec.ts index fefb01bf..e6223797 100644 --- a/packages/node/src/utils/cosmos.spec.ts +++ b/packages/node/src/utils/cosmos.spec.ts @@ -21,7 +21,12 @@ import { import { fromInt } from 'long'; import { CosmosClient } from '../indexer/api.service'; import { BlockContent } from '../indexer/types'; -import { fetchBlocksBatches, filterMessageData, wrapEvent } from './cosmos'; +import { + fetchBlocksBatches, + filterMessageData, + filterMessages, + wrapEvent, +} from './cosmos'; const ENDPOINT = 'https://rpc.mainnet.archway.io'; @@ -400,4 +405,22 @@ 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); + }); }); diff --git a/packages/node/src/utils/cosmos.ts b/packages/node/src/utils/cosmos.ts index 5989adc2..a9ed6a65 100644 --- a/packages/node/src/utils/cosmos.ts +++ b/packages/node/src/utils/cosmos.ts @@ -262,16 +262,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(