rawdb: ignore invalid receipt cache transaction indexes#21249
Merged
AskAlexSharov merged 3 commits intoMay 19, 2026
Merged
Conversation
AskAlexSharov
requested changes
May 18, 2026
AskAlexSharov
requested changes
May 18, 2026
AskAlexSharov
approved these changes
May 19, 2026
AskAlexSharov
added a commit
that referenced
this pull request
May 20, 2026
Cherry-pick of #21249 to release/3.4. --------- Co-authored-by: Sahil Sojitra <sahilsojitra4555@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
This PR fixes an
eth_getBlockReceiptsfailure when the persisted receipt cache contains invalid transaction-index metadata for a block.ReadReceiptsCacheV2reads block receipts fromRCacheV2by walking the block’s txNum range and decoding each cached receipt. The decoded receipt metadata includesTransactionIndex, which is then used to pick the corresponding transaction fromblock.Transactions()before deriving RPC fields such as transaction hash, block hash, log indexes, and bloom.Before this change, an invalid cached
TransactionIndexwas treated as a hard error. For example, block24,952,410has543transactions, but the cached receipt path could decode a receipt withTransactionIndex = 3,468,750,000. That index can never be valid for the block, so ReadReceiptsCacheV2 returned:
That error then propagated to
eth_getBlockReceipts, even though the receipt cache is only an acceleration path and receipts can still be derived from canonical block/state data.For production users, this matters because corrupted, stale, or otherwise inconsistent receipt-cache metadata should not make block receipt RPCs fail when Erigon can regenerate the correct receipts.
Fix
This change makes block-level
RCacheV2reads validate the cached receipt set before using it.ReadReceiptsCacheV2now checks that cached receipts match the block transaction order. Since cache entries are read in txNum order, each decoded receipt must have aTransactionIndexequal to the next expected receipt position and must be within the block transaction list.If a cached receipt has an impossible or non-sequential transaction index, the cache read is treated as a cache miss. The caller can then fall back to deriving receipts instead of returning an internal cache error to the RPC client.
The reader also checks that the cache produced a complete receipt set for the block. Partial cache contents are not enough for block receipt RPCs, which require the full ordered receipt list.
The fix is intentionally small and keeps the cache semantics clear: valid cache data is used as before, while invalid or incomplete cache data is ignored and regenerated from canonical data.
Tests
This PR adds focused coverage for the
ReadReceiptsCacheV2block receipt cache path.TestReadReceiptsCacheV2BadTxIndexwrites a cached receipt with the reported invalid transaction index,3,468,750,000, for a block with two transactions. It verifies that the cache reader returns a cache miss instead of surfacing an out-of-range error.TestReadReceiptsCacheV2UnorderedTxIndexwrites a cached receipt whose transaction index is in range but does not match the txNum order. This covers stale or inconsistent cache metadata that would otherwise attach a receipt to the wrong transaction.The existing
TestBlockReceiptStoragecoverage continues to verify that a valid ordered receipt cache is still read successfully.Closes: #21194