mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:50:37 +00:00
test, bench: construct inputs/outputs declaratively in context-dependent cases #36606
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!36606
Loading…
Reference in a new issue
No description provided.
Delete branch "transaction_utils-declarative"
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?
Part of https://github.com/bitcoin/bitcoin/issues/36692 (previously discussed in https://github.com/bitcoin/bitcoin/pull/35994): replace procedural, field-by-field construction of
COutPoint,CTxInandCTxOutin test code with constructor calls.This PR covers cases that are context-dependent and need manual changes, independent of a scripted-diff for the trivial bulk:
test/util/transaction_utils: inBuildSpendingTransaction, thescriptWitnessassignment has to be moved aftervinis replaced, otherwise the witness is dropped.test/util/mining: inCreateBlockChain, the coinbase input's fields were split by the output assignments, with comments that are now kept next to the constructor arguments.sigopcount_tests:BuildTxshas the same witness ordering issue asBuildSpendingTransaction.bench/ccoins_caching: ThescriptSigs are built with<<appends, and the second output was created byvout.resize(2)but never assigned, so it is kept as a nullCTxOut{}.transaction_tests:test_Getbuilds the same transaction asbench/ccoins_caching, with the same<<appends and null second output.This change is test- and bench-only and does not change the constructed transactions.
Notes for reviewers:
CTxInhas no witness constructor argument, soscriptWitnessis assigned aftervinis replaced.BuildTxsis called repeatedly on the same transaction objects. Previously,resize(1)kept the existing inputs and only overwrote some of their fields; now they are replaced entirely. The fields that were left untouched byBuildTxsare never modified by the test, so the transactions are unchanged.ccoins_cachingis copied fromtest_Getintransaction_testsand looks like an oversight. It is kept here to avoid behaviour changes.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:
CAmounta class by hodlinator)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.
I found no actionable issues in this static review.
Previous findings
Resolved findings
[Suggestion · resolved] Explain why the second output remains null
Before this change,
resize(2)created a default second output, and only index 0 was assigned.CTxOut{}preserves that null output, but the reason is not apparent from the initializer. Please add a brief comment here and at the matchingtest_Getinitializer explaining that this preserves the prior fixture, so the output is not mistaken for an accidental placeholder.Location:
src/bench/ccoins_caching.cpp:42(head).No longer considered actionable. First reported at
37681c15fcd3190a14f5f0f33962b5cc8ae1179a. Last checked atbdf58dd89cc2fe2f0be5ac63755e821661022be6. Both initializers still have a bareCTxOut{}with no comment. However, the source disproves the finding's premise: that the null output is a meaningful part of the fixture, and that mistaking it for an accidental placeholder would matter.In the benchmark and in
test_Get, the only thing that uses t1 isValidateInputsStandardness. That function, and theCheckSigopsBIP54it calls, read onlytx.vin(throughIsCoinBase) and the coin entries for those prevouts. They never readtx.vout. The second output therefore cannot affect the assertion intest_Getor the timed benchmark body. The PR description itself calls it a likely oversight that is kept only so the transaction stays byte-identical. A comment presenting it as a deliberate fixture element would be inaccurate, and reading it as an accidental leftover is correct.unchangedis false because theCTxOut{}literal is new code in this PR (the base produced the same output implicitly throughresize(2)).unchanged_since_reportis false because the status is no longerstill_present. No author reply addresses this finding.Reviewed:
bdf58dd89cc2· Full review report · Previous reportsSeems fine, but what is the great picture here:
vin, then another commit forvout?vin.resize(1)and thenvin[0].<_> = <_>? Or would that be not worth it?)Thanks for the feedback!
Rough numbers: 593 lines assign individual fields via vin[...]/vout[...] across 50 files. The largest are: transaction_tests (122), miner_tests (90), script_p2sh_tests (72), mempool_tests (58) and bench/mempool_eviction (38).
Single commits per file seems more intuitive to me, but happy to take a different approach.
The script would need to reorder fields into constructor arguments, fill in defaults, and handle
<<appends, and it can't preserve interleaved comments. I chosetransaction_utilsbecause it's where the mechanical rewrite in #35994 went wrong:BuildSpendingTransactionassignedscriptWitnessbeforevinwas replaced, which dropped the witness. That shows context matters, which is why I would do it manually.What do you think?
I am mostly thinking that 50 pulls/commits for this won't scale/review. My preference would be to just handle the trivial bulk of the changes with a trivial scripted-diff (that is, excluding the transformations that have lines in-between).
Then, the tedious transformations can be done manually later, hopefully being a small amount of line changes.
Happy to create an alternative pull to show it.
Sounds good.
@maflcko I've added four more commits covering cases that need manual work regardless of the scripted-diff.
I've marked this ready for review, since these are independent of the trivial bulk. Happy to rebase on top of your change if that lands first.
This PR is a prime example of why I think Core needs a different development process, where a plan is decided before work starts. Assuming we had agreed on the plan that bitcoin's vocabulary types shall be made immutable. Then the review of this PR would be trivial:
ACK
4da6b9af11We need to reverse the approach where people are discouraged from opening PRs and encouraged to build a reputation through making code reviews. I know that reviews in the current process are a bottleneck, but the assumption that we can solve it with more reviewers is naive. Imagine a carpentry shop where apprentices watch the master at work and are supposed to weigh in with comments.
We need to agree on a plan and then let people work on it in small increments. Such increments are easy to review (example above) and should allow timely integration, which gives a motivating boost to continue and may attract more developers. This process scales way better than opening PRs containing hundreds of commits or offering contributors an "alternative pull".
nit: I find this harder to read. I think all vector assignments here should have an init-list with a trailing comma (even for N=1). Previously, it was easy to see there are two outputs, now one has to manually parse this line and count the commas. Also, appending more elements in the future is easier with line-broken init-lists.
Ok, fair enough. I took a look at a scripted-diff, but I couldn't find a common pattern. (There is
<<vs=, skipped fields, random orders, etc) So manual review will be needed anyway on a case-by-case basis.Done - thanks!
Thanks for taking a look. For the remaining cases I’ll group several files per PR. Let me know if you have a preference for how to group them.
Happy to re-ack the nits, or leave as-is, up to you.
review ACK
e7320faded🌸Show signature
Signature:
nit in
3a0318af87: The commit message says "fields" (plural), but I think this should be singular? Maybe just list the field (or fields) by name in the msg?ed16701f14: Why add a redundant comment that wasn't there before?nit in all commits: I think those can be
CScript{}(with the C++11 braces)Removed - thanks!
Done - thanks!
I tried to clarify in the new commit message.
only change is addressing the nits.
review ACK
bdf58dd89c🍠Show signature
Signature:
My preferred approach would be:
github.com/purpleKarrot/bitcoin@3468ff6401andgithub.com/purpleKarrot/bitcoin@143edb6ac6CTransaction):github.com/purpleKarrot/bitcoin@929bdaad8dBut even when the approach does not follow the steps 1 and 2, it is a step in the right direction, hence ACK
bdf58dd89c