Skip to content

Commit 8791410

Browse files
committed
[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.
1 parent cba5934 commit 8791410

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/test/util/setup_common.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,15 +397,15 @@ std::vector<CTransactionRef> TestChain100Setup::PopulateMempool(FastRandomContex
397397
unspent_prevouts.pop_front();
398398
}
399399
const size_t num_outputs = det_rand.randrange(24) + 1;
400-
// Approximately 1000sat "fee," equal output amounts.
401-
const CAmount amount_per_output = (total_in - 1000) / num_outputs;
400+
const CAmount fee = 100 * det_rand.randrange(30);
401+
const CAmount amount_per_output = (total_in - fee) / num_outputs;
402402
for (size_t n{0}; n < num_outputs; ++n) {
403403
CScript spk = CScript() << CScriptNum(num_transactions + n);
404404
mtx.vout.push_back(CTxOut(amount_per_output, spk));
405405
}
406406
CTransactionRef ptx = MakeTransactionRef(mtx);
407407
mempool_transactions.push_back(ptx);
408-
if (amount_per_output > 2000) {
408+
if (amount_per_output > 3000) {
409409
// If the value is high enough to fund another transaction + fees, keep track of it so
410410
// it can be used to build a more complex transaction graph. Insert randomly into
411411
// unspent_prevouts for extra randomness in the resulting structures.
@@ -417,7 +417,9 @@ std::vector<CTransactionRef> TestChain100Setup::PopulateMempool(FastRandomContex
417417
if (submit) {
418418
LOCK2(m_node.mempool->cs, cs_main);
419419
LockPoints lp;
420-
m_node.mempool->addUnchecked(CTxMemPoolEntry(ptx, 1000, 0, 1, false, 4, lp));
420+
m_node.mempool->addUnchecked(CTxMemPoolEntry(ptx, /*fee=*/(total_in - num_outputs * amount_per_output),
421+
/*time=*/0, /*entry_height=*/1,
422+
/*spends_coinbase=*/false, /*sigops_cost=*/4, lp));
421423
}
422424
--num_transactions;
423425
}

0 commit comments

Comments
 (0)