Skip to content

fix(prune): add minimum 64 block retention for receipts and bodies#21520

Merged
joshieDo merged 3 commits intomainfrom
fix/receipts-pruning-min-blocks
Jan 28, 2026
Merged

fix(prune): add minimum 64 block retention for receipts and bodies#21520
joshieDo merged 3 commits intomainfrom
fix/receipts-pruning-min-blocks

Conversation

@joshieDo
Copy link
Collaborator

@joshieDo joshieDo commented Jan 28, 2026

Problem

With PruneMode::Full for receipts (min_blocks() == 0), receipts are pruned immediately after persistence. During a same-height reorg, canonical_block_by_hash fails with no receipt found because receipts were already pruned.

Fix

  • Add MINIMUM_DISTANCE = 64 for Receipts and Bodies segments
  • Rename MINIMUM_PRUNING_DISTANCEMINIMUM_UNWIND_SAFE_DISTANCE

When PruneMode::Full is used for receipts, the pruner would prune all
receipts up to the tip block immediately after persistence. This causes
a race condition during chain reorganizations:

1. Block A at height N is persisted to disk
2. Pruner runs and prunes A's receipts
3. Block B at height N arrives (reorg)
4. FCU tries to make B canonical
5. on_new_head calls canonical_block_by_hash(A) to walk back old chain
6. canonical_block_by_hash tries to reconstruct ExecutedBlock from disk
7. get_state() fails with 'no receipt found' because receipts were pruned

This fix adds MINIMUM_RECEIPTS_DISTANCE (64 blocks) to ensure receipts
and bodies are retained long enough to handle any potential reorgs.

Fixes a regression introduced by PR #17938 which added canonical_block_by_hash
that assumes ExecutedBlock can always be reconstructed from disk.
@joshieDo joshieDo self-assigned this Jan 28, 2026
@github-project-automation github-project-automation bot moved this to Backlog in Reth Tracker Jan 28, 2026
@joshieDo joshieDo force-pushed the fix/receipts-pruning-min-blocks branch from 1f2648c to 73bff9e Compare January 28, 2026 12:32
…STANCE

- MINIMUM_STATE_HISTORY_DISTANCE (10064): used for AccountHistory, StorageHistory, ContractLogs
- MINIMUM_PRUNING_DISTANCE (64): used for Receipts, Bodies to ensure reorg safety
@joshieDo joshieDo force-pushed the fix/receipts-pruning-min-blocks branch from 73bff9e to f938e79 Compare January 28, 2026 12:34
@joshieDo joshieDo marked this pull request as ready for review January 28, 2026 12:35
@github-project-automation github-project-automation bot moved this from Backlog to In Progress in Reth Tracker Jan 28, 2026
@joshieDo joshieDo marked this pull request as draft January 28, 2026 12:45
@joshieDo joshieDo marked this pull request as ready for review January 28, 2026 12:48
@@ -80,9 +82,9 @@ impl Default for DefaultPruningValues {
sender_recovery: Some(PruneMode::Full),
transaction_lookup: Some(PruneMode::Full),
receipts: Some(PruneMode::Full),
Copy link
Member

Choose a reason for hiding this comment

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

should we also change this?

@joshieDo joshieDo added this pull request to the merge queue Jan 28, 2026
Merged via the queue into main with commit 013dfdf Jan 28, 2026
46 checks passed
@joshieDo joshieDo deleted the fix/receipts-pruning-min-blocks branch January 28, 2026 18:21
@github-project-automation github-project-automation bot moved this from In Progress to Done in Reth Tracker Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants