diff --git a/src/bench/mempool_eviction.cpp b/src/bench/mempool_eviction.cpp --- a/src/bench/mempool_eviction.cpp +++ b/src/bench/mempool_eviction.cpp @@ -9,7 +9,7 @@ #include #include -static void AddTx(const CTransaction &tx, const Amount &nFee, +static void AddTx(const CTransactionRef &tx, const Amount &nFee, CTxMemPool &pool) { int64_t nTime = 0; double dPriority = 10.0; @@ -17,10 +17,10 @@ bool spendsCoinbase = false; unsigned int sigOpCost = 4; LockPoints lp; - pool.addUnchecked(tx.GetId(), - CTxMemPoolEntry(MakeTransactionRef(tx), nFee, nTime, - dPriority, nHeight, tx.GetValueOut(), - spendsCoinbase, sigOpCost, lp)); + pool.addUnchecked(tx->GetId(), + CTxMemPoolEntry(tx, nFee, nTime, dPriority, nHeight, + tx->GetValueOut(), spendsCoinbase, + sigOpCost, lp)); } // Right now this is only testing eviction performance in an extremely small @@ -99,24 +99,25 @@ CTxMemPool pool; - CTransaction t1(tx1); - CTransaction t2(tx2); - CTransaction t3(tx3); - CTransaction t4(tx4); - CTransaction t5(tx5); - CTransaction t6(tx6); - CTransaction t7(tx1); + // Create transaction references outside the "hot loop" + const CTransactionRef tx1_r{MakeTransactionRef(tx1)}; + const CTransactionRef tx2_r{MakeTransactionRef(tx2)}; + const CTransactionRef tx3_r{MakeTransactionRef(tx3)}; + const CTransactionRef tx4_r{MakeTransactionRef(tx4)}; + const CTransactionRef tx5_r{MakeTransactionRef(tx5)}; + const CTransactionRef tx6_r{MakeTransactionRef(tx6)}; + const CTransactionRef tx7_r{MakeTransactionRef(tx7)}; while (state.KeepRunning()) { - AddTx(t1, 10000 * SATOSHI, pool); - AddTx(t2, 5000 * SATOSHI, pool); - AddTx(t3, 20000 * SATOSHI, pool); - AddTx(t4, 7000 * SATOSHI, pool); - AddTx(t5, 1000 * SATOSHI, pool); - AddTx(t6, 1100 * SATOSHI, pool); - AddTx(t7, 9000 * SATOSHI, pool); + AddTx(tx1_r, 10000 * SATOSHI, pool); + AddTx(tx2_r, 5000 * SATOSHI, pool); + AddTx(tx3_r, 20000 * SATOSHI, pool); + AddTx(tx4_r, 7000 * SATOSHI, pool); + AddTx(tx5_r, 1000 * SATOSHI, pool); + AddTx(tx6_r, 1100 * SATOSHI, pool); + AddTx(tx7_r, 9000 * SATOSHI, pool); pool.TrimToSize(pool.DynamicMemoryUsage() * 3 / 4); - pool.TrimToSize(t1.GetTotalSize()); + pool.TrimToSize(GetVirtualTransactionSize(*tx1_r)); } }