Skip to content

fix(rpc): Fix eth_getBlockReceipts crash when KV indexer is overwritten#877

Open
JayT106 wants to merge 8 commits intodevelopfrom
backport/pr-870-fix-receipt-indexer-overwrite
Open

fix(rpc): Fix eth_getBlockReceipts crash when KV indexer is overwritten#877
JayT106 wants to merge 8 commits intodevelopfrom
backport/pr-870-fix-receipt-indexer-overwrite

Conversation

@JayT106
Copy link
Copy Markdown

@JayT106 JayT106 commented Mar 31, 2026

eth_getBlockReceipts (and eth_getTransactionReceipt with an explicit block scope) could crash or return a receipt from the wrong block when the KV tx indexer had been overwritten to point the same Ethereum tx hash at a later block height.

Changes

  • GetBlockReceipts – skip nil receipts instead of panicking on append
  • GetTransactionReceipt – compare indexer-reported height against the caller-supplied resBlock height; when they differ, rebuild the TxResult from the requested block's data rather than trusting the stale index
  • txResultFromBlockHash (new helper) – walks all transactions in a ResultBlock, parses each via ParseTxResult, and returns a correctly-anchored TxResult + ResultBlockResults for the requested block; returns (nil, blockRes, nil) when the hash is not present in the block
// Before: blockRes always fetched from indexer height (wrong block if index was overwritten)
blockRes, err := b.TendermintBlockResultByNumber(&res.Height)

// After: if indexer height ≠ requested block height, rescan the requested block
if res.Height == resBlock.Block.Height {
    blockRes, err = b.TendermintBlockResultByNumber(&res.Height)
} else {
    res, blockRes, err = b.txResultFromBlockHash(resBlock, hash)
}
  • Tests – added TestGetTransactionReceipt_BlockScopedWhenIndexerOverwritten covering the full overwrite scenario: index two blocks for the same tx hash, verify block-scoped queries return data anchored to the requested block

@JayT106 JayT106 requested a review from a team as a code owner March 31, 2026 19:08
@JayT106 JayT106 requested review from XinyuCRO and songgaoye and removed request for a team March 31, 2026 19:08
@github-actions

This comment has been minimized.

JayT106 added a commit that referenced this pull request Mar 31, 2026
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@JayT106 JayT106 changed the title backport: skip receipt when KV indexer points to a different block (#870) fix(rpc): fix eth_getBlockReceipts crash Mar 31, 2026
@JayT106 JayT106 force-pushed the backport/pr-870-fix-receipt-indexer-overwrite branch from 663beea to 8cf38b6 Compare March 31, 2026 19:15
@JayT106 JayT106 changed the title fix(rpc): fix eth_getBlockReceipts crash fix(rpc): Fix eth_getBlockReceipts crash Mar 31, 2026
@JayT106 JayT106 force-pushed the backport/pr-870-fix-receipt-indexer-overwrite branch from 8cf38b6 to a2a3089 Compare March 31, 2026 19:19
@JayT106 JayT106 self-assigned this Mar 31, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

❌ Patch coverage is 54.00000% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 43.11%. Comparing base (620d74d) to head (742830c).

Files with missing lines Patch % Lines
rpc/backend/tx_info.go 56.25% 12 Missing and 9 partials ⚠️
rpc/backend/blocks.go 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #877      +/-   ##
===========================================
+ Coverage    43.07%   43.11%   +0.03%     
===========================================
  Files          195      195              
  Lines        16551    16597      +46     
===========================================
+ Hits          7130     7156      +26     
- Misses        8697     8708      +11     
- Partials       724      733       +9     
Files with missing lines Coverage Δ
rpc/backend/blocks.go 78.86% <0.00%> (-0.48%) ⬇️
rpc/backend/tx_info.go 54.80% <56.25%> (+0.60%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

@songgaoye songgaoye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown

@thomas-nguy thomas-nguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the implementation to return the receipt in the block

@JayT106
Copy link
Copy Markdown
Author

JayT106 commented Apr 7, 2026

Change the implementation to return the receipt in the block

Done!

@songgaoye songgaoye self-requested a review April 8, 2026 07:14
@thomas-nguy
Copy link
Copy Markdown

@copilot review the PR

Copy link
Copy Markdown

Copilot AI commented Apr 8, 2026

@copilot review the PR

PR review completed. The implementation looks correct and the tests pass. Here's a summary:

Changes reviewed:

  • blocks.goGetBlockReceipts now skips nil receipts with continue to prevent panics.
  • tx_info.goGetTransactionReceipt compares the indexer height (res.Height) against the requested block height (resBlock.Block.Height). When they differ (indexer overwrite scenario), it calls the new txResultFromBlockHash helper to rebuild the TxResult from the requested block's transactions instead of returning the wrong block's data.
  • txResultFromBlockHash – Scans all txs in the requested block, parses each one via ParseTxResult, and returns a correctly-anchored TxResult + ResultBlockResults for the requested block. Returns (nil, blockRes, nil) when the hash isn't found in the block (handled gracefully by the caller).

No issues found. Edge cases are handled (out-of-range indexes, decode errors, tx not found in block). All related tests pass (commit a6b75e5).

Copilot AI changed the title fix(rpc): Fix eth_getBlockReceipts crash fix(rpc): Fix eth_getBlockReceipts crash when KV indexer is overwritten Apr 8, 2026
Copilot AI requested a review from thomas-nguy April 8, 2026 07:59
@songgaoye songgaoye self-requested a review April 9, 2026 01:22
Copy link
Copy Markdown

@songgaoye songgaoye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just need to fix the nil guard. LGTM

JayT106 and others added 3 commits April 9, 2026 10:14
…rite

Signed-off-by: JayT106 <JayT106@users.noreply.github.com>
Co-authored-by: Thomas <81727899+thomas-nguy@users.noreply.github.com>
Signed-off-by: JayT106 <JayT106@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants