mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 12:17:38 +00:00
test: fix coinbases built on arbitrary parents #36109
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36109
Loading…
Reference in a new issue
No description provided.
Delete branch "l0rinc/test-build-valid-fork-blocks"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem: Test helpers that attach active-tip templates to arbitrary parents retain the template's subsidy.
Existing reorg tests can pass with underpaid coinbases.
A fork crossing a halving can overpay and fail with
bad-cb-amount.At heights 1 through 16, encoding only the height leaves the coinbase input script too short and triggers
bad-cb-length.Fix: Share parent-dependent reconstruction between
BuildChain()andMinerTestingSetup::Block(), deriving difficulty and coinbase fields from the actual parent.Pad rebuilt coinbase input scripts.
Require coinbase-only templates so replacing the reward with the subsidy cannot discard transaction fees.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
Concept ACK
Built each commit and ran the unit tests, with a before and after of both cases against master.
Removing the target, subsidy or padding line here leaves
blockfilter_index_testsandbaseindex_testsgreen, so nothing on that side covers what the branch changes. The new assertions inMinerTestingSetup::Blockcatch the subsidy and the padding, and the target has nothing anywhere.These two cover all four fields, if they are worth having. The target one calls the helper directly, which is the only way in, since on regtest the recalculated target always equals the template's and no chain can tell the line apart. The coinbase one passes here and fails on master, first on the script length and then at the halving block. Both compile in
blockfilter_index_tests.cpp.This is an assignment rather than an adjustment, so the template's fees go with it.
MinerTestingSetup::Blockasks for its template with the mempool on, and with one transaction in it the coinbase reward comes out at 5000001000 on master and 5000000000 here, with the block still carrying that transaction.Nothing hits it today, since the mempool is empty at every call. Would
.use_mempool = falseon that template call be simpler? It makes the site matchBuildChain, so the overwrite is exact, and the three suites stay green with it.🐙 This pull request conflicts with the target branch and needs rebase.
Rebased to resolve conflicts and applied the review suggestions.
The block’s difficulty now uses its actual parent and timestamp, and its coinbase pays the subsidy for its resulting height.
I also added focused tests for the target and coinbase fields through the first halving.
Thanks! I added similar tests, with the coinbase cases combined into one fork test. I also credited you as a co-author on the commits containing them.
Sure, added
.use_mempool = falsetoMinerTestingSetup::Block()and asserted the shared helper receives a coinbase-only block.Earlier concerns remain unresolved; see the Run archive linked from the Review report.
🔵 Suggestion · The
Block()subsidy change lacks a distinguishing assertionThe new subsidy assertions cover
BuildChain(), but the tests usingMinerTestingSetup::Block()would still accept its previous active-tip template reward.Location:
src/test/validation_block_tests.cpp:98(head).🔵 Suggestion · The
Block()migration spans the subsidy and padding commitsThe series temporarily rewrites
Block()'s coinbase input script twice; migrating the caller after the padding change would make that migration independently reviewable without changing the final tree.Location: src/test/validation_block_tests.cpp:98 (commit).
Review coverage was incomplete.
Reviewed:
b7b762880e75· Review report · Previous reportspermalink
Concept ACK
Code review
23a99695ef, mostly documentation feedback.You may find the
BlockAssembler::CreateCoinbaseTxhelper in #36109 commit902d836b75useful. But I don't mind rebasing that PR.In
9312297e15test: derive fork subsidy from parent: let's document the reason for this restriction, so anyone who needs to relax it will know what to pay attention to.In
4e5aeb3535refactor: extract fork block reconstruction nit:SwitchBlockParent(..., uint32_t new_time)might be a better name. The caller's goal is to switch the parent and change the time. The description could then say that the block is rebuilt, and enumerate the side effects (in later commits), like modified subsidy.In
9312297e15test: derive fork subsidy from parent: this might be a good time to giveMinerTestingSetup::Blocka quick doc:In
4e5aeb3535refactor: extract fork block reconstruction:This relies on the 20-minute difficulty reset rule, which only exists on testnet3 and testnet4. Regtest doesn't have difficulty adjustment at all, but technically the same 20-minute reset rule exists. The test exploits this with a synthetic block with an
nBitsthat's impossible in a "real" regtest chain.In other words: please document this.
I'm also worried that it's a bit brittle to rely on, since we could remove the 20-minute reset rule on regtest, but I suppose we're never going to touch that consensus code.
Done, thanks
Renamed, added description, thanks
Done
Documented it, thanks
ACK
27240dce14tACK
27240dce14Seems rare that a unit test needs the helpers to build such a chain, but this seems fine as a style-cleanup.
review ACK
27240dce14🐁Show signature
Signature:
nit in the last commit: Any reason to reword the comment here? The prior comment was preferable, because it mentioned that in reality this is usually some extranonce space. Also, it had the exact error msg ID, so that a simple
git grepcan be used.nit: Use the shorter
///doxygen for new comments? The/**is inconsistent with the one above and below.nit in
7bb37739db: It seems a bit confusing to phrase this what it doesn't need to be, and then have the reader ask if it must not be the active tip and what else it can be. It would be better and shorter to just say what it can be:..., which may refer to any known prior header.Alternatively, the comment suffix can be removed, because accepting a prev_hash should already clarify that the dev can pass any prev hash here.Also, use
///doxygen comment?second-to-last commit nit: the global
Params()would be good to avoidnit in the first commit: Please try to avoid the globals. There is a
chainman.GetConsensus()same here wrt globals: c.f.
fa1b76aeb0Could also just drop the declaration and make the definition static, if the intention is not for this to be re-used elsewhere.
lgtm
e07fdd2a11😼Show signature
Signature:
5c4209eecb: Two line hunk in the wrong commit?nit in
096875f8f3: Add and use a chainman reference?Thanks, switched to ///. The helper is already used from another test file.
review ACK
b7b762880e🐡Show signature
Signature:
ACK
b7b762880ere-ACK
b7b762880eACK
b7b762880e