Skip to content

Commit a0079d4

Browse files
author
MarcoFalke
committed
Merge #13013: bench: Amend mempool_eviction test for witness txs
fa3bb18 bench: Amend mempool_eviction test for witness txs (MarcoFalke) 962d223 bench: Move constructors out of mempool_eviction hot loop (MarcoFalke) Pull request description: Tree-SHA512: 997a07e067623bc2c0904a21bd490d164045cf51393af260fc79882ed010636dce82c9ebe35aae8fa5db5e73c9f3ecb6232353a0939c295034f9be574f1fcff2
2 parents 476cb35 + fa3bb18 commit a0079d4

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

src/bench/mempool_eviction.cpp

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
#include <list>
1010
#include <vector>
1111

12-
static void AddTx(const CMutableTransaction& tx, const CAmount& nFee, CTxMemPool& pool)
12+
static void AddTx(const CTransactionRef& tx, const CAmount& nFee, CTxMemPool& pool)
1313
{
1414
int64_t nTime = 0;
1515
unsigned int nHeight = 1;
1616
bool spendsCoinbase = false;
1717
unsigned int sigOpCost = 4;
1818
LockPoints lp;
19-
pool.addUnchecked(tx.GetHash(), CTxMemPoolEntry(
20-
MakeTransactionRef(tx), nFee, nTime, nHeight,
21-
spendsCoinbase, sigOpCost, lp));
19+
pool.addUnchecked(tx->GetHash(), CTxMemPoolEntry(
20+
tx, nFee, nTime, nHeight,
21+
spendsCoinbase, sigOpCost, lp));
2222
}
2323

2424
// Right now this is only testing eviction performance in an extremely small
@@ -29,13 +29,15 @@ static void MempoolEviction(benchmark::State& state)
2929
CMutableTransaction tx1 = CMutableTransaction();
3030
tx1.vin.resize(1);
3131
tx1.vin[0].scriptSig = CScript() << OP_1;
32+
tx1.vin[0].scriptWitness.stack.push_back({1});
3233
tx1.vout.resize(1);
3334
tx1.vout[0].scriptPubKey = CScript() << OP_1 << OP_EQUAL;
3435
tx1.vout[0].nValue = 10 * COIN;
3536

3637
CMutableTransaction tx2 = CMutableTransaction();
3738
tx2.vin.resize(1);
3839
tx2.vin[0].scriptSig = CScript() << OP_2;
40+
tx2.vin[0].scriptWitness.stack.push_back({2});
3941
tx2.vout.resize(1);
4042
tx2.vout[0].scriptPubKey = CScript() << OP_2 << OP_EQUAL;
4143
tx2.vout[0].nValue = 10 * COIN;
@@ -44,6 +46,7 @@ static void MempoolEviction(benchmark::State& state)
4446
tx3.vin.resize(1);
4547
tx3.vin[0].prevout = COutPoint(tx2.GetHash(), 0);
4648
tx3.vin[0].scriptSig = CScript() << OP_2;
49+
tx3.vin[0].scriptWitness.stack.push_back({3});
4750
tx3.vout.resize(1);
4851
tx3.vout[0].scriptPubKey = CScript() << OP_3 << OP_EQUAL;
4952
tx3.vout[0].nValue = 10 * COIN;
@@ -52,8 +55,10 @@ static void MempoolEviction(benchmark::State& state)
5255
tx4.vin.resize(2);
5356
tx4.vin[0].prevout.SetNull();
5457
tx4.vin[0].scriptSig = CScript() << OP_4;
58+
tx4.vin[0].scriptWitness.stack.push_back({4});
5559
tx4.vin[1].prevout.SetNull();
5660
tx4.vin[1].scriptSig = CScript() << OP_4;
61+
tx4.vin[1].scriptWitness.stack.push_back({4});
5762
tx4.vout.resize(2);
5863
tx4.vout[0].scriptPubKey = CScript() << OP_4 << OP_EQUAL;
5964
tx4.vout[0].nValue = 10 * COIN;
@@ -64,8 +69,10 @@ static void MempoolEviction(benchmark::State& state)
6469
tx5.vin.resize(2);
6570
tx5.vin[0].prevout = COutPoint(tx4.GetHash(), 0);
6671
tx5.vin[0].scriptSig = CScript() << OP_4;
72+
tx5.vin[0].scriptWitness.stack.push_back({4});
6773
tx5.vin[1].prevout.SetNull();
6874
tx5.vin[1].scriptSig = CScript() << OP_5;
75+
tx5.vin[1].scriptWitness.stack.push_back({5});
6976
tx5.vout.resize(2);
7077
tx5.vout[0].scriptPubKey = CScript() << OP_5 << OP_EQUAL;
7178
tx5.vout[0].nValue = 10 * COIN;
@@ -76,8 +83,10 @@ static void MempoolEviction(benchmark::State& state)
7683
tx6.vin.resize(2);
7784
tx6.vin[0].prevout = COutPoint(tx4.GetHash(), 1);
7885
tx6.vin[0].scriptSig = CScript() << OP_4;
86+
tx6.vin[0].scriptWitness.stack.push_back({4});
7987
tx6.vin[1].prevout.SetNull();
8088
tx6.vin[1].scriptSig = CScript() << OP_6;
89+
tx6.vin[1].scriptWitness.stack.push_back({6});
8190
tx6.vout.resize(2);
8291
tx6.vout[0].scriptPubKey = CScript() << OP_6 << OP_EQUAL;
8392
tx6.vout[0].nValue = 10 * COIN;
@@ -88,24 +97,34 @@ static void MempoolEviction(benchmark::State& state)
8897
tx7.vin.resize(2);
8998
tx7.vin[0].prevout = COutPoint(tx5.GetHash(), 0);
9099
tx7.vin[0].scriptSig = CScript() << OP_5;
100+
tx7.vin[0].scriptWitness.stack.push_back({5});
91101
tx7.vin[1].prevout = COutPoint(tx6.GetHash(), 0);
92102
tx7.vin[1].scriptSig = CScript() << OP_6;
103+
tx7.vin[1].scriptWitness.stack.push_back({6});
93104
tx7.vout.resize(2);
94105
tx7.vout[0].scriptPubKey = CScript() << OP_7 << OP_EQUAL;
95106
tx7.vout[0].nValue = 10 * COIN;
96107
tx7.vout[1].scriptPubKey = CScript() << OP_7 << OP_EQUAL;
97108
tx7.vout[1].nValue = 10 * COIN;
98109

99110
CTxMemPool pool;
111+
// Create transaction references outside the "hot loop"
112+
const CTransactionRef tx1_r{MakeTransactionRef(tx1)};
113+
const CTransactionRef tx2_r{MakeTransactionRef(tx2)};
114+
const CTransactionRef tx3_r{MakeTransactionRef(tx3)};
115+
const CTransactionRef tx4_r{MakeTransactionRef(tx4)};
116+
const CTransactionRef tx5_r{MakeTransactionRef(tx5)};
117+
const CTransactionRef tx6_r{MakeTransactionRef(tx6)};
118+
const CTransactionRef tx7_r{MakeTransactionRef(tx7)};
100119

101120
while (state.KeepRunning()) {
102-
AddTx(tx1, 10000LL, pool);
103-
AddTx(tx2, 5000LL, pool);
104-
AddTx(tx3, 20000LL, pool);
105-
AddTx(tx4, 7000LL, pool);
106-
AddTx(tx5, 1000LL, pool);
107-
AddTx(tx6, 1100LL, pool);
108-
AddTx(tx7, 9000LL, pool);
121+
AddTx(tx1_r, 10000LL, pool);
122+
AddTx(tx2_r, 5000LL, pool);
123+
AddTx(tx3_r, 20000LL, pool);
124+
AddTx(tx4_r, 7000LL, pool);
125+
AddTx(tx5_r, 1000LL, pool);
126+
AddTx(tx6_r, 1100LL, pool);
127+
AddTx(tx7_r, 9000LL, pool);
109128
pool.TrimToSize(pool.DynamicMemoryUsage() * 3 / 4);
110129
pool.TrimToSize(GetVirtualTransactionSize(tx1));
111130
}

0 commit comments

Comments
 (0)