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

Remove transactions that cant be decoded #280

Merged
merged 2 commits into from
Aug 22, 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]
### 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
Loading