#36109 test: harden arbitrary-parent block creation
https://github.com/bitcoin/bitcoin/pull/36109 · · +32/-15 in 3 files, 4 commits · labels: Tests
Goal
- Ensure test utilities safely construct valid blocks when building on arbitrary parent blocks
- Prevent future fork tests from silently generating invalid blocks at low heights or across halvings
Consolidates parent-dependent block template reconstruction logic into a shared RebuildBlockForParent helper used by BuildChain and MinerTestingSetup::Block. The helper updates the previous block hash and timestamp, recalculates the proof-of-work target and block subsidy for the parent's actual height, and pads coinbase input scripts at low heights to satisfy the two-byte minimum length.
Problem: Test utilities that repoint active-tip block templates to arbitrary parents previously copied the active tip's work target and subsidy, and could create coinbase scripts that violate minimum length at heights 1 through 16. Existing test callers avoided these cases or worked around them locally, but future tests constructing fork blocks could produce silently invalid blocks.
Category: Test infrastructure (#30 of 45)
P3 · cleanup
- P3 because it is internal hardening for test utilities rather than a fix for broken tests
- Benefit is preventative leverage for developers writing new fork-block test scenarios
- Existing test callers already worked around these edge cases locally
Deduplicates fork block construction logic and guards against subtle test-block invalidity across halvings and low heights. The author explicitly notes that 'existing callers already avoid these cases or handle them locally, so no current test fails', making this a worthwhile internal hardening change rather than a fix for flaky or broken tests.
Membership: Changes test helper functions in src/test/util/mining.cpp and assertions in src/test/validation_block_tests.cpp.
Factors: security/stability 0, bug 0, performance 0, user value 0, leverage 1
Reviewability: Paused: Waiting on author
- Reviewable now to weigh in on open design questions while waiting on an author reply
Reviewer jeanpablojp raised a material design question regarding mempool fee handling in the rebuilt coinbase and offered test fixtures; the PR has been waiting 8 days on an author reply.
Author status: silent since submission on 2026-08-28
Open concerns:
- jeanpablojp noted that RebuildBlockForParent overwrites coinbase nValue strictly with GetBlockSubsidy, which would drop fees if a template included mempool transactions, and suggested disabling mempool on the MinerTestingSetup template call
- jeanpablojp provided two test case snippets covering the target and subsidy/padding recalculation, as current suites do not fail if those lines are removed
Agreement: Positive
- Overall positive sentiment with testing and improvement suggestions
- Concept approval after testing each commit locally against master (jeanpablojp)
- Suggested disabling mempool on template calls to avoid dropping transaction fees (jeanpablojp)
- Provided test fixtures to cover target recalculation and coinbase padding (jeanpablojp)
Positive; jeanpablojp tested and Concept ACKed with suggestions on fee handling and test coverage
The only reviewer provided a Concept ACK and reported successful local testing of each commit against master, alongside actionable suggestions for improvement.
- jeanpablojp gave Concept ACK after testing each commit and running unit tests against master
- jeanpablojp suggested setting .use_mempool = false on the MinerTestingSetup template call to prevent fee mismatch
- jeanpablojp supplied two fixture tests to cover the recalculated difficulty and coinbase script
Review verdicts (DrahtBot): 0
- Concept ACK: jeanpablojp
Files
47 lines under test/bench/ci.
- src/test/util/mining.cpp +18/-9
- src/test/validation_block_tests.cpp +7/-6
- src/test/util/mining.h +7/-0
Card
PR #36109 extracts and hardens the shared logic for repointing block templates to arbitrary fork parents in test helpers. It recalculates the proof-of-work target and block subsidy from the target parent and pads short BIP34 coinbase scripts. No existing tests currently fail because existing callers avoid these boundaries, so the benefit is preventative hardening for future test writers. Review is currently paused waiting on author feedback regarding reviewer suggestions about mempool fee preservation and test additions.