mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
[test util] mock mempool minimum feerate
This commit is contained in:
@@ -432,6 +432,33 @@ std::vector<CTransactionRef> TestChain100Setup::PopulateMempool(FastRandomContex
|
||||
return mempool_transactions;
|
||||
}
|
||||
|
||||
void TestChain100Setup::MockMempoolMinFee(const CFeeRate& target_feerate)
|
||||
{
|
||||
LOCK2(cs_main, m_node.mempool->cs);
|
||||
// Transactions in the mempool will affect the new minimum feerate.
|
||||
assert(m_node.mempool->size() == 0);
|
||||
// The target feerate cannot be too low...
|
||||
// ...otherwise the transaction's feerate will need to be negative.
|
||||
assert(target_feerate > m_node.mempool->m_incremental_relay_feerate);
|
||||
// ...otherwise this is not meaningful. The feerate policy uses the maximum of both feerates.
|
||||
assert(target_feerate > m_node.mempool->m_min_relay_feerate);
|
||||
|
||||
// Manually create an invalid transaction. Manually set the fee in the CTxMemPoolEntry to
|
||||
// achieve the exact target feerate.
|
||||
CMutableTransaction mtx = CMutableTransaction();
|
||||
mtx.vin.push_back(CTxIn{COutPoint{g_insecure_rand_ctx.rand256(), 0}});
|
||||
mtx.vout.push_back(CTxOut(1 * COIN, GetScriptForDestination(WitnessV0ScriptHash(CScript() << OP_TRUE))));
|
||||
const auto tx{MakeTransactionRef(mtx)};
|
||||
LockPoints lp;
|
||||
// The new mempool min feerate is equal to the removed package's feerate + incremental feerate.
|
||||
const auto tx_fee = target_feerate.GetFee(GetVirtualTransactionSize(*tx)) -
|
||||
m_node.mempool->m_incremental_relay_feerate.GetFee(GetVirtualTransactionSize(*tx));
|
||||
m_node.mempool->addUnchecked(CTxMemPoolEntry(tx, /*fee=*/tx_fee,
|
||||
/*time=*/0, /*entry_height=*/1,
|
||||
/*spends_coinbase=*/true, /*sigops_cost=*/1, lp));
|
||||
m_node.mempool->TrimToSize(0);
|
||||
assert(m_node.mempool->GetMinFee() == target_feerate);
|
||||
}
|
||||
/**
|
||||
* @returns a real block (0000000000013b8ab2cd513b0261a14096412195a72a0c4827d229dcc7e0f7af)
|
||||
* with 9 txs.
|
||||
|
||||
Reference in New Issue
Block a user