aboutsummaryrefslogtreecommitdiff
path: root/src/test/util/setup_common.cpp
diff options
context:
space:
mode:
authorglozow <gloriajzhao@gmail.com>2022-12-13 16:02:29 +0000
committerglozow <gloriajzhao@gmail.com>2022-12-22 11:33:42 +0000
commit8791410662ce3ab7ba6bbe9813c55369edd6e4c9 (patch)
treeac646020daa432c23029840d0946edd179b5d191 /src/test/util/setup_common.cpp
parentcba5934eb697aedbe1966ebc2817ab87232a1b59 (diff)
[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.
Diffstat (limited to 'src/test/util/setup_common.cpp')
-rw-r--r--src/test/util/setup_common.cpp10
1 files changed, 6 insertions, 4 deletions
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<CTransactionRef> 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<CTransactionRef> 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;
}