| 223 | } |
| 224 | |
| 225 | void 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 | } |
no test coverage detected