Merge bitcoin/bitcoin#36950: test, bench: construct inputs/outputs declaratively in descriptor, bip352, group_outputs and ephemeral spends
What changed, and why it matters
This commit only refactors how test and benchmark code builds Bitcoin transactions. It replaces imperative 'resize then fill' patterns with declarative lists of inputs and outputs. The pull request explicitly states there is no change in behavior, and the diff shows only test/benchmark files being modified in equivalent ways.
No action required. This is a non-functional code-quality refactor in test and benchmark code.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The merge commit updates three files under src/test, src/wallet/test, and src/bench to construct CTxIn/CTxOut vectors using initializer lists and emplace_back loops instead of resize() followed by element mutation. The affected transactions are described as unchanged in behavior. No consensus, wallet, or P2P logic is modified.
Changed components
src/bench/mempool_ephemeral_spends.cppsrc/test/descriptor_tests.cppsrc/wallet/test/group_outputs_tests.cppInspect captured patch +18 / −11
### src/bench/mempool_ephemeral_spends.cpp
@@ -47,7 +47,9 @@ static void MempoolCheckEphemeralSpends(benchmark::Bench& bench)
// Tx with many outputs
CMutableTransaction tx1;
- tx1.vin.resize(1);
+ tx1.vin = {
+ CTxIn{},
+ };
tx1.vout.resize(number_outputs);
for (size_t i = 0; i < tx1.vout.size(); i++) {
// Each output progressively larger
@@ -58,11 +60,13 @@ static void MempoolCheckEphemeralSpends(benchmark::Bench& bench)
// Spends all outputs of tx1, other details don't matter
CMutableTransaction tx2;
- tx2.vin.resize(tx1.vout.size());
- for (uint32_t i{0}; i < tx2.vin.size(); ++i) {
- tx2.vin[i].prevout = COutPoint{parent_txid, i};
+ tx2.vin.reserve(tx1.vout.size());
+ for (uint32_t i{0}; i < tx1.vout.size(); ++i) {
+ tx2.vin.emplace_back(COutPoint{parent_txid, i});
}
- tx2.vout.resize(1);
+ tx2.vout = {
+ CTxOut{},
+ };
CTxMemPool& pool = *Assert(testing_setup->m_node.mempool);
LOCK2(cs_main, pool.cs);
### src/test/descriptor_tests.cpp
@@ -457,9 +457,12 @@ void DoCheck(std::string prv, std::string pub, const std::string& norm_pub, int
if (flags & (SIGNABLE | SIGNABLE_FAILS)) {
CMutableTransaction spend;
spend.nLockTime = spender_nlocktime;
- spend.vin.resize(1);
- spend.vin[0].nSequence = spender_nsequence;
- spend.vout.resize(1);
+ spend.vin = {
+ CTxIn{COutPoint{}, CScript{}, spender_nsequence},
+ };
+ spend.vout = {
+ CTxOut{},
+ };
std::vector<CTxOut> utxos(1);
PrecomputedTransactionData txdata;
txdata.Init(spend, std::move(utxos), /*force=*/true);
### src/wallet/test/group_outputs_tests.cpp
@@ -35,9 +35,9 @@ static void addCoin(CoinsResult& coins,
{
CMutableTransaction tx;
tx.nLockTime = nextLockTime++; // so all transactions get different hashes
- tx.vout.resize(1);
- tx.vout[0].nValue = nValue;
- tx.vout[0].scriptPubKey = GetScriptForDestination(dest);
+ tx.vout = {
+ CTxOut{nValue, GetScriptForDestination(dest)},
+ };
const auto txid{tx.GetHash()};
LOCK(wallet.cs_wallet);Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.