Skip to content

Commit

Permalink
Remove transactions that cant be decoded (#280)
Browse files Browse the repository at this point in the history
* Remove transactions that cant be decoded

* Update changelog
  • Loading branch information
stwiname authored Aug 22, 2024
1 parent 46fb650 commit 7ae4239
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
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]
### Fixed
- Filter out transactions that can't be decoded (#280)

## [4.1.0] - 2024-08-12
### Added
Expand Down
25 changes: 24 additions & 1 deletion packages/node/src/utils/cosmos.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
});
});
34 changes: 24 additions & 10 deletions packages/node/src/utils/cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 7ae4239

Please sign in to comment.