@@ -432,6 +432,33 @@ std::vector<CTransactionRef> TestChain100Setup::PopulateMempool(FastRandomContex
432
432
return mempool_transactions;
433
433
}
434
434
435
+ void TestChain100Setup::MockMempoolMinFee (const CFeeRate& target_feerate)
436
+ {
437
+ LOCK2 (cs_main, m_node.mempool ->cs );
438
+ // Transactions in the mempool will affect the new minimum feerate.
439
+ assert (m_node.mempool ->size () == 0 );
440
+ // The target feerate cannot be too low...
441
+ // ...otherwise the transaction's feerate will need to be negative.
442
+ assert (target_feerate > m_node.mempool ->m_incremental_relay_feerate );
443
+ // ...otherwise this is not meaningful. The feerate policy uses the maximum of both feerates.
444
+ assert (target_feerate > m_node.mempool ->m_min_relay_feerate );
445
+
446
+ // Manually create an invalid transaction. Manually set the fee in the CTxMemPoolEntry to
447
+ // achieve the exact target feerate.
448
+ CMutableTransaction mtx = CMutableTransaction ();
449
+ mtx.vin .push_back (CTxIn{COutPoint{g_insecure_rand_ctx.rand256 (), 0 }});
450
+ mtx.vout .push_back (CTxOut (1 * COIN, GetScriptForDestination (WitnessV0ScriptHash (CScript () << OP_TRUE))));
451
+ const auto tx{MakeTransactionRef (mtx)};
452
+ LockPoints lp;
453
+ // The new mempool min feerate is equal to the removed package's feerate + incremental feerate.
454
+ const auto tx_fee = target_feerate.GetFee (GetVirtualTransactionSize (*tx)) -
455
+ m_node.mempool ->m_incremental_relay_feerate .GetFee (GetVirtualTransactionSize (*tx));
456
+ m_node.mempool ->addUnchecked (CTxMemPoolEntry (tx, /* fee=*/ tx_fee,
457
+ /* time=*/ 0 , /* entry_height=*/ 1 ,
458
+ /* spends_coinbase=*/ true , /* sigops_cost=*/ 1 , lp));
459
+ m_node.mempool ->TrimToSize (0 );
460
+ assert (m_node.mempool ->GetMinFee () == target_feerate);
461
+ }
435
462
/* *
436
463
* @returns a real block (0000000000013b8ab2cd513b0261a14096412195a72a0c4827d229dcc7e0f7af)
437
464
* with 9 txs.
0 commit comments