#33959 test: deduplicate reorg test code
https://github.com/bitcoin/bitcoin/pull/33959 · · +104/-90 in 13 files, 2 commits · labels: Tests
Goal
- Deduplicate reorg test helpers across functional tests into a shared utility
- Exercise realistic competing-chain reorg code paths instead of artificial block invalidations
This PR moves the duplicated `trigger_reorg()` helper method across functional test files into `test_framework/blocktools.py`. It also converts functional tests that used the `invalidateblock` RPC to simulate reorgs over to fork-based reorgs.
Problem: Functional tests repeatedly copy-pasted `trigger_reorg()` helpers, and several tests used `invalidateblock` to simulate reorgs, which exercises a different code path than an actual reorg triggered by an arriving competing chain.
Category: Test infrastructure (#29 of 45)
P3 · cleanup
- P3 because it consolidates test utilities and cleans up reorg mechanics without fixing active bugs
- Makes reorg testing more realistic across several functional test suites
Deduplicates `trigger_reorg()` across test files and improves test realism by avoiding `invalidateblock` where a real reorg is intended. Follow-up to merged PR #32587.
Membership: Modifies shared test framework utility `blocktools.py` and cleans up functional test reorg mechanics.
Factors: security/stability 0, bug 0, performance 0, user value 0, leverage 1
Reviewability: Ready
- Ready to review
- Previous reviewer feedback has been addressed and CI is passing cleanly
All reviewer comments were addressed in the latest push, and CI is passing cleanly.
Author status: active, last addressed reviewer suggestions on 2026-07-30
Resolved concerns:
- instagibbs noted that introducing a separate `Forkgenerator` abstraction was overengineering; author removed it and kept only `trigger_reorg` in `blocktools.py`.
Agreement: Neutral
- Advised dropping the separate generator abstraction to keep only the helper (instagibbs)
- Author simplified the PR accordingly and is awaiting re-review (instagibbs)
instagibbs recommended simplifying away excess abstractions, which the author implemented; awaiting re-review.
instagibbs reviewed the code and suggested keeping only `trigger_reorg` rather than adding a `Forkgenerator` abstraction. The author implemented the suggestion, and no further objections remain.
- instagibbs: 'I think this might be a bit of overengineering. Centralizing code is nice, but really I don't see the value of the added abstraction aside from centralizing trigger_reorg?'
- yuvicc: 'Addressed @instagibbs suggestion to only keep trigger_reorg method in blocktools.py' and force-pushed updates
Review verdicts (DrahtBot): 0
Files
File list not available for this run.
Card
This PR moves the duplicated trigger_reorg helper into blocktools.py and converts functional tests that used invalidateblock to use realistic fork-based reorgs. It addresses duplicate test code and ensures tests exercise real reorg code paths rather than artificial block invalidations. Review feedback from instagibbs to drop extra class abstractions was incorporated, and the branch is clean and ready for further review.