Skip to content

feat: Retain pruned transactions until pruned block is finalised#20237

Open
PhilWindle wants to merge 2 commits intonextfrom
pw/soft-delete
Open

feat: Retain pruned transactions until pruned block is finalised#20237
PhilWindle wants to merge 2 commits intonextfrom
pw/soft-delete

Conversation

@PhilWindle
Copy link
Collaborator

@PhilWindle PhilWindle commented Feb 6, 2026

Summary

Implements soft deletion for transactions from pruned blocks in TxPoolV2:

  • Transactions from pruned blocks are soft-deleted - kept in DB for later re-execution
  • Transactions NOT from pruned blocks are hard-deleted - removed from DB immediately as before
  • Soft-deleted txs are retrievable via getTxByHash and hasTxs, with status 'deleted' from getTxStatus
  • Hard deletion on finalization - soft-deleted txs are permanently removed when their original mined block is finalized

Key Design Decisions

  1. Track mined block, not prune point: When a tx is un-mined due to a reorg, we track the block it was mined in, not the block we pruned to. This ensures the tx is kept until that block is finalized on the new chain.

  2. Handle re-mining: If a tx is mined at block 4, pruned, re-mined at block 5, then pruned again, we track block 5 (the higher value). The tx is only hard-deleted when block 5 is finalized.

  3. Single source of truth: DeletedPool is responsible for ALL deletion decisions. It determines whether to soft-delete or hard-delete based on whether the tx is from a pruned block.

Example Scenario

1. Tx mined at block 10
2. Chain prunes to block 5 (tx un-mined, tracked as minedAtBlock=10)
3. Tx fails validation and is soft-deleted
4. Block 9 finalized → tx still in DB
5. Block 10 finalized → tx hard-deleted

Test plan

  • 177 tx_pool_v2 tests pass
  • 17 deleted_pool tests pass
  • Test: tx mined, pruned, soft-deleted, finalized at correct block
  • Test: tx re-mined at higher block, tracked correctly
  • Test: multiple txs with different mined blocks finalize at correct times
  • Test: persistence across restarts

🤖 Generated with Claude Code

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.

1 participant