From 8791410662ce3ab7ba6bbe9813c55369edd6e4c9 Mon Sep 17 00:00:00 2001 From: glozow Date: Tue, 13 Dec 2022 16:02:29 +0000 Subject: [test util] randomize fee in PopulateMempool This makes the contents of the mempool more realistic and iterating by ancestor feerate order more meaningful. If transactions have varying feerates, it's also more likely that packages will need to be updated during block template assembly. --- src/test/util/setup_common.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/test/util') diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index a7ca97222a..970b40737a 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -397,15 +397,15 @@ std::vector TestChain100Setup::PopulateMempool(FastRandomContex unspent_prevouts.pop_front(); } const size_t num_outputs = det_rand.randrange(24) + 1; - // Approximately 1000sat "fee," equal output amounts. - const CAmount amount_per_output = (total_in - 1000) / num_outputs; + const CAmount fee = 100 * det_rand.randrange(30); + const CAmount amount_per_output = (total_in - fee) / num_outputs; for (size_t n{0}; n < num_outputs; ++n) { CScript spk = CScript() << CScriptNum(num_transactions + n); mtx.vout.push_back(CTxOut(amount_per_output, spk)); } CTransactionRef ptx = MakeTransactionRef(mtx); mempool_transactions.push_back(ptx); - if (amount_per_output > 2000) { + if (amount_per_output > 3000) { // If the value is high enough to fund another transaction + fees, keep track of it so // it can be used to build a more complex transaction graph. Insert randomly into // unspent_prevouts for extra randomness in the resulting structures. @@ -417,7 +417,9 @@ std::vector TestChain100Setup::PopulateMempool(FastRandomContex if (submit) { LOCK2(m_node.mempool->cs, cs_main); LockPoints lp; - m_node.mempool->addUnchecked(CTxMemPoolEntry(ptx, 1000, 0, 1, false, 4, lp)); + m_node.mempool->addUnchecked(CTxMemPoolEntry(ptx, /*fee=*/(total_in - num_outputs * amount_per_output), + /*time=*/0, /*entry_height=*/1, + /*spends_coinbase=*/false, /*sigops_cost=*/4, lp)); } --num_transactions; } -- cgit v1.2.3