Fix incomplete event indexing for SEI based EVM chains#426
Fix incomplete event indexing for SEI based EVM chains#426lorrod wants to merge 2 commits intosubquery:mainfrom
Conversation
📝 WalkthroughWalkthroughTwo files in the indexer module are modified. The first adds logic to index synthetic Cosmos/Sei logs with transaction hashes not found in the block's transactions. The second changes how fallback headers are retrieved from manual construction to a service method call. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/node/src/indexer/indexer.manager.ts (1)
132-137: Harden hash normalization to avoid runtime crashes on malformed log payloads.Line 136 assumes
log.transactionHashis always present. If an RPC response ever returns a null/undefined hash for an anomalous log, this path throws and aborts block indexing. Consider a defensive guard.Proposed hardening
- const txHashes = new Set( - block.transactions.map((tx) => tx.hash.toLowerCase()), - ); + const txHashes = new Set( + block.transactions + .map((tx) => tx.hash?.toLowerCase()) + .filter((h): h is string => Boolean(h)), + ); for (const log of block.logs ?? []) { - if (!txHashes.has(log.transactionHash.toLowerCase())) { + const logTxHash = log.transactionHash?.toLowerCase(); + if (!logTxHash || !txHashes.has(logTxHash)) { await this.indexEvent(log, dataSources, getVM); } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/node/src/indexer/indexer.manager.ts` around lines 132 - 137, The loop over block.logs assumes log.transactionHash is always defined and calls .toLowerCase(), which can crash on null/undefined; in the indexer.manager.ts where txHashes is created and the for-loop calls this.indexEvent(log, dataSources, getVM), add a defensive guard that extracts transactionHash from each log, ensures it's a string (e.g., typeof === 'string' && transactionHash.length > 0) before calling .toLowerCase(), and skip or otherwise handle logs with missing/invalid transactionHash so they do not trigger the .toLowerCase() call or abort block indexing; keep the existing behavior of calling indexEvent only for logs whose normalized hash is not in the txHashes Set.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/node/src/indexer/indexer.manager.ts`:
- Around line 132-137: The loop over block.logs assumes log.transactionHash is
always defined and calls .toLowerCase(), which can crash on null/undefined; in
the indexer.manager.ts where txHashes is created and the for-loop calls
this.indexEvent(log, dataSources, getVM), add a defensive guard that extracts
transactionHash from each log, ensures it's a string (e.g., typeof === 'string'
&& transactionHash.length > 0) before calling .toLowerCase(), and skip or
otherwise handle logs with missing/invalid transactionHash so they do not
trigger the .toLowerCase() call or abort block indexing; keep the existing
behavior of calling indexEvent only for logs whose normalized hash is not in the
txHashes Set.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 5120baf2-bc38-48d2-9c9b-6a84146dc4b0
📒 Files selected for processing (2)
packages/node/src/indexer/indexer.manager.tspackages/node/src/indexer/unfinalizedBlocks.service.ts
This PR fixes incomplete event indexing for Cosmos/Sei-based EVM chains where synthetic logs are injected at the block level.
In these environments, some logs are emitted from transactions that are not returned via
eth_getBlockByNumber, but are still discoverable througheth_getLogsdue to block-level bloom filtering. These logs were previously skipped because the indexer only processed logs tied to visible transactions.What was changed
Added additional handling in
IndexerManagerto process synthetic logs whosetransactionHashis not present in the block’s transaction list.Introduced a fallback mechanism that:
Improved rewind logic in
UnfinalizedBlocksService:getHeaderForHeightMotivation
Without this fix:
This change ensures compatibility with hybrid EVM implementations that inject logs outside standard Ethereum transaction visibility.
Fixes # (issue)
Type of change
Checklist
Summary by CodeRabbit
Bug Fixes