Bitcoin Core 32.99.0
P2P Digital Currency
Loading...
Searching...
No Matches
rbf_tests.cpp
Go to the documentation of this file.
1// Copyright (c) 2021-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4#include <common/system.h>
5#include <policy/rbf.h>
6#include <random.h>
8#include <txmempool.h>
9#include <util/time.h>
10
11#include <test/util/common.h>
13
14#include <boost/test/unit_test.hpp>
15#include <optional>
16#include <vector>
17
19
22{
24 tx.vin.resize(inputs.size());
25 tx.vout.resize(output_values.size());
26 for (size_t i = 0; i < inputs.size(); ++i) {
27 tx.vin[i].prevout.hash = inputs[i]->GetHash();
28 tx.vin[i].prevout.n = 0;
29 // Add a witness so wtxid != txid
30 CScriptWitness witness;
31 witness.stack.emplace_back(i + 10);
32 tx.vin[i].scriptWitness = witness;
33 }
34 for (size_t i = 0; i < output_values.size(); ++i) {
35 tx.vout[i].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
36 tx.vout[i].nValue = output_values[i];
37 }
38 return MakeTransactionRef(tx);
39}
40
43{
45 AssertLockHeld(pool.cs);
47 // Assumes this isn't already spent in mempool
48 auto tx_to_spend = tx;
49 for (int32_t i{0}; i < num_descendants; ++i) {
50 auto next_tx = make_tx(/*inputs=*/{tx_to_spend}, /*output_values=*/{(50 - i) * CENT});
51 TryAddToMempool(pool, entry.FromTx(next_tx));
52 BOOST_CHECK(pool.GetIter(next_tx->GetHash()).has_value());
54 }
55 // Return last created tx
56 return tx_to_spend;
57}
58
60{
62 LOCK2(::cs_main, pool.cs);
64
65 const CAmount low_fee{CENT/100};
66 const CAmount normal_fee{CENT/10};
67 const CAmount high_fee{CENT};
68
69 // Create a parent tx1 and child tx2 with normal fees:
70 const auto tx1 = make_tx(/*inputs=*/ {m_coinbase_txns[0]}, /*output_values=*/ {10 * COIN});
72 const auto tx2 = make_tx(/*inputs=*/ {tx1}, /*output_values=*/ {995 * CENT});
74
75 // Create a low-feerate parent tx3 and high-feerate child tx4 (cpfp)
76 const auto tx3 = make_tx(/*inputs=*/ {m_coinbase_txns[1]}, /*output_values=*/ {1099 * CENT});
77 TryAddToMempool(pool, entry.Fee(low_fee).FromTx(tx3));
78 const auto tx4 = make_tx(/*inputs=*/ {tx3}, /*output_values=*/ {999 * CENT});
79 TryAddToMempool(pool, entry.Fee(high_fee).FromTx(tx4));
80
81 // Create a parent tx5 and child tx6 where both have very low fees
82 const auto tx5 = make_tx(/*inputs=*/ {m_coinbase_txns[2]}, /*output_values=*/ {1099 * CENT});
83 TryAddToMempool(pool, entry.Fee(low_fee).FromTx(tx5));
84 const auto tx6 = make_tx(/*inputs=*/ {tx5}, /*output_values=*/ {1098 * CENT});
85 TryAddToMempool(pool, entry.Fee(low_fee).FromTx(tx6));
86 // Make tx6's modified fee much higher than its base fee. This should cause it to pass
87 // the fee-related checks despite being low-feerate.
88 pool.PrioritiseTransaction(tx6->GetHash(), 1 * COIN);
89
90 // Two independent high-feerate transactions, tx7 and tx8
91 const auto tx7 = make_tx(/*inputs=*/ {m_coinbase_txns[3]}, /*output_values=*/ {999 * CENT});
92 TryAddToMempool(pool, entry.Fee(high_fee).FromTx(tx7));
93 const auto tx8 = make_tx(/*inputs=*/ {m_coinbase_txns[4]}, /*output_values=*/ {999 * CENT});
94 TryAddToMempool(pool, entry.Fee(high_fee).FromTx(tx8));
95
96 // Will make these two parents of single child
97 const auto tx11 = make_tx(/*inputs=*/ {m_coinbase_txns[7]}, /*output_values=*/ {995 * CENT});
99 const auto tx12 = make_tx(/*inputs=*/ {m_coinbase_txns[8]}, /*output_values=*/ {995 * CENT});
101
102 // Will make two children of this single parent
103 const auto tx13 = make_tx(/*inputs=*/ {m_coinbase_txns[9]}, /*output_values=*/ {995 * CENT, 995 * CENT});
105
106 const auto entry1_normal = pool.GetIter(tx1->GetHash()).value();
107 const auto entry2_normal = pool.GetIter(tx2->GetHash()).value();
108 const auto entry3_low = pool.GetIter(tx3->GetHash()).value();
109 const auto entry4_high = pool.GetIter(tx4->GetHash()).value();
110 const auto entry5_low = pool.GetIter(tx5->GetHash()).value();
111 const auto entry6_low_prioritised = pool.GetIter(tx6->GetHash()).value();
112 const auto entry7_high = pool.GetIter(tx7->GetHash()).value();
113 const auto entry8_high = pool.GetIter(tx8->GetHash()).value();
114
123
126
128
129 // Tests for EntriesAndTxidsDisjoint
130 BOOST_CHECK(EntriesAndTxidsDisjoint(empty_set, {tx1->GetHash()}, unused_txid) == std::nullopt);
131 BOOST_CHECK(EntriesAndTxidsDisjoint(set_12_normal, {tx3->GetHash()}, unused_txid) == std::nullopt);
132 BOOST_CHECK(EntriesAndTxidsDisjoint({entry2_normal}, {tx2->GetHash()}, unused_txid).has_value());
135 // EntriesAndTxidsDisjoint does not calculate descendants of iters_conflicting; it uses whatever
136 // the caller passed in. As such, no error is returned even though entry2_normal is a descendant of tx1.
137 BOOST_CHECK(EntriesAndTxidsDisjoint({entry2_normal}, {tx1->GetHash()}, unused_txid) == std::nullopt);
138
139 // Tests for PaysForRBF
140 const CFeeRate incremental_relay_feerate{DEFAULT_INCREMENTAL_RELAY_FEE};
142 // Must pay at least as much as the original.
143 BOOST_CHECK(PaysForRBF(/*original_fees=*/high_fee,
144 /*replacement_fees=*/high_fee,
145 /*replacement_vsize=*/1,
146 /*relay_fee=*/CFeeRate(0),
147 /*txid=*/unused_txid)
148 == std::nullopt);
149 BOOST_CHECK(PaysForRBF(high_fee, high_fee - 1, 1, CFeeRate(0), unused_txid).has_value());
150 BOOST_CHECK(PaysForRBF(high_fee + 1, high_fee, 1, CFeeRate(0), unused_txid).has_value());
151 // Additional fees must cover the replacement's vsize at incremental relay fee
152 BOOST_CHECK(PaysForRBF(high_fee, high_fee + 1, 11, incremental_relay_feerate, unused_txid).has_value());
153 BOOST_CHECK(PaysForRBF(high_fee, high_fee + 1, 10, incremental_relay_feerate, unused_txid) == std::nullopt);
156 BOOST_CHECK(PaysForRBF(low_fee, high_fee, 99999999, incremental_relay_feerate, unused_txid).has_value());
157 BOOST_CHECK(PaysForRBF(low_fee, high_fee + 99999999, 99999999, incremental_relay_feerate, unused_txid) == std::nullopt);
158}
159
161{
163 LOCK2(::cs_main, pool.cs);
165
166 const CAmount normal_fee{CENT/10};
167
168 // Create two parent transactions with 51 outputs each
169 const int NUM_OUTPUTS = 51;
170 std::vector<CAmount> output_values;
171 output_values.reserve(NUM_OUTPUTS);
172 for (int i = 0; i < NUM_OUTPUTS; ++i) {
173 output_values.push_back(1 * COIN);
174 }
175
176 const auto parent_tx_1 = make_tx(/*inputs=*/ {m_coinbase_txns[0]}, /*output_values=*/ output_values);
177 const auto parent_tx_2 = make_tx(/*inputs=*/ {m_coinbase_txns[1]}, /*output_values=*/ output_values);
180
181 std::vector<CTransactionRef> direct_children;
182
183 // Create individual spends of these outputs
184 for (const auto& parent_tx : {parent_tx_1, parent_tx_2}) {
185 for (auto i = 0; i < NUM_OUTPUTS; ++i) {
186 auto pretx = make_tx(/*inputs=*/ {parent_tx}, /*output_values=*/ {995 * CENT});
188 tx.vin[0].prevout.n = i;
189 TryAddToMempool(pool, entry.Fee(normal_fee).FromTx(tx));
190 BOOST_CHECK(pool.GetIter(tx.GetHash()).has_value());
191 direct_children.push_back(MakeTransactionRef(tx));
192 }
193 }
194
195 // At this point, we should have 2 clusters in the mempool, each with 52
196 // transactions.
197
198 // parent_tx and all children are in one cluster, so we can have as many
199 // conflicts within this cluster as we want without violating the RBF conflicts
200 // limit.
201 const auto parent_entry_1 = pool.GetIter(parent_tx_1->GetHash()).value();
202 const auto parent_entry_2 = pool.GetIter(parent_tx_2->GetHash()).value();
206 /*pool=*/ pool,
207 /*iters_conflicting=*/ {parent_entry_1, parent_entry_2},
208 /*all_conflicts=*/ all_conflicts) == std::nullopt);
209
210 dummy.clear();
211 // Conflicting directly with all those conflicts doesn't change anything.
213 /*pool=*/ pool,
214 /*iters_conflicting=*/ all_conflicts,
215 /*all_conflicts=*/ dummy) == std::nullopt);
216 BOOST_CHECK_EQUAL(all_conflicts.size(), dummy.size());
217 dummy.clear();
218
219 // If we mine the parent_tx's, then the clusters split (102 clusters).
221
222 // Add some descendants now to each of the direct children (we can do this now that the clusters have split).
223 for (const auto& child : direct_children) {
224 add_descendants(child, 10, pool);
225 }
226
227 // We can conflict with 100 different clusters, even if they have lots of transactions.
229 for (auto i = 0; i < 100; ++i) {
230 conflicts.insert(pool.GetIter(direct_children[i]->GetHash()).value());
231 }
233 /*pool=*/ pool,
234 /*iters_conflicting=*/ conflicts,
235 /*all_conflicts=*/ dummy) == std::nullopt);
236
237 // Conflicting with 1 more distinct cluster causes failure, however.
238 conflicts.insert(pool.GetIter(direct_children[100]->GetHash()).value());
240 /*pool=*/ pool,
241 /*iters_conflicting=*/ conflicts,
242 /*all_conflicts=*/ dummy).has_value());
243}
244
246{
248 LOCK2(::cs_main, pool.cs);
250
251 const CAmount low_fee{CENT/100};
252 const CAmount normal_fee{CENT/10};
253
254 // low feerate parent with normal feerate child
255 const auto tx1 = make_tx(/*inputs=*/ {m_coinbase_txns[0], m_coinbase_txns[1]}, /*output_values=*/ {10 * COIN});
256 TryAddToMempool(pool, entry.Fee(low_fee).FromTx(tx1));
257 const auto tx2 = make_tx(/*inputs=*/ {tx1}, /*output_values=*/ {995 * CENT});
258 TryAddToMempool(pool, entry.Fee(normal_fee).FromTx(tx2));
259
260 const auto entry1 = pool.GetIter(tx1->GetHash()).value();
261 const auto tx1_fee = entry1->GetModifiedFee();
262 const auto entry2 = pool.GetIter(tx2->GetHash()).value();
263 const auto tx2_fee = entry2->GetModifiedFee();
264
265 // conflicting transactions
266 const auto tx1_conflict = make_tx(/*inputs=*/ {m_coinbase_txns[0], m_coinbase_txns[2]}, /*output_values=*/ {10 * COIN});
267 const auto tx3 = make_tx(/*inputs=*/ {tx1_conflict}, /*output_values=*/ {995 * CENT});
268 auto entry3 = entry.FromTx(tx3);
269
270 // Now test ImprovesFeerateDiagram with various levels of "package rbf" feerates
271
272 // It doesn't improve itself
273 {
274 auto changeset{pool.GetChangeSet()};
275 changeset->StageRemoval(entry1);
276 changeset->StageRemoval(entry2);
277 changeset->StageAddition(tx1_conflict, tx1_fee, 0, 1, 0, false, 4, LockPoints());
278 changeset->StageAddition(tx3, tx2_fee, 0, 1, 0, false, 4, LockPoints());
280 BOOST_CHECK(res1.has_value());
282 BOOST_CHECK(res1.value().second == "insufficient feerate: does not improve feerate diagram");
283 }
284
285 // With one more satoshi it does
286 {
287 auto changeset{pool.GetChangeSet()};
288 changeset->StageRemoval(entry1);
289 changeset->StageRemoval(entry2);
290 changeset->StageAddition(tx1_conflict, tx1_fee + 1, 0, 1, 0, false, 4, LockPoints());
291 changeset->StageAddition(tx3, tx2_fee, 0, 1, 0, false, 4, LockPoints());
293 }
294
295 // With prioritisation of in-mempool conflicts, it affects the results of the comparison using the same args as just above
296 pool.PrioritiseTransaction(entry1->GetSharedTx()->GetHash(), /*nFeeDelta=*/1);
297 {
298 auto changeset{pool.GetChangeSet()};
299 changeset->StageRemoval(entry1);
300 changeset->StageRemoval(entry2);
301 changeset->StageAddition(tx1_conflict, tx1_fee + 1, 0, 1, 0, false, 4, LockPoints());
302 changeset->StageAddition(tx3, tx2_fee, 0, 1, 0, false, 4, LockPoints());
304 BOOST_CHECK(res2.has_value());
306 BOOST_CHECK(res2.value().second == "insufficient feerate: does not improve feerate diagram");
307 }
308 pool.PrioritiseTransaction(entry1->GetSharedTx()->GetHash(), /*nFeeDelta=*/-1);
309
310 // With fewer vbytes it does
312 tx4.vin[0].scriptWitness = CScriptWitness(); // Clear out the witness, to reduce size
313 auto entry4 = entry.FromTx(MakeTransactionRef(tx4));
314 {
315 auto changeset{pool.GetChangeSet()};
316 changeset->StageRemoval(entry1);
317 changeset->StageRemoval(entry2);
318 changeset->StageAddition(tx1_conflict, tx1_fee, 0, 1, 0, false, 4, LockPoints());
319 changeset->StageAddition(entry4.GetSharedTx(), tx2_fee, 0, 1, 0, false, 4, LockPoints());
321 }
322
323 // Adding a grandchild makes the cluster size 3, which is also calculable
324 const auto tx5 = make_tx(/*inputs=*/{tx2}, /*output_values=*/{995 * CENT});
325 TryAddToMempool(pool, entry.Fee(normal_fee).FromTx(tx5));
326 const auto entry5 = pool.GetIter(tx5->GetHash()).value();
327 {
328 auto changeset{pool.GetChangeSet()};
329 changeset->StageRemoval(entry1);
330 changeset->StageRemoval(entry2);
331 changeset->StageRemoval(entry5);
332 changeset->StageAddition(tx1_conflict, tx1_fee, 0, 1, 0, false, 4, LockPoints());
333 changeset->StageAddition(entry4.GetSharedTx(), tx2_fee + entry5->GetModifiedFee() + 1, 0, 1, 0, false, 4, LockPoints());
335 BOOST_CHECK(res3 == std::nullopt);
336 }
337}
338
340{
342 LOCK2(::cs_main, pool.cs);
344
345 const CAmount low_fee{CENT/100};
346 const CAmount high_fee{CENT};
347
348 // low -> high -> medium fee transactions that would result in two chunks together since they
349 // are all same size
350 const auto low_tx = make_tx(/*inputs=*/ {m_coinbase_txns[0]}, /*output_values=*/ {10 * COIN});
351 TryAddToMempool(pool, entry.Fee(low_fee).FromTx(low_tx));
352
353 const auto entry_low = pool.GetIter(low_tx->GetHash()).value();
354 const auto low_size = entry_low->GetAdjustedWeight();
355
356 const auto replacement_tx = make_tx(/*inputs=*/ {m_coinbase_txns[0]}, /*output_values=*/ {9 * COIN});
358
359 // Replacement of size 1
360 {
361 auto changeset = pool.GetChangeSet();
362 changeset->StageRemoval(entry_low);
363 changeset->StageAddition(replacement_tx, 0, 0, 1, 0, false, 4, LockPoints());
364 const auto replace_one{changeset->CalculateChunksForRBF()};
365 BOOST_CHECK(replace_one.has_value());
366 std::vector<FeeFrac> expected_old_chunks{{low_fee, low_size}};
367 BOOST_CHECK_EQUAL_COLLECTIONS(replace_one->first.begin(), replace_one->first.end(),
369 std::vector<FeeFrac> expected_new_chunks{{0, entry_replacement.GetAdjustedWeight()}};
370 BOOST_CHECK_EQUAL_COLLECTIONS(replace_one->second.begin(), replace_one->second.end(),
372 }
373
374 // Non-zero replacement fee/size
375 {
376 auto changeset = pool.GetChangeSet();
377 changeset->StageRemoval(entry_low);
378 changeset->StageAddition(replacement_tx, high_fee, 0, 1, 0, false, 4, LockPoints());
379 const auto replace_one_fee{changeset->CalculateChunksForRBF()};
380 BOOST_CHECK(replace_one_fee.has_value());
381 std::vector<FeeFrac> expected_old_diagram{{low_fee, low_size}};
384 std::vector<FeeFrac> expected_new_diagram{{high_fee, entry_replacement.GetAdjustedWeight()}};
387 }
388
389 // Add a second transaction to the cluster that will make a single chunk, to be evicted in the RBF
390 const auto high_tx = make_tx(/*inputs=*/ {low_tx}, /*output_values=*/ {995 * CENT});
392 const auto entry_high = pool.GetIter(high_tx->GetHash()).value();
393 const auto high_size = entry_high->GetAdjustedWeight();
394
395 {
396 auto changeset = pool.GetChangeSet();
397 changeset->StageRemoval(entry_low);
398 changeset->StageRemoval(entry_high);
399 changeset->StageAddition(replacement_tx, high_fee, 0, 1, 0, false, 4, LockPoints());
400 const auto replace_single_chunk{changeset->CalculateChunksForRBF()};
402 std::vector<FeeFrac> expected_old_chunks{{low_fee + high_fee, low_size + high_size}};
405 std::vector<FeeFrac> expected_new_chunks{{high_fee, entry_replacement.GetAdjustedWeight()}};
408 }
409
410 // Conflict with the 2nd tx, resulting in new diagram with three entries
411 {
412 auto changeset = pool.GetChangeSet();
413 changeset->StageRemoval(entry_high);
414 changeset->StageAddition(replacement_tx, high_fee, 0, 1, 0, false, 4, LockPoints());
415 const auto replace_cpfp_child{changeset->CalculateChunksForRBF()};
416 BOOST_CHECK(replace_cpfp_child.has_value());
417 std::vector<FeeFrac> expected_old_chunks{{low_fee + high_fee, low_size + high_size}};
420 std::vector<FeeFrac> expected_new_chunks{{high_fee, entry_replacement.GetAdjustedWeight()}, {low_fee, low_size}};
423 }
424
425 // Make a size 2 cluster that is itself two chunks; evict both txns
426 const auto high_tx_2 = make_tx(/*inputs=*/ {m_coinbase_txns[1]}, /*output_values=*/ {10 * COIN});
428 const auto entry_high_2 = pool.GetIter(high_tx_2->GetHash()).value();
429 const auto high_size_2 = entry_high_2->GetAdjustedWeight();
430
431 const auto low_tx_2 = make_tx(/*inputs=*/ {high_tx_2}, /*output_values=*/ {9 * COIN});
433 const auto entry_low_2 = pool.GetIter(low_tx_2->GetHash()).value();
434 const auto low_size_2 = entry_low_2->GetAdjustedWeight();
435
436 {
437 auto changeset = pool.GetChangeSet();
438 changeset->StageRemoval(entry_high_2);
439 changeset->StageRemoval(entry_low_2);
440 changeset->StageAddition(replacement_tx, high_fee, 0, 1, 0, false, 4, LockPoints());
441 const auto replace_two_chunks_single_cluster{changeset->CalculateChunksForRBF()};
443 std::vector<FeeFrac> expected_old_chunks{{high_fee, high_size_2}, {low_fee, low_size_2}};
446 std::vector<FeeFrac> expected_new_chunks{{high_fee, low_size_2}};
449 }
450
451 // You can have more than two direct conflicts
452 const auto conflict_1 = make_tx(/*inputs=*/ {m_coinbase_txns[2]}, /*output_values=*/ {10 * COIN});
454 const auto conflict_1_entry = pool.GetIter(conflict_1->GetHash()).value();
455
456 const auto conflict_2 = make_tx(/*inputs=*/ {m_coinbase_txns[3]}, /*output_values=*/ {10 * COIN});
458 const auto conflict_2_entry = pool.GetIter(conflict_2->GetHash()).value();
459
460 const auto conflict_3 = make_tx(/*inputs=*/ {m_coinbase_txns[4]}, /*output_values=*/ {10 * COIN});
462 const auto conflict_3_entry = pool.GetIter(conflict_3->GetHash()).value();
463
464 {
465 auto changeset = pool.GetChangeSet();
466 changeset->StageRemoval(conflict_1_entry);
467 changeset->StageRemoval(conflict_2_entry);
468 changeset->StageRemoval(conflict_3_entry);
469 changeset->StageAddition(replacement_tx, high_fee, 0, 1, 0, false, 4, LockPoints());
470 const auto replace_multiple_clusters{changeset->CalculateChunksForRBF()};
472 BOOST_CHECK(replace_multiple_clusters->first.size() == 3);
473 BOOST_CHECK(replace_multiple_clusters->second.size() == 1);
474 }
475
476 // Add a child transaction to conflict_1 and make it cluster size 2, two chunks due to same feerate
477 const auto conflict_1_child = make_tx(/*inputs=*/{conflict_1}, /*output_values=*/ {995 * CENT});
479 const auto conflict_1_child_entry = pool.GetIter(conflict_1_child->GetHash()).value();
480
481 {
482 auto changeset = pool.GetChangeSet();
483 changeset->StageRemoval(conflict_1_entry);
484 changeset->StageRemoval(conflict_2_entry);
485 changeset->StageRemoval(conflict_3_entry);
486 changeset->StageRemoval(conflict_1_child_entry);
487 changeset->StageAddition(replacement_tx, high_fee, 0, 1, 0, false, 4, LockPoints());
488 const auto replace_multiple_clusters_2{changeset->CalculateChunksForRBF()};
489
491 BOOST_CHECK(replace_multiple_clusters_2->first.size() == 4);
492 BOOST_CHECK(replace_multiple_clusters_2->second.size() == 1);
493 }
494}
495
497{
498 // Sanity check the correctness of the feerate chunks comparison.
499
500 // A strictly better case.
501 std::vector<FeeFrac> old_chunks{{{950, 300}, {100, 100}}};
502 std::vector<FeeFrac> new_chunks{{{1000, 300}, {50, 100}}};
503
506
507 // Incomparable diagrams
508 old_chunks = {{950, 300}, {100, 100}};
509 new_chunks = {{1000, 300}, {0, 100}};
510
511 BOOST_CHECK(CompareChunks(old_chunks, new_chunks) == std::partial_ordering::unordered);
512 BOOST_CHECK(CompareChunks(new_chunks, old_chunks) == std::partial_ordering::unordered);
513
514 // Strictly better but smaller size.
515 old_chunks = {{950, 300}, {100, 100}};
516 new_chunks = {{1100, 300}};
517
520
521 // New diagram is strictly better due to the first chunk, even though
522 // second chunk contributes no fees
523 old_chunks = {{950, 300}, {100, 100}};
524 new_chunks = {{1100, 100}, {0, 100}};
525
528
529 // Feerate of first new chunk is better with, but second chunk is worse
530 old_chunks = {{950, 300}, {100, 100}};
531 new_chunks = {{750, 100}, {249, 250}, {151, 650}};
532
533 BOOST_CHECK(CompareChunks(old_chunks, new_chunks) == std::partial_ordering::unordered);
534 BOOST_CHECK(CompareChunks(new_chunks, old_chunks) == std::partial_ordering::unordered);
535
536 // If we make the second chunk slightly better, the new diagram now wins.
537 old_chunks = {{950, 300}, {100, 100}};
538 new_chunks = {{750, 100}, {250, 250}, {150, 150}};
539
542
543 // Identical diagrams, cannot be strictly better
544 old_chunks = {{950, 300}, {100, 100}};
545 new_chunks = {{950, 300}, {100, 100}};
546
549
550 // Same aggregate fee, but different total size (trigger single tail fee check step)
551 old_chunks = {{950, 300}, {100, 99}};
552 new_chunks = {{950, 300}, {100, 100}};
553
554 // No change in evaluation when tail check needed.
557
558 // Trigger multiple tail fee check steps
559 old_chunks = {{950, 300}, {100, 99}};
560 new_chunks = {{950, 300}, {100, 100}, {0, 1}, {0, 1}};
561
564
565 // Multiple tail fee check steps, unordered result
566 new_chunks = {{950, 300}, {100, 100}, {0, 1}, {0, 1}, {1, 1}};
567 BOOST_CHECK(CompareChunks(old_chunks, new_chunks) == std::partial_ordering::unordered);
568 BOOST_CHECK(CompareChunks(new_chunks, old_chunks) == std::partial_ordering::unordered);
569}
570
int64_t CAmount
Amount in satoshis (Can be negative)
Definition amount.h:12
constexpr CAmount COIN
The amount of satoshis in one BTC.
Definition amount.h:15
TryAddToMempool(pool, CTxMemPoolEntry(tx, fee, 0, 1, 0, false, 4, lp))
node::NodeContext m_node
#define Assert(val)
Identity function.
Definition check.h:119
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
Definition feerate.h:32
Serialized script, used inside transaction inputs and outputs.
Definition script.h:406
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition txmempool.h:188
void PrioritiseTransaction(const Txid &hash, const CAmount &nFeeDelta)
Affect CreateNewBlock prioritisation of transactions.
std::optional< txiter > GetIter(const Txid &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Returns an iterator to the given hash, if found.
std::set< txiter, CompareIteratorByHash > setEntries
Definition txmempool.h:267
std::vector< RemovedMempoolTransactionInfo > removeForBlock(const std::vector< CTransactionRef > &vtx) EXCLUSIVE_LOCKS_REQUIRED(cs)
util::NotNullUniquePtr< ChangeSet > GetChangeSet() EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition txmempool.h:726
static transaction_identifier FromUint256(const uint256 &id)
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition cs_main.cpp:8
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
const CAmount high_fee
const CAmount low_fee
#define BOOST_CHECK_EQUAL(v1, v2)
Definition object.cpp:17
#define BOOST_CHECK(expr)
Definition object.cpp:16
std::optional< std::pair< DiagramCheckError, std::string > > ImprovesFeerateDiagram(CTxMemPool::ChangeSet &changeset)
The replacement transaction must improve the feerate diagram of the mempool.
Definition rbf.cpp:127
std::optional< std::string > PaysForRBF(CAmount original_fees, CAmount replacement_fees, size_t replacement_vsize, CFeeRate relay_fee, const Txid &txid)
The replacement transaction must pay more fees than the original transactions.
Definition rbf.cpp:100
std::optional< std::string > EntriesAndTxidsDisjoint(const CTxMemPool::setEntries &ancestors, const std::set< Txid > &direct_conflicts, const Txid &txid)
Check the intersection between two sets of transactions (a set of mempool entries and a set of txids)...
Definition rbf.cpp:85
std::optional< std::string > GetEntriesForConflicts(const CTransaction &tx, CTxMemPool &pool, const CTxMemPool::setEntries &iters_conflicting, CTxMemPool::setEntries &all_conflicts)
Get all descendants of iters_conflicting.
Definition rbf.cpp:58
@ FAILURE
New diagram wasn't strictly superior
constexpr unsigned int DEFAULT_INCREMENTAL_RELAY_FEE
Default for -incrementalrelayfee, which sets the minimum feerate increase for mempool limiting or rep...
Definition policy.h:48
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
uint256 GetRandHash() noexcept
Generate a random uint256.
Definition random.h:463
static CTransactionRef make_tx(const std::vector< CTransactionRef > &inputs, const std::vector< CAmount > &output_values)
Definition rbf_tests.cpp:20
static CTransactionRef add_descendants(const CTransactionRef &tx, int32_t num_descendants, CTxMemPool &pool) EXCLUSIVE_LOCKS_REQUIRED(
Definition rbf_tests.cpp:41
BOOST_AUTO_TEST_CASE(feerate_chunks_utilities)
BOOST_FIXTURE_TEST_CASE(rbf_helper_functions, TestChain100Setup)
Definition rbf_tests.cpp:59
@ OP_EQUAL
Definition script.h:147
@ OP_11
Definition script.h:95
constexpr CAmount CENT
Basic testing setup.
A mutable version of CTransaction.
std::vector< CTxOut > vout
std::vector< CTxIn > vin
std::vector< std::vector< unsigned char > > stack
Definition script.h:581
Testing fixture that pre-creates a 100-block REGTEST-mode block chain.
Definition txmempool.h:19
CTxMemPoolEntry FromTx(const CMutableTransaction &tx) const
Definition txmempool.cpp:34
TestMemPoolEntryHelper & Fee(CAmount _fee)
Definition txmempool.h:33
std::unique_ptr< CTxMemPool > mempool
Definition context.h:69
#define LOCK2(cs1, cs2)
Definition sync.h:269
#define AssertLockHeld(cs)
Definition sync.h:144
#define EXCLUSIVE_LOCKS_REQUIRED(...)
BOOST_CHECK_EQUAL_COLLECTIONS(R1L.begin(), R1L.end(), R1Array, R1Array+uint256::size())
std::partial_ordering CompareChunks(std::span< const FeeFrac > chunks0, std::span< const FeeFrac > chunks1)
Compare the feerate diagrams implied by the provided sorted chunks data.
Definition feefrac.cpp:12
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition time.h:82