9
9
#include < list>
10
10
#include < vector>
11
11
12
- static void AddTx (const CMutableTransaction & tx, const CAmount& nFee, CTxMemPool& pool)
12
+ static void AddTx (const CTransactionRef & tx, const CAmount& nFee, CTxMemPool& pool)
13
13
{
14
14
int64_t nTime = 0 ;
15
15
unsigned int nHeight = 1 ;
16
16
bool spendsCoinbase = false ;
17
17
unsigned int sigOpCost = 4 ;
18
18
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));
22
22
}
23
23
24
24
// Right now this is only testing eviction performance in an extremely small
@@ -29,13 +29,15 @@ static void MempoolEviction(benchmark::State& state)
29
29
CMutableTransaction tx1 = CMutableTransaction ();
30
30
tx1.vin .resize (1 );
31
31
tx1.vin [0 ].scriptSig = CScript () << OP_1;
32
+ tx1.vin [0 ].scriptWitness .stack .push_back ({1 });
32
33
tx1.vout .resize (1 );
33
34
tx1.vout [0 ].scriptPubKey = CScript () << OP_1 << OP_EQUAL;
34
35
tx1.vout [0 ].nValue = 10 * COIN;
35
36
36
37
CMutableTransaction tx2 = CMutableTransaction ();
37
38
tx2.vin .resize (1 );
38
39
tx2.vin [0 ].scriptSig = CScript () << OP_2;
40
+ tx2.vin [0 ].scriptWitness .stack .push_back ({2 });
39
41
tx2.vout .resize (1 );
40
42
tx2.vout [0 ].scriptPubKey = CScript () << OP_2 << OP_EQUAL;
41
43
tx2.vout [0 ].nValue = 10 * COIN;
@@ -44,6 +46,7 @@ static void MempoolEviction(benchmark::State& state)
44
46
tx3.vin .resize (1 );
45
47
tx3.vin [0 ].prevout = COutPoint (tx2.GetHash (), 0 );
46
48
tx3.vin [0 ].scriptSig = CScript () << OP_2;
49
+ tx3.vin [0 ].scriptWitness .stack .push_back ({3 });
47
50
tx3.vout .resize (1 );
48
51
tx3.vout [0 ].scriptPubKey = CScript () << OP_3 << OP_EQUAL;
49
52
tx3.vout [0 ].nValue = 10 * COIN;
@@ -52,8 +55,10 @@ static void MempoolEviction(benchmark::State& state)
52
55
tx4.vin .resize (2 );
53
56
tx4.vin [0 ].prevout .SetNull ();
54
57
tx4.vin [0 ].scriptSig = CScript () << OP_4;
58
+ tx4.vin [0 ].scriptWitness .stack .push_back ({4 });
55
59
tx4.vin [1 ].prevout .SetNull ();
56
60
tx4.vin [1 ].scriptSig = CScript () << OP_4;
61
+ tx4.vin [1 ].scriptWitness .stack .push_back ({4 });
57
62
tx4.vout .resize (2 );
58
63
tx4.vout [0 ].scriptPubKey = CScript () << OP_4 << OP_EQUAL;
59
64
tx4.vout [0 ].nValue = 10 * COIN;
@@ -64,8 +69,10 @@ static void MempoolEviction(benchmark::State& state)
64
69
tx5.vin .resize (2 );
65
70
tx5.vin [0 ].prevout = COutPoint (tx4.GetHash (), 0 );
66
71
tx5.vin [0 ].scriptSig = CScript () << OP_4;
72
+ tx5.vin [0 ].scriptWitness .stack .push_back ({4 });
67
73
tx5.vin [1 ].prevout .SetNull ();
68
74
tx5.vin [1 ].scriptSig = CScript () << OP_5;
75
+ tx5.vin [1 ].scriptWitness .stack .push_back ({5 });
69
76
tx5.vout .resize (2 );
70
77
tx5.vout [0 ].scriptPubKey = CScript () << OP_5 << OP_EQUAL;
71
78
tx5.vout [0 ].nValue = 10 * COIN;
@@ -76,8 +83,10 @@ static void MempoolEviction(benchmark::State& state)
76
83
tx6.vin .resize (2 );
77
84
tx6.vin [0 ].prevout = COutPoint (tx4.GetHash (), 1 );
78
85
tx6.vin [0 ].scriptSig = CScript () << OP_4;
86
+ tx6.vin [0 ].scriptWitness .stack .push_back ({4 });
79
87
tx6.vin [1 ].prevout .SetNull ();
80
88
tx6.vin [1 ].scriptSig = CScript () << OP_6;
89
+ tx6.vin [1 ].scriptWitness .stack .push_back ({6 });
81
90
tx6.vout .resize (2 );
82
91
tx6.vout [0 ].scriptPubKey = CScript () << OP_6 << OP_EQUAL;
83
92
tx6.vout [0 ].nValue = 10 * COIN;
@@ -88,24 +97,34 @@ static void MempoolEviction(benchmark::State& state)
88
97
tx7.vin .resize (2 );
89
98
tx7.vin [0 ].prevout = COutPoint (tx5.GetHash (), 0 );
90
99
tx7.vin [0 ].scriptSig = CScript () << OP_5;
100
+ tx7.vin [0 ].scriptWitness .stack .push_back ({5 });
91
101
tx7.vin [1 ].prevout = COutPoint (tx6.GetHash (), 0 );
92
102
tx7.vin [1 ].scriptSig = CScript () << OP_6;
103
+ tx7.vin [1 ].scriptWitness .stack .push_back ({6 });
93
104
tx7.vout .resize (2 );
94
105
tx7.vout [0 ].scriptPubKey = CScript () << OP_7 << OP_EQUAL;
95
106
tx7.vout [0 ].nValue = 10 * COIN;
96
107
tx7.vout [1 ].scriptPubKey = CScript () << OP_7 << OP_EQUAL;
97
108
tx7.vout [1 ].nValue = 10 * COIN;
98
109
99
110
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)};
100
119
101
120
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);
109
128
pool.TrimToSize (pool.DynamicMemoryUsage () * 3 / 4 );
110
129
pool.TrimToSize (GetVirtualTransactionSize (tx1));
111
130
}
0 commit comments