Fixes dumptxoutset rollback functionality when competing forks exist.
Problem: dumptxoutset rollback fails when competing forks are present at the target height, even though it should work on the active chain regardless of forks.
Solution:
When competing forks exist, the current implementation’s InvalidateBlock
call causes a reorg to the competing fork instead of rolling back to the desired main chain block.
This PR fixes the issue by enhancing the TemporaryRollback
class to:
- Identify all competing fork blocks at heights above the target
- Invalidate fork blocks first to prevent reorg during main chain invalidation
- Then invalidate the main chain block for clean rollback
- Restore all invalidated blocks in the destructor
Changes:
- Fix
TemporaryRollback
class insrc/rpc/blockchain.cpp
to handle competing forks - Add comprehensive functional test
rpc_dumptxoutset_forks.py
that verifies the fix - Update test to confirm
dumptxoutset
works correctly with competing forks present
Testing:
The test creates competing forks and verifies that dumptxoutset rollback
now works correctly, creating snapshots from the intended main chain block rather than failing or using the wrong chain.
Fixes #32817.