MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / MockMempoolMinFee

Function MockMempoolMinFee

src/test/util/txmempool.cpp:225–258  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

223}
224
225void MockMempoolMinFee(const CFeeRate& target_feerate, CTxMemPool& mempool)
226{
227 LOCK2(cs_main, mempool.cs);
228 // Transactions in the mempool will affect the new minimum feerate.
229 assert(mempool.size() == 0);
230 // The target feerate cannot be too low...
231 // ...otherwise the transaction's feerate will need to be negative.
232 assert(target_feerate > mempool.m_opts.incremental_relay_feerate);
233 // ...otherwise this is not meaningful. The feerate policy uses the maximum of both feerates.
234 assert(target_feerate > mempool.m_opts.min_relay_feerate);
235
236 // Manually create an invalid transaction. Manually set the fee in the CTxMemPoolEntry to
237 // achieve the exact target feerate.
238 CMutableTransaction mtx{};
239 mtx.vin.emplace_back(COutPoint{Txid::FromUint256(uint256{123}), 0});
240 mtx.vout.emplace_back(1 * COIN, GetScriptForDestination(WitnessV0ScriptHash(CScript() << OP_TRUE)));
241 // Set a large size so that the fee evaluated at target_feerate (which is usually in sats/kvB) is an integer.
242 // Otherwise, GetMinFee() may end up slightly different from target_feerate.
243 BulkTransaction(mtx, 4000);
244 const auto tx{MakeTransactionRef(mtx)};
245 LockPoints lp;
246 // The new mempool min feerate is equal to the removed package's feerate + incremental feerate.
247 const auto tx_fee = target_feerate.GetFee(GetVirtualTransactionSize(*tx)) -
248 mempool.m_opts.incremental_relay_feerate.GetFee(GetVirtualTransactionSize(*tx));
249 {
250 auto changeset = mempool.GetChangeSet();
251 changeset->StageAddition(tx, /*fee=*/tx_fee,
252 /*time=*/0, /*entry_height=*/1, /*entry_sequence=*/0,
253 /*spends_coinbase=*/true, /*sigops_cost=*/1, lp);
254 changeset->Apply();
255 }
256 mempool.TrimToSize(0);
257 assert(mempool.GetMinFee() == target_feerate);
258}

Callers 2

fees.cppFile · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 13

GetScriptForDestinationFunction · 0.85
WitnessV0ScriptHashClass · 0.85
BulkTransactionFunction · 0.85
MakeTransactionRefFunction · 0.85
StageAdditionMethod · 0.80
TrimToSizeMethod · 0.80
CScriptClass · 0.70
sizeMethod · 0.45
emplace_backMethod · 0.45
GetFeeMethod · 0.45
ApplyMethod · 0.45

Tested by

no test coverage detected