@@ -17,6 +17,7 @@ BOOST_AUTO_TEST_CASE(MempoolRemoveTest)
17
17
{
18
18
// Test CTxMemPool::remove functionality
19
19
20
+ TestMemPoolEntryHelper entry;
20
21
// Parent transaction with three children,
21
22
// and three grand-children:
22
23
CMutableTransaction txParent;
@@ -60,17 +61,17 @@ BOOST_AUTO_TEST_CASE(MempoolRemoveTest)
60
61
BOOST_CHECK_EQUAL (removed.size (), 0 );
61
62
62
63
// Just the parent:
63
- testPool.addUnchecked (txParent.GetHash (), CTxMemPoolEntry (txParent, 0 , 0 , 0.0 , 1 ));
64
+ testPool.addUnchecked (txParent.GetHash (), entry. FromTx (txParent));
64
65
testPool.remove (txParent, removed, true );
65
66
BOOST_CHECK_EQUAL (removed.size (), 1 );
66
67
removed.clear ();
67
68
68
69
// Parent, children, grandchildren:
69
- testPool.addUnchecked (txParent.GetHash (), CTxMemPoolEntry (txParent, 0 , 0 , 0.0 , 1 ));
70
+ testPool.addUnchecked (txParent.GetHash (), entry. FromTx (txParent));
70
71
for (int i = 0 ; i < 3 ; i++)
71
72
{
72
- testPool.addUnchecked (txChild[i].GetHash (), CTxMemPoolEntry (txChild[i], 0 , 0 , 0.0 , 1 ));
73
- testPool.addUnchecked (txGrandChild[i].GetHash (), CTxMemPoolEntry (txGrandChild[i], 0 , 0 , 0.0 , 1 ));
73
+ testPool.addUnchecked (txChild[i].GetHash (), entry. FromTx (txChild[i]));
74
+ testPool.addUnchecked (txGrandChild[i].GetHash (), entry. FromTx (txGrandChild[i]));
74
75
}
75
76
// Remove Child[0], GrandChild[0] should be removed:
76
77
testPool.remove (txChild[0 ], removed, true );
@@ -90,8 +91,8 @@ BOOST_AUTO_TEST_CASE(MempoolRemoveTest)
90
91
// Add children and grandchildren, but NOT the parent (simulate the parent being in a block)
91
92
for (int i = 0 ; i < 3 ; i++)
92
93
{
93
- testPool.addUnchecked (txChild[i].GetHash (), CTxMemPoolEntry (txChild[i], 0 , 0 , 0.0 , 1 ));
94
- testPool.addUnchecked (txGrandChild[i].GetHash (), CTxMemPoolEntry (txGrandChild[i], 0 , 0 , 0.0 , 1 ));
94
+ testPool.addUnchecked (txChild[i].GetHash (), entry. FromTx (txChild[i]));
95
+ testPool.addUnchecked (txGrandChild[i].GetHash (), entry. FromTx (txGrandChild[i]));
95
96
}
96
97
// Now remove the parent, as might happen if a block-re-org occurs but the parent cannot be
97
98
// put into the mempool (maybe because it is non-standard):
@@ -114,41 +115,45 @@ void CheckSort(CTxMemPool &pool, std::vector<std::string> &sortedOrder)
114
115
BOOST_AUTO_TEST_CASE (MempoolIndexingTest)
115
116
{
116
117
CTxMemPool pool (CFeeRate (0 ));
118
+ TestMemPoolEntryHelper entry;
119
+ entry.hadNoDependencies = true ;
117
120
118
121
/* 3rd highest fee */
119
122
CMutableTransaction tx1 = CMutableTransaction ();
120
123
tx1.vout .resize (1 );
121
124
tx1.vout [0 ].scriptPubKey = CScript () << OP_11 << OP_EQUAL;
122
125
tx1.vout [0 ].nValue = 10 * COIN;
123
- pool.addUnchecked (tx1.GetHash (), CTxMemPoolEntry (tx1, 10000LL , 0 , 10.0 , 1 , true ));
126
+ pool.addUnchecked (tx1.GetHash (), entry. Fee ( 10000LL ). Priority ( 10.0 ). FromTx (tx1 ));
124
127
125
128
/* highest fee */
126
129
CMutableTransaction tx2 = CMutableTransaction ();
127
130
tx2.vout .resize (1 );
128
131
tx2.vout [0 ].scriptPubKey = CScript () << OP_11 << OP_EQUAL;
129
132
tx2.vout [0 ].nValue = 2 * COIN;
130
- pool.addUnchecked (tx2.GetHash (), CTxMemPoolEntry (tx2, 20000LL , 0 , 9.0 , 1 , true ));
133
+ pool.addUnchecked (tx2.GetHash (), entry. Fee ( 20000LL ). Priority ( 9.0 ). FromTx (tx2 ));
131
134
132
135
/* lowest fee */
133
136
CMutableTransaction tx3 = CMutableTransaction ();
134
137
tx3.vout .resize (1 );
135
138
tx3.vout [0 ].scriptPubKey = CScript () << OP_11 << OP_EQUAL;
136
139
tx3.vout [0 ].nValue = 5 * COIN;
137
- pool.addUnchecked (tx3.GetHash (), CTxMemPoolEntry (tx3, 0LL , 0 , 100.0 , 1 , true ));
140
+ pool.addUnchecked (tx3.GetHash (), entry. Fee ( 0LL ). Priority ( 100.0 ). FromTx (tx3 ));
138
141
139
142
/* 2nd highest fee */
140
143
CMutableTransaction tx4 = CMutableTransaction ();
141
144
tx4.vout .resize (1 );
142
145
tx4.vout [0 ].scriptPubKey = CScript () << OP_11 << OP_EQUAL;
143
146
tx4.vout [0 ].nValue = 6 * COIN;
144
- pool.addUnchecked (tx4.GetHash (), CTxMemPoolEntry (tx4, 15000LL , 0 , 1.0 , 1 , true ));
147
+ pool.addUnchecked (tx4.GetHash (), entry. Fee ( 15000LL ). Priority ( 1.0 ). FromTx (tx4 ));
145
148
146
149
/* equal fee rate to tx1, but newer */
147
150
CMutableTransaction tx5 = CMutableTransaction ();
148
151
tx5.vout .resize (1 );
149
152
tx5.vout [0 ].scriptPubKey = CScript () << OP_11 << OP_EQUAL;
150
153
tx5.vout [0 ].nValue = 11 * COIN;
151
- pool.addUnchecked (tx5.GetHash (), CTxMemPoolEntry (tx5, 10000LL , 1 , 10.0 , 1 , true ));
154
+ entry.nTime = 1 ;
155
+ entry.dPriority = 10.0 ;
156
+ pool.addUnchecked (tx5.GetHash (), entry.Fee (10000LL ).FromTx (tx5));
152
157
BOOST_CHECK_EQUAL (pool.size (), 5 );
153
158
154
159
std::vector<std::string> sortedOrder;
@@ -166,7 +171,7 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
166
171
tx6.vout .resize (1 );
167
172
tx6.vout [0 ].scriptPubKey = CScript () << OP_11 << OP_EQUAL;
168
173
tx6.vout [0 ].nValue = 20 * COIN;
169
- pool.addUnchecked (tx6.GetHash (), CTxMemPoolEntry (tx6, 0LL , 1 , 10.0 , 1 , true ));
174
+ pool.addUnchecked (tx6.GetHash (), entry. Fee ( 0LL ). FromTx (tx6 ));
170
175
BOOST_CHECK_EQUAL (pool.size (), 6 );
171
176
// Check that at this point, tx6 is sorted low
172
177
sortedOrder.insert (sortedOrder.begin (), tx6.GetHash ().ToString ());
@@ -186,11 +191,10 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
186
191
187
192
CTxMemPool::setEntries setAncestorsCalculated;
188
193
std::string dummy;
189
- CTxMemPoolEntry entry7 (tx7, 2000000LL , 1 , 10.0 , 1 , true );
190
- BOOST_CHECK_EQUAL (pool.CalculateMemPoolAncestors (entry7, setAncestorsCalculated, 100 , 1000000 , 1000 , 1000000 , dummy), true );
194
+ BOOST_CHECK_EQUAL (pool.CalculateMemPoolAncestors (entry.Fee (2000000LL ).FromTx (tx7), setAncestorsCalculated, 100 , 1000000 , 1000 , 1000000 , dummy), true );
191
195
BOOST_CHECK (setAncestorsCalculated == setAncestors);
192
196
193
- pool.addUnchecked (tx7.GetHash (), CTxMemPoolEntry (tx7, 2000000LL , 1 , 10.0 , 1 , true ), setAncestors);
197
+ pool.addUnchecked (tx7.GetHash (), entry. FromTx (tx7), setAncestors);
194
198
BOOST_CHECK_EQUAL (pool.size (), 7 );
195
199
196
200
// Now tx6 should be sorted higher (high fee child): tx7, tx6, tx2, ...
@@ -208,7 +212,7 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
208
212
tx8.vout [0 ].scriptPubKey = CScript () << OP_11 << OP_EQUAL;
209
213
tx8.vout [0 ].nValue = 10 * COIN;
210
214
setAncestors.insert (pool.mapTx .find (tx7.GetHash ()));
211
- pool.addUnchecked (tx8.GetHash (), CTxMemPoolEntry (tx8, 0LL , 2 , 10.0 , 1 , true ), setAncestors);
215
+ pool.addUnchecked (tx8.GetHash (), entry. Fee ( 0LL ). Time ( 2 ). FromTx (tx8 ), setAncestors);
212
216
213
217
// Now tx8 should be sorted low, but tx6/tx both high
214
218
sortedOrder.insert (sortedOrder.begin (), tx8.GetHash ().ToString ());
@@ -222,7 +226,7 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
222
226
tx9.vout .resize (1 );
223
227
tx9.vout [0 ].scriptPubKey = CScript () << OP_11 << OP_EQUAL;
224
228
tx9.vout [0 ].nValue = 1 * COIN;
225
- pool.addUnchecked (tx9.GetHash (), CTxMemPoolEntry (tx9, 0LL , 3 , 10.0 , 1 , true ), setAncestors);
229
+ pool.addUnchecked (tx9.GetHash (), entry. Fee ( 0LL ). Time ( 3 ). FromTx (tx9 ), setAncestors);
226
230
227
231
// tx9 should be sorted low
228
232
BOOST_CHECK_EQUAL (pool.size (), 9 );
@@ -245,11 +249,10 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
245
249
tx10.vout [0 ].nValue = 10 * COIN;
246
250
247
251
setAncestorsCalculated.clear ();
248
- CTxMemPoolEntry entry10 (tx10, 200000LL , 4 , 10.0 , 1 , true );
249
- BOOST_CHECK_EQUAL (pool.CalculateMemPoolAncestors (entry10, setAncestorsCalculated, 100 , 1000000 , 1000 , 1000000 , dummy), true );
252
+ BOOST_CHECK_EQUAL (pool.CalculateMemPoolAncestors (entry.Fee (200000LL ).Time (4 ).FromTx (tx10), setAncestorsCalculated, 100 , 1000000 , 1000 , 1000000 , dummy), true );
250
253
BOOST_CHECK (setAncestorsCalculated == setAncestors);
251
254
252
- pool.addUnchecked (tx10.GetHash (), CTxMemPoolEntry (tx10, 200000LL , 4 , 10.0 , 1 , true ), setAncestors);
255
+ pool.addUnchecked (tx10.GetHash (), entry. FromTx (tx10), setAncestors);
253
256
254
257
/* *
255
258
* tx8 and tx9 should both now be sorted higher
@@ -284,22 +287,24 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
284
287
BOOST_AUTO_TEST_CASE (MempoolSizeLimitTest)
285
288
{
286
289
CTxMemPool pool (CFeeRate (1000 ));
290
+ TestMemPoolEntryHelper entry;
291
+ entry.dPriority = 10.0 ;
287
292
288
293
CMutableTransaction tx1 = CMutableTransaction ();
289
294
tx1.vin .resize (1 );
290
295
tx1.vin [0 ].scriptSig = CScript () << OP_1;
291
296
tx1.vout .resize (1 );
292
297
tx1.vout [0 ].scriptPubKey = CScript () << OP_1 << OP_EQUAL;
293
298
tx1.vout [0 ].nValue = 10 * COIN;
294
- pool.addUnchecked (tx1.GetHash (), CTxMemPoolEntry (tx1, 10000LL , 0 , 10.0 , 1 , pool. HasNoInputsOf (tx1) ));
299
+ pool.addUnchecked (tx1.GetHash (), entry. Fee ( 10000LL ). FromTx (tx1, & pool));
295
300
296
301
CMutableTransaction tx2 = CMutableTransaction ();
297
302
tx2.vin .resize (1 );
298
303
tx2.vin [0 ].scriptSig = CScript () << OP_2;
299
304
tx2.vout .resize (1 );
300
305
tx2.vout [0 ].scriptPubKey = CScript () << OP_2 << OP_EQUAL;
301
306
tx2.vout [0 ].nValue = 10 * COIN;
302
- pool.addUnchecked (tx2.GetHash (), CTxMemPoolEntry (tx2, 5000LL , 0 , 10.0 , 1 , pool. HasNoInputsOf (tx2) ));
307
+ pool.addUnchecked (tx2.GetHash (), entry. Fee ( 5000LL ). FromTx (tx2, & pool));
303
308
304
309
pool.TrimToSize (pool.DynamicMemoryUsage ()); // should do nothing
305
310
BOOST_CHECK (pool.exists (tx1.GetHash ()));
@@ -309,15 +314,15 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest)
309
314
BOOST_CHECK (pool.exists (tx1.GetHash ()));
310
315
BOOST_CHECK (!pool.exists (tx2.GetHash ()));
311
316
312
- pool.addUnchecked (tx2.GetHash (), CTxMemPoolEntry (tx2, 5000LL , 0 , 10.0 , 1 , pool. HasNoInputsOf (tx2) ));
317
+ pool.addUnchecked (tx2.GetHash (), entry. FromTx (tx2, & pool));
313
318
CMutableTransaction tx3 = CMutableTransaction ();
314
319
tx3.vin .resize (1 );
315
320
tx3.vin [0 ].prevout = COutPoint (tx2.GetHash (), 0 );
316
321
tx3.vin [0 ].scriptSig = CScript () << OP_2;
317
322
tx3.vout .resize (1 );
318
323
tx3.vout [0 ].scriptPubKey = CScript () << OP_3 << OP_EQUAL;
319
324
tx3.vout [0 ].nValue = 10 * COIN;
320
- pool.addUnchecked (tx3.GetHash (), CTxMemPoolEntry (tx3, 20000LL , 0 , 10.0 , 1 , pool. HasNoInputsOf (tx3) ));
325
+ pool.addUnchecked (tx3.GetHash (), entry. Fee ( 20000LL ). FromTx (tx3, & pool));
321
326
322
327
pool.TrimToSize (pool.DynamicMemoryUsage () * 3 / 4 ); // tx3 should pay for tx2 (CPFP)
323
328
BOOST_CHECK (!pool.exists (tx1.GetHash ()));
@@ -380,10 +385,10 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest)
380
385
tx7.vout [1 ].scriptPubKey = CScript () << OP_7 << OP_EQUAL;
381
386
tx7.vout [1 ].nValue = 10 * COIN;
382
387
383
- pool.addUnchecked (tx4.GetHash (), CTxMemPoolEntry (tx4, 7000LL , 0 , 10.0 , 1 , pool. HasNoInputsOf (tx4) ));
384
- pool.addUnchecked (tx5.GetHash (), CTxMemPoolEntry (tx5, 1000LL , 0 , 10.0 , 1 , pool. HasNoInputsOf (tx5) ));
385
- pool.addUnchecked (tx6.GetHash (), CTxMemPoolEntry (tx6, 1100LL , 0 , 10.0 , 1 , pool. HasNoInputsOf (tx6) ));
386
- pool.addUnchecked (tx7.GetHash (), CTxMemPoolEntry (tx7, 9000LL , 0 , 10.0 , 1 , pool. HasNoInputsOf (tx7) ));
388
+ pool.addUnchecked (tx4.GetHash (), entry. Fee ( 7000LL ). FromTx (tx4, & pool));
389
+ pool.addUnchecked (tx5.GetHash (), entry. Fee ( 1000LL ). FromTx (tx5, & pool));
390
+ pool.addUnchecked (tx6.GetHash (), entry. Fee ( 1100LL ). FromTx (tx6, & pool));
391
+ pool.addUnchecked (tx7.GetHash (), entry. Fee ( 9000LL ). FromTx (tx7, & pool));
387
392
388
393
// we only require this remove, at max, 2 txn, because its not clear what we're really optimizing for aside from that
389
394
pool.TrimToSize (pool.DynamicMemoryUsage () - 1 );
@@ -392,17 +397,17 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest)
392
397
BOOST_CHECK (!pool.exists (tx7.GetHash ()));
393
398
394
399
if (!pool.exists (tx5.GetHash ()))
395
- pool.addUnchecked (tx5.GetHash (), CTxMemPoolEntry (tx5, 1000LL , 0 , 10.0 , 1 , pool. HasNoInputsOf (tx5) ));
396
- pool.addUnchecked (tx7.GetHash (), CTxMemPoolEntry (tx7, 9000LL , 0 , 10.0 , 1 , pool. HasNoInputsOf (tx7) ));
400
+ pool.addUnchecked (tx5.GetHash (), entry. Fee ( 1000LL ). FromTx (tx5, & pool));
401
+ pool.addUnchecked (tx7.GetHash (), entry. Fee ( 9000LL ). FromTx (tx7, & pool));
397
402
398
403
pool.TrimToSize (pool.DynamicMemoryUsage () / 2 ); // should maximize mempool size by only removing 5/7
399
404
BOOST_CHECK (pool.exists (tx4.GetHash ()));
400
405
BOOST_CHECK (!pool.exists (tx5.GetHash ()));
401
406
BOOST_CHECK (pool.exists (tx6.GetHash ()));
402
407
BOOST_CHECK (!pool.exists (tx7.GetHash ()));
403
408
404
- pool.addUnchecked (tx5.GetHash (), CTxMemPoolEntry (tx5, 1000LL , 0 , 10.0 , 1 , pool. HasNoInputsOf (tx5) ));
405
- pool.addUnchecked (tx7.GetHash (), CTxMemPoolEntry (tx7, 9000LL , 0 , 10.0 , 1 , pool. HasNoInputsOf (tx7) ));
409
+ pool.addUnchecked (tx5.GetHash (), entry. Fee ( 1000LL ). FromTx (tx5, & pool));
410
+ pool.addUnchecked (tx7.GetHash (), entry. Fee ( 9000LL ). FromTx (tx7, & pool));
406
411
407
412
std::vector<CTransaction> vtx;
408
413
std::list<CTransaction> conflicts;
0 commit comments