Bitcoin Core 30.99.0
P2P Digital Currency
miniminer_tests.cpp
Go to the documentation of this file.
1// Copyright (c) 2021 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 <node/mini_miner.h>
5#include <random.h>
6#include <txmempool.h>
7#include <util/time.h>
8
10#include <test/util/txmempool.h>
11
12#include <boost/test/unit_test.hpp>
13#include <optional>
14#include <vector>
15
17
18const CAmount low_fee{CENT/2000}; // 500 ṩ
19const CAmount med_fee{CENT/200}; // 5000 ṩ
20const CAmount high_fee{CENT/10}; // 100_000 ṩ
21
22
23static inline CTransactionRef make_tx(const std::vector<COutPoint>& inputs, size_t num_outputs)
24{
26 tx.vin.resize(inputs.size());
27 tx.vout.resize(num_outputs);
28 for (size_t i = 0; i < inputs.size(); ++i) {
29 tx.vin[i].prevout = inputs[i];
30 }
31 for (size_t i = 0; i < num_outputs; ++i) {
32 tx.vout[i].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
33 // The actual input and output values of these transactions don't really
34 // matter, since all accounting will use the entries' cached fees.
35 tx.vout[i].nValue = COIN;
36 }
37 return MakeTransactionRef(tx);
38}
39
40static inline bool sanity_check(const std::vector<CTransactionRef>& transactions,
41 const std::map<COutPoint, CAmount>& bumpfees)
42{
43 // No negative bumpfees.
44 for (const auto& [outpoint, fee] : bumpfees) {
45 if (fee < 0) return false;
46 if (fee == 0) continue;
47 auto outpoint_ = outpoint; // structured bindings can't be captured in C++17, so we need to use a variable
48 const bool found = std::any_of(transactions.cbegin(), transactions.cend(), [&](const auto& tx) {
49 return outpoint_.hash == tx->GetHash() && outpoint_.n < tx->vout.size();
50 });
51 if (!found) return false;
52 }
53 for (const auto& tx : transactions) {
54 // If tx has multiple outputs, they must all have the same bumpfee (if they exist).
55 if (tx->vout.size() > 1) {
56 std::set<CAmount> distinct_bumpfees;
57 for (size_t i{0}; i < tx->vout.size(); ++i) {
58 const auto bumpfee = bumpfees.find(COutPoint{tx->GetHash(), static_cast<uint32_t>(i)});
59 if (bumpfee != bumpfees.end()) distinct_bumpfees.insert(bumpfee->second);
60 }
61 if (distinct_bumpfees.size() > 1) return false;
62 }
63 }
64 return true;
65}
66
67template <typename Key, typename Value>
68Value Find(const std::map<Key, Value>& map, const Key& key)
69{
70 auto it = map.find(key);
71 BOOST_CHECK_MESSAGE(it != map.end(), strprintf("Cannot find %s", key.ToString()));
72 return it->second;
73}
74
76{
78 LOCK2(::cs_main, pool.cs);
80
81 // Create a transaction that will be prioritised to have a negative modified fee.
82 const CAmount positive_base_fee{1000};
83 const CAmount negative_fee_delta{-50000};
84 const CAmount negative_modified_fees{positive_base_fee + negative_fee_delta};
85 BOOST_CHECK(negative_modified_fees < 0);
86 const auto tx_mod_negative = make_tx({COutPoint{m_coinbase_txns[4]->GetHash(), 0}}, /*num_outputs=*/1);
87 AddToMempool(pool, entry.Fee(positive_base_fee).FromTx(tx_mod_negative));
88 pool.PrioritiseTransaction(tx_mod_negative->GetHash(), negative_fee_delta);
89 const COutPoint only_outpoint{tx_mod_negative->GetHash(), 0};
90
91 // When target feerate is 0, transactions with negative fees are not selected.
92 node::MiniMiner mini_miner_target0(pool, {only_outpoint});
93 BOOST_CHECK(mini_miner_target0.IsReadyToCalculate());
94 const CFeeRate feerate_zero(0);
95 mini_miner_target0.BuildMockTemplate(feerate_zero);
96 // Check the quit condition:
97 BOOST_CHECK(negative_modified_fees < feerate_zero.GetFee(Assert(pool.GetEntry(tx_mod_negative->GetHash()))->GetTxSize()));
98 BOOST_CHECK(mini_miner_target0.GetMockTemplateTxids().empty());
99
100 // With no target feerate, the template includes all transactions, even negative feerate ones.
101 node::MiniMiner mini_miner_no_target(pool, {only_outpoint});
102 BOOST_CHECK(mini_miner_no_target.IsReadyToCalculate());
103 mini_miner_no_target.BuildMockTemplate(std::nullopt);
104 const auto template_txids{mini_miner_no_target.GetMockTemplateTxids()};
105 BOOST_CHECK_EQUAL(template_txids.size(), 1);
106 BOOST_CHECK(template_txids.count(tx_mod_negative->GetHash()) > 0);
107}
108
110{
112 LOCK2(::cs_main, pool.cs);
114
115 // Create a parent tx0 and child tx1 with normal fees:
116 const auto tx0 = make_tx({COutPoint{m_coinbase_txns[0]->GetHash(), 0}}, /*num_outputs=*/2);
117 AddToMempool(pool, entry.Fee(med_fee).FromTx(tx0));
118 const auto tx1 = make_tx({COutPoint{tx0->GetHash(), 0}}, /*num_outputs=*/1);
119 AddToMempool(pool, entry.Fee(med_fee).FromTx(tx1));
120
121 // Create a low-feerate parent tx2 and high-feerate child tx3 (cpfp)
122 const auto tx2 = make_tx({COutPoint{m_coinbase_txns[1]->GetHash(), 0}}, /*num_outputs=*/2);
123 AddToMempool(pool, entry.Fee(low_fee).FromTx(tx2));
124 const auto tx3 = make_tx({COutPoint{tx2->GetHash(), 0}}, /*num_outputs=*/1);
125 AddToMempool(pool, entry.Fee(high_fee).FromTx(tx3));
126
127 // Create a parent tx4 and child tx5 where both have low fees
128 const auto tx4 = make_tx({COutPoint{m_coinbase_txns[2]->GetHash(), 0}}, /*num_outputs=*/2);
129 AddToMempool(pool, entry.Fee(low_fee).FromTx(tx4));
130 const auto tx5 = make_tx({COutPoint{tx4->GetHash(), 0}}, /*num_outputs=*/1);
131 AddToMempool(pool, entry.Fee(low_fee).FromTx(tx5));
132 const CAmount tx5_delta{CENT/100};
133 // Make tx5's modified fee much higher than its base fee. This should cause it to pass
134 // the fee-related checks despite being low-feerate.
135 pool.PrioritiseTransaction(tx5->GetHash(), tx5_delta);
136 const CAmount tx5_mod_fee{low_fee + tx5_delta};
137
138 // Create a high-feerate parent tx6, low-feerate child tx7
139 const auto tx6 = make_tx({COutPoint{m_coinbase_txns[3]->GetHash(), 0}}, /*num_outputs=*/2);
140 AddToMempool(pool, entry.Fee(high_fee).FromTx(tx6));
141 const auto tx7 = make_tx({COutPoint{tx6->GetHash(), 0}}, /*num_outputs=*/1);
142 AddToMempool(pool, entry.Fee(low_fee).FromTx(tx7));
143
144 std::vector<COutPoint> all_unspent_outpoints({
145 COutPoint{tx0->GetHash(), 1},
146 COutPoint{tx1->GetHash(), 0},
147 COutPoint{tx2->GetHash(), 1},
148 COutPoint{tx3->GetHash(), 0},
149 COutPoint{tx4->GetHash(), 1},
150 COutPoint{tx5->GetHash(), 0},
151 COutPoint{tx6->GetHash(), 1},
152 COutPoint{tx7->GetHash(), 0}
153 });
154 for (const auto& outpoint : all_unspent_outpoints) BOOST_CHECK(!pool.isSpent(outpoint));
155
156 std::vector<COutPoint> all_spent_outpoints({
157 COutPoint{tx0->GetHash(), 0},
158 COutPoint{tx2->GetHash(), 0},
159 COutPoint{tx4->GetHash(), 0},
160 COutPoint{tx6->GetHash(), 0}
161 });
162 for (const auto& outpoint : all_spent_outpoints) BOOST_CHECK(pool.GetConflictTx(outpoint) != nullptr);
163
164 std::vector<COutPoint> all_parent_outputs({
165 COutPoint{tx0->GetHash(), 0},
166 COutPoint{tx0->GetHash(), 1},
167 COutPoint{tx2->GetHash(), 0},
168 COutPoint{tx2->GetHash(), 1},
169 COutPoint{tx4->GetHash(), 0},
170 COutPoint{tx4->GetHash(), 1},
171 COutPoint{tx6->GetHash(), 0},
172 COutPoint{tx6->GetHash(), 1}
173 });
174
175
176 std::vector<CTransactionRef> all_transactions{tx0, tx1, tx2, tx3, tx4, tx5, tx6, tx7};
177 struct TxDimensions {
178 int32_t vsize; CAmount mod_fee; CFeeRate feerate;
179 };
180 std::map<Txid, TxDimensions> tx_dims;
181 for (const auto& tx : all_transactions) {
182 const auto& entry{*Assert(pool.GetEntry(tx->GetHash()))};
183 tx_dims.emplace(tx->GetHash(), TxDimensions{entry.GetTxSize(), entry.GetModifiedFee(),
184 CFeeRate(entry.GetModifiedFee(), entry.GetTxSize())});
185 }
186
187 const std::vector<CFeeRate> various_normal_feerates({CFeeRate(0), CFeeRate(500), CFeeRate(999),
188 CFeeRate(1000), CFeeRate(2000), CFeeRate(2500),
189 CFeeRate(3333), CFeeRate(7800), CFeeRate(11199),
190 CFeeRate(23330), CFeeRate(50000), CFeeRate(5*CENT)});
191
192 // All nonexistent entries have a bumpfee of zero, regardless of feerate
193 std::vector<COutPoint> nonexistent_outpoints({ COutPoint{Txid::FromUint256(GetRandHash()), 0}, COutPoint{Txid::FromUint256(GetRandHash()), 3} });
194 for (const auto& outpoint : nonexistent_outpoints) BOOST_CHECK(!pool.isSpent(outpoint));
195 for (const auto& feerate : various_normal_feerates) {
196 node::MiniMiner mini_miner(pool, nonexistent_outpoints);
197 BOOST_CHECK(mini_miner.IsReadyToCalculate());
198 auto bump_fees = mini_miner.CalculateBumpFees(feerate);
199 BOOST_CHECK(!mini_miner.IsReadyToCalculate());
200 BOOST_CHECK(sanity_check(all_transactions, bump_fees));
201 BOOST_CHECK(bump_fees.size() == nonexistent_outpoints.size());
202 for (const auto& outpoint: nonexistent_outpoints) {
203 auto it = bump_fees.find(outpoint);
204 BOOST_CHECK(it != bump_fees.end());
205 BOOST_CHECK_EQUAL(it->second, 0);
206 }
207 }
208
209 // Gather bump fees for all available UTXOs.
210 for (const auto& target_feerate : various_normal_feerates) {
211 node::MiniMiner mini_miner(pool, all_unspent_outpoints);
212 BOOST_CHECK(mini_miner.IsReadyToCalculate());
213 auto bump_fees = mini_miner.CalculateBumpFees(target_feerate);
214 BOOST_CHECK(!mini_miner.IsReadyToCalculate());
215 BOOST_CHECK(sanity_check(all_transactions, bump_fees));
216 BOOST_CHECK_EQUAL(bump_fees.size(), all_unspent_outpoints.size());
217
218 // Check tx0 bumpfee: no other bumper.
219 const TxDimensions& tx0_dimensions = tx_dims.find(tx0->GetHash())->second;
220 CAmount bumpfee0 = Find(bump_fees, COutPoint{tx0->GetHash(), 1});
221 if (target_feerate <= tx0_dimensions.feerate) {
222 BOOST_CHECK_EQUAL(bumpfee0, 0);
223 } else {
224 // Difference is fee to bump tx0 from current to target feerate.
225 BOOST_CHECK_EQUAL(bumpfee0, target_feerate.GetFee(tx0_dimensions.vsize) - tx0_dimensions.mod_fee);
226 }
227
228 // Check tx2 bumpfee: assisted by tx3.
229 const TxDimensions& tx2_dimensions = tx_dims.find(tx2->GetHash())->second;
230 const TxDimensions& tx3_dimensions = tx_dims.find(tx3->GetHash())->second;
231 const CFeeRate tx2_feerate = CFeeRate(tx2_dimensions.mod_fee + tx3_dimensions.mod_fee, tx2_dimensions.vsize + tx3_dimensions.vsize);
232 CAmount bumpfee2 = Find(bump_fees, COutPoint{tx2->GetHash(), 1});
233 if (target_feerate <= tx2_feerate) {
234 // As long as target feerate is below tx3's ancestor feerate, there is no bump fee.
235 BOOST_CHECK_EQUAL(bumpfee2, 0);
236 } else {
237 // Difference is fee to bump tx2 from current to target feerate, without tx3.
238 BOOST_CHECK_EQUAL(bumpfee2, target_feerate.GetFee(tx2_dimensions.vsize) - tx2_dimensions.mod_fee);
239 }
240
241 // If tx5’s modified fees are sufficient for tx4 and tx5 to be picked
242 // into the block, our prospective new transaction would not need to
243 // bump tx4 when using tx4’s second output. If however even tx5’s
244 // modified fee (which essentially indicates "effective feerate") is
245 // not sufficient to bump tx4, using the second output of tx4 would
246 // require our transaction to bump tx4 from scratch since we evaluate
247 // transaction packages per ancestor sets and do not consider multiple
248 // children’s fees.
249 const TxDimensions& tx4_dimensions = tx_dims.find(tx4->GetHash())->second;
250 const TxDimensions& tx5_dimensions = tx_dims.find(tx5->GetHash())->second;
251 const CFeeRate tx4_feerate = CFeeRate(tx4_dimensions.mod_fee + tx5_dimensions.mod_fee, tx4_dimensions.vsize + tx5_dimensions.vsize);
252 CAmount bumpfee4 = Find(bump_fees, COutPoint{tx4->GetHash(), 1});
253 if (target_feerate <= tx4_feerate) {
254 // As long as target feerate is below tx5's ancestor feerate, there is no bump fee.
255 BOOST_CHECK_EQUAL(bumpfee4, 0);
256 } else {
257 // Difference is fee to bump tx4 from current to target feerate, without tx5.
258 BOOST_CHECK_EQUAL(bumpfee4, target_feerate.GetFee(tx4_dimensions.vsize) - tx4_dimensions.mod_fee);
259 }
260 }
261 // Spent outpoints should usually not be requested as they would not be
262 // considered available. However, when they are explicitly requested, we
263 // can calculate their bumpfee to facilitate RBF-replacements
264 for (const auto& target_feerate : various_normal_feerates) {
265 node::MiniMiner mini_miner_all_spent(pool, all_spent_outpoints);
266 BOOST_CHECK(mini_miner_all_spent.IsReadyToCalculate());
267 auto bump_fees_all_spent = mini_miner_all_spent.CalculateBumpFees(target_feerate);
268 BOOST_CHECK(!mini_miner_all_spent.IsReadyToCalculate());
269 BOOST_CHECK_EQUAL(bump_fees_all_spent.size(), all_spent_outpoints.size());
270 node::MiniMiner mini_miner_all_parents(pool, all_parent_outputs);
271 BOOST_CHECK(mini_miner_all_parents.IsReadyToCalculate());
272 auto bump_fees_all_parents = mini_miner_all_parents.CalculateBumpFees(target_feerate);
273 BOOST_CHECK(!mini_miner_all_parents.IsReadyToCalculate());
274 BOOST_CHECK_EQUAL(bump_fees_all_parents.size(), all_parent_outputs.size());
275 for (auto& bump_fees : {bump_fees_all_parents, bump_fees_all_spent}) {
276 // For all_parents case, both outputs from the parent should have the same bump fee,
277 // even though only one of them is in a to-be-replaced transaction.
278 BOOST_CHECK(sanity_check(all_transactions, bump_fees));
279
280 // Check tx0 bumpfee: no other bumper.
281 const TxDimensions& tx0_dimensions = tx_dims.find(tx0->GetHash())->second;
282 CAmount it0_spent = Find(bump_fees, COutPoint{tx0->GetHash(), 0});
283 if (target_feerate <= tx0_dimensions.feerate) {
284 BOOST_CHECK_EQUAL(it0_spent, 0);
285 } else {
286 // Difference is fee to bump tx0 from current to target feerate.
287 BOOST_CHECK_EQUAL(it0_spent, target_feerate.GetFee(tx0_dimensions.vsize) - tx0_dimensions.mod_fee);
288 }
289
290 // Check tx2 bumpfee: no other bumper, because tx3 is to-be-replaced.
291 const TxDimensions& tx2_dimensions = tx_dims.find(tx2->GetHash())->second;
292 const CFeeRate tx2_feerate_unbumped = tx2_dimensions.feerate;
293 auto it2_spent = Find(bump_fees, COutPoint{tx2->GetHash(), 0});
294 if (target_feerate <= tx2_feerate_unbumped) {
295 BOOST_CHECK_EQUAL(it2_spent, 0);
296 } else {
297 // Difference is fee to bump tx2 from current to target feerate, without tx3.
298 BOOST_CHECK_EQUAL(it2_spent, target_feerate.GetFee(tx2_dimensions.vsize) - tx2_dimensions.mod_fee);
299 }
300
301 // Check tx4 bumpfee: no other bumper, because tx5 is to-be-replaced.
302 const TxDimensions& tx4_dimensions = tx_dims.find(tx4->GetHash())->second;
303 const CFeeRate tx4_feerate_unbumped = tx4_dimensions.feerate;
304 auto it4_spent = Find(bump_fees, COutPoint{tx4->GetHash(), 0});
305 if (target_feerate <= tx4_feerate_unbumped) {
306 BOOST_CHECK_EQUAL(it4_spent, 0);
307 } else {
308 // Difference is fee to bump tx4 from current to target feerate, without tx5.
309 BOOST_CHECK_EQUAL(it4_spent, target_feerate.GetFee(tx4_dimensions.vsize) - tx4_dimensions.mod_fee);
310 }
311 }
312 }
313
314 // Check m_inclusion_order for equivalent mempool- and manually-constructed MiniMiners.
315 // (We cannot check bump fees in manually-constructed MiniMiners because it doesn't know what
316 // outpoints are requested).
317 std::vector<node::MiniMinerMempoolEntry> miniminer_info;
318 {
319 const int32_t tx0_vsize{tx_dims.at(tx0->GetHash()).vsize};
320 const int32_t tx1_vsize{tx_dims.at(tx1->GetHash()).vsize};
321 const int32_t tx2_vsize{tx_dims.at(tx2->GetHash()).vsize};
322 const int32_t tx3_vsize{tx_dims.at(tx3->GetHash()).vsize};
323 const int32_t tx4_vsize{tx_dims.at(tx4->GetHash()).vsize};
324 const int32_t tx5_vsize{tx_dims.at(tx5->GetHash()).vsize};
325 const int32_t tx6_vsize{tx_dims.at(tx6->GetHash()).vsize};
326 const int32_t tx7_vsize{tx_dims.at(tx7->GetHash()).vsize};
327
328 miniminer_info.emplace_back(tx0,/*vsize_self=*/tx0_vsize,/*vsize_ancestor=*/tx0_vsize,/*fee_self=*/med_fee,/*fee_ancestor=*/med_fee);
329 miniminer_info.emplace_back(tx1, tx1_vsize, tx0_vsize + tx1_vsize, med_fee, 2*med_fee);
330 miniminer_info.emplace_back(tx2, tx2_vsize, tx2_vsize, low_fee, low_fee);
331 miniminer_info.emplace_back(tx3, tx3_vsize, tx2_vsize + tx3_vsize, high_fee, low_fee + high_fee);
332 miniminer_info.emplace_back(tx4, tx4_vsize, tx4_vsize, low_fee, low_fee);
333 miniminer_info.emplace_back(tx5, tx5_vsize, tx4_vsize + tx5_vsize, tx5_mod_fee, low_fee + tx5_mod_fee);
334 miniminer_info.emplace_back(tx6, tx6_vsize, tx6_vsize, high_fee, high_fee);
335 miniminer_info.emplace_back(tx7, tx7_vsize, tx6_vsize + tx7_vsize, low_fee, high_fee + low_fee);
336 }
337 std::map<Txid, std::set<Txid>> descendant_caches;
338 descendant_caches.emplace(tx0->GetHash(), std::set<Txid>{tx0->GetHash(), tx1->GetHash()});
339 descendant_caches.emplace(tx1->GetHash(), std::set<Txid>{tx1->GetHash()});
340 descendant_caches.emplace(tx2->GetHash(), std::set<Txid>{tx2->GetHash(), tx3->GetHash()});
341 descendant_caches.emplace(tx3->GetHash(), std::set<Txid>{tx3->GetHash()});
342 descendant_caches.emplace(tx4->GetHash(), std::set<Txid>{tx4->GetHash(), tx5->GetHash()});
343 descendant_caches.emplace(tx5->GetHash(), std::set<Txid>{tx5->GetHash()});
344 descendant_caches.emplace(tx6->GetHash(), std::set<Txid>{tx6->GetHash(), tx7->GetHash()});
345 descendant_caches.emplace(tx7->GetHash(), std::set<Txid>{tx7->GetHash()});
346
347 node::MiniMiner miniminer_manual(miniminer_info, descendant_caches);
348 // Use unspent outpoints to avoid entries being omitted.
349 node::MiniMiner miniminer_pool(pool, all_unspent_outpoints);
350 BOOST_CHECK(miniminer_manual.IsReadyToCalculate());
351 BOOST_CHECK(miniminer_pool.IsReadyToCalculate());
352 for (const auto& sequences : {miniminer_manual.Linearize(), miniminer_pool.Linearize()}) {
353 // tx6 is selected first: high feerate with no parents to bump
354 BOOST_CHECK_EQUAL(Find(sequences, tx6->GetHash()), 0);
355
356 // tx2 + tx3 CPFP are selected next
357 BOOST_CHECK_EQUAL(Find(sequences, tx2->GetHash()), 1);
358 BOOST_CHECK_EQUAL(Find(sequences, tx3->GetHash()), 1);
359
360 // tx4 + prioritised tx5 CPFP
361 BOOST_CHECK_EQUAL(Find(sequences, tx4->GetHash()), 2);
362 BOOST_CHECK_EQUAL(Find(sequences, tx5->GetHash()), 2);
363
364 BOOST_CHECK_EQUAL(Find(sequences, tx0->GetHash()), 3);
365 BOOST_CHECK_EQUAL(Find(sequences, tx1->GetHash()), 3);
366
367
368 // tx7 is selected last: low feerate with no children
369 BOOST_CHECK_EQUAL(Find(sequences, tx7->GetHash()), 4);
370 }
371}
372
374{
375/* Tx graph for `miniminer_overlap` unit test:
376 *
377 * coinbase_tx [mined] ... block-chain
378 * -------------------------------------------------
379 * / | \ \ ... mempool
380 * / | \ |
381 * tx0 tx1 tx2 tx4
382 * [low] [med] [high] [high]
383 * \ | / |
384 * \ | / tx5
385 * \ | / [low]
386 * tx3 / \
387 * [high] tx6 tx7
388 * [med] [high]
389 *
390 * NOTE:
391 * -> "low"/"med"/"high" denote the _absolute_ fee of each tx
392 * -> tx3 has 3 inputs and 3 outputs, all other txs have 1 input and 2 outputs
393 * -> tx3's feerate is lower than tx2's, as tx3 has more weight (due to having more inputs and outputs)
394 *
395 * -> tx2_FR = high / tx2_vsize
396 * -> tx3_FR = high / tx3_vsize
397 * -> tx3_ASFR = (low+med+high+high) / (tx0_vsize + tx1_vsize + tx2_vsize + tx3_vsize)
398 * -> tx4_FR = high / tx4_vsize
399 * -> tx6_ASFR = (high+low+med) / (tx4_vsize + tx5_vsize + tx6_vsize)
400 * -> tx7_ASFR = (high+low+high) / (tx4_vsize + tx5_vsize + tx7_vsize) */
401
403 LOCK2(::cs_main, pool.cs);
405
406 // Create 3 parents of different feerates, and 1 child spending outputs from all 3 parents.
407 const auto tx0 = make_tx({COutPoint{m_coinbase_txns[0]->GetHash(), 0}}, /*num_outputs=*/2);
408 AddToMempool(pool, entry.Fee(low_fee).FromTx(tx0));
409 const auto tx1 = make_tx({COutPoint{m_coinbase_txns[1]->GetHash(), 0}}, /*num_outputs=*/2);
410 AddToMempool(pool, entry.Fee(med_fee).FromTx(tx1));
411 const auto tx2 = make_tx({COutPoint{m_coinbase_txns[2]->GetHash(), 0}}, /*num_outputs=*/2);
412 AddToMempool(pool, entry.Fee(high_fee).FromTx(tx2));
413 const auto tx3 = make_tx({COutPoint{tx0->GetHash(), 0}, COutPoint{tx1->GetHash(), 0}, COutPoint{tx2->GetHash(), 0}}, /*num_outputs=*/3);
414 AddToMempool(pool, entry.Fee(high_fee).FromTx(tx3));
415
416 // Create 1 grandparent and 1 parent, then 2 children.
417 const auto tx4 = make_tx({COutPoint{m_coinbase_txns[3]->GetHash(), 0}}, /*num_outputs=*/2);
418 AddToMempool(pool, entry.Fee(high_fee).FromTx(tx4));
419 const auto tx5 = make_tx({COutPoint{tx4->GetHash(), 0}}, /*num_outputs=*/3);
420 AddToMempool(pool, entry.Fee(low_fee).FromTx(tx5));
421 const auto tx6 = make_tx({COutPoint{tx5->GetHash(), 0}}, /*num_outputs=*/2);
422 AddToMempool(pool, entry.Fee(med_fee).FromTx(tx6));
423 const auto tx7 = make_tx({COutPoint{tx5->GetHash(), 1}}, /*num_outputs=*/2);
424 AddToMempool(pool, entry.Fee(high_fee).FromTx(tx7));
425
426 std::vector<CTransactionRef> all_transactions{tx0, tx1, tx2, tx3, tx4, tx5, tx6, tx7};
427 std::vector<int64_t> tx_vsizes;
428 tx_vsizes.reserve(all_transactions.size());
429 for (const auto& tx : all_transactions) tx_vsizes.push_back(GetVirtualTransactionSize(*tx));
430
431 std::vector<COutPoint> all_unspent_outpoints({
432 COutPoint{tx0->GetHash(), 1},
433 COutPoint{tx1->GetHash(), 1},
434 COutPoint{tx2->GetHash(), 1},
435 COutPoint{tx3->GetHash(), 0},
436 COutPoint{tx3->GetHash(), 1},
437 COutPoint{tx3->GetHash(), 2},
438 COutPoint{tx4->GetHash(), 1},
439 COutPoint{tx5->GetHash(), 2},
440 COutPoint{tx6->GetHash(), 0},
441 COutPoint{tx7->GetHash(), 0}
442 });
443 for (const auto& outpoint : all_unspent_outpoints) BOOST_CHECK(!pool.isSpent(outpoint));
444
445 const auto tx2_feerate = CFeeRate(high_fee, tx_vsizes[2]);
446 const auto tx3_feerate = CFeeRate(high_fee, tx_vsizes[3]);
447 // tx3's feerate is lower than tx2's. same fee, different weight.
448 BOOST_CHECK(tx2_feerate > tx3_feerate);
449 const auto tx3_anc_feerate = CFeeRate(low_fee + med_fee + high_fee + high_fee, tx_vsizes[0] + tx_vsizes[1] + tx_vsizes[2] + tx_vsizes[3]);
450 const auto& tx3_entry{*Assert(pool.GetEntry(tx3->GetHash()))};
451
452 // Check that ancestor feerate is calculated correctly.
453 auto [dummy_count, ancestor_vsize, mod_fees] = pool.CalculateAncestorData(tx3_entry);
454 BOOST_CHECK(tx3_anc_feerate == CFeeRate(mod_fees, ancestor_vsize));
455
456 const auto tx4_feerate = CFeeRate(high_fee, tx_vsizes[4]);
457 const auto tx6_anc_feerate = CFeeRate(high_fee + low_fee + med_fee, tx_vsizes[4] + tx_vsizes[5] + tx_vsizes[6]);
458 const auto& tx6_entry{*Assert(pool.GetEntry(tx6->GetHash()))};
459
460 std::tie(std::ignore, ancestor_vsize, mod_fees) = pool.CalculateAncestorData(tx6_entry);
461 BOOST_CHECK(tx6_anc_feerate == CFeeRate(mod_fees, ancestor_vsize));
462 const auto tx7_anc_feerate = CFeeRate(high_fee + low_fee + high_fee, tx_vsizes[4] + tx_vsizes[5] + tx_vsizes[7]);
463 const auto& tx7_entry{*Assert(pool.GetEntry(tx7->GetHash()))};
464
465 std::tie(std::ignore, ancestor_vsize, mod_fees) = pool.CalculateAncestorData(tx7_entry);
466 BOOST_CHECK(tx7_anc_feerate == CFeeRate(mod_fees, ancestor_vsize));
467 BOOST_CHECK(tx4_feerate > tx6_anc_feerate);
468 BOOST_CHECK(tx4_feerate > tx7_anc_feerate);
469
470 // Extremely high feerate: everybody's bumpfee is from their full ancestor set.
471 {
472 node::MiniMiner mini_miner(pool, all_unspent_outpoints);
473 const CFeeRate very_high_feerate(COIN);
474 BOOST_CHECK(tx3_anc_feerate < very_high_feerate);
475 BOOST_CHECK(mini_miner.IsReadyToCalculate());
476 auto bump_fees = mini_miner.CalculateBumpFees(very_high_feerate);
477 BOOST_CHECK_EQUAL(bump_fees.size(), all_unspent_outpoints.size());
478 BOOST_CHECK(!mini_miner.IsReadyToCalculate());
479 BOOST_CHECK(sanity_check(all_transactions, bump_fees));
480 const auto tx0_bumpfee = bump_fees.find(COutPoint{tx0->GetHash(), 1});
481 BOOST_CHECK(tx0_bumpfee != bump_fees.end());
482 BOOST_CHECK_EQUAL(tx0_bumpfee->second, very_high_feerate.GetFee(tx_vsizes[0]) - low_fee);
483 const auto tx3_bumpfee = bump_fees.find(COutPoint{tx3->GetHash(), 0});
484 BOOST_CHECK(tx3_bumpfee != bump_fees.end());
485 BOOST_CHECK_EQUAL(tx3_bumpfee->second,
486 very_high_feerate.GetFee(tx_vsizes[0] + tx_vsizes[1] + tx_vsizes[2] + tx_vsizes[3]) - (low_fee + med_fee + high_fee + high_fee));
487 const auto tx6_bumpfee = bump_fees.find(COutPoint{tx6->GetHash(), 0});
488 BOOST_CHECK(tx6_bumpfee != bump_fees.end());
489 BOOST_CHECK_EQUAL(tx6_bumpfee->second,
490 very_high_feerate.GetFee(tx_vsizes[4] + tx_vsizes[5] + tx_vsizes[6]) - (high_fee + low_fee + med_fee));
491 const auto tx7_bumpfee = bump_fees.find(COutPoint{tx7->GetHash(), 0});
492 BOOST_CHECK(tx7_bumpfee != bump_fees.end());
493 BOOST_CHECK_EQUAL(tx7_bumpfee->second,
494 very_high_feerate.GetFee(tx_vsizes[4] + tx_vsizes[5] + tx_vsizes[7]) - (high_fee + low_fee + high_fee));
495 // Total fees: if spending multiple outputs from tx3 don't double-count fees.
496 node::MiniMiner mini_miner_total_tx3(pool, {COutPoint{tx3->GetHash(), 0}, COutPoint{tx3->GetHash(), 1}});
497 BOOST_CHECK(mini_miner_total_tx3.IsReadyToCalculate());
498 const auto tx3_bump_fee = mini_miner_total_tx3.CalculateTotalBumpFees(very_high_feerate);
499 BOOST_CHECK(!mini_miner_total_tx3.IsReadyToCalculate());
500 BOOST_CHECK(tx3_bump_fee.has_value());
501 BOOST_CHECK_EQUAL(tx3_bump_fee.value(),
502 very_high_feerate.GetFee(tx_vsizes[0] + tx_vsizes[1] + tx_vsizes[2] + tx_vsizes[3]) - (low_fee + med_fee + high_fee + high_fee));
503 // Total fees: if spending both tx6 and tx7, don't double-count fees.
504 node::MiniMiner mini_miner_tx6_tx7(pool, {COutPoint{tx6->GetHash(), 0}, COutPoint{tx7->GetHash(), 0}});
505 BOOST_CHECK(mini_miner_tx6_tx7.IsReadyToCalculate());
506 const auto tx6_tx7_bumpfee = mini_miner_tx6_tx7.CalculateTotalBumpFees(very_high_feerate);
507 BOOST_CHECK(!mini_miner_tx6_tx7.IsReadyToCalculate());
508 BOOST_CHECK(tx6_tx7_bumpfee.has_value());
509 BOOST_CHECK_EQUAL(tx6_tx7_bumpfee.value(),
510 very_high_feerate.GetFee(tx_vsizes[4] + tx_vsizes[5] + tx_vsizes[6] + tx_vsizes[7]) - (high_fee + low_fee + med_fee + high_fee));
511 }
512 // Feerate just below tx4: tx6 and tx7 have different bump fees.
513 {
514 const auto just_below_tx4 = CFeeRate(tx4_feerate.GetFeePerK() - 5);
515 node::MiniMiner mini_miner(pool, all_unspent_outpoints);
516 BOOST_CHECK(mini_miner.IsReadyToCalculate());
517 auto bump_fees = mini_miner.CalculateBumpFees(just_below_tx4);
518 BOOST_CHECK(!mini_miner.IsReadyToCalculate());
519 BOOST_CHECK_EQUAL(bump_fees.size(), all_unspent_outpoints.size());
520 BOOST_CHECK(sanity_check(all_transactions, bump_fees));
521 const auto tx6_bumpfee = bump_fees.find(COutPoint{tx6->GetHash(), 0});
522 BOOST_CHECK(tx6_bumpfee != bump_fees.end());
523 BOOST_CHECK_EQUAL(tx6_bumpfee->second, just_below_tx4.GetFee(tx_vsizes[5] + tx_vsizes[6]) - (low_fee + med_fee));
524 const auto tx7_bumpfee = bump_fees.find(COutPoint{tx7->GetHash(), 0});
525 BOOST_CHECK(tx7_bumpfee != bump_fees.end());
526 BOOST_CHECK_EQUAL(tx7_bumpfee->second, just_below_tx4.GetFee(tx_vsizes[5] + tx_vsizes[7]) - (low_fee + high_fee));
527 // Total fees: if spending both tx6 and tx7, don't double-count fees.
528 node::MiniMiner mini_miner_tx6_tx7(pool, {COutPoint{tx6->GetHash(), 0}, COutPoint{tx7->GetHash(), 0}});
529 BOOST_CHECK(mini_miner_tx6_tx7.IsReadyToCalculate());
530 const auto tx6_tx7_bumpfee = mini_miner_tx6_tx7.CalculateTotalBumpFees(just_below_tx4);
531 BOOST_CHECK(!mini_miner_tx6_tx7.IsReadyToCalculate());
532 BOOST_CHECK(tx6_tx7_bumpfee.has_value());
533 BOOST_CHECK_EQUAL(tx6_tx7_bumpfee.value(), just_below_tx4.GetFee(tx_vsizes[5] + tx_vsizes[6]) - (low_fee + med_fee));
534 }
535 // Feerate between tx6 and tx7's ancestor feerates: don't need to bump tx5 because tx7 already does.
536 {
537 const auto just_above_tx6 = CFeeRate(med_fee + 10, tx_vsizes[6]);
538 BOOST_CHECK(just_above_tx6 <= CFeeRate(low_fee + high_fee, tx_vsizes[5] + tx_vsizes[7]));
539 node::MiniMiner mini_miner(pool, all_unspent_outpoints);
540 BOOST_CHECK(mini_miner.IsReadyToCalculate());
541 auto bump_fees = mini_miner.CalculateBumpFees(just_above_tx6);
542 BOOST_CHECK(!mini_miner.IsReadyToCalculate());
543 BOOST_CHECK_EQUAL(bump_fees.size(), all_unspent_outpoints.size());
544 BOOST_CHECK(sanity_check(all_transactions, bump_fees));
545 const auto tx6_bumpfee = bump_fees.find(COutPoint{tx6->GetHash(), 0});
546 BOOST_CHECK(tx6_bumpfee != bump_fees.end());
547 BOOST_CHECK_EQUAL(tx6_bumpfee->second, just_above_tx6.GetFee(tx_vsizes[6]) - (med_fee));
548 const auto tx7_bumpfee = bump_fees.find(COutPoint{tx7->GetHash(), 0});
549 BOOST_CHECK(tx7_bumpfee != bump_fees.end());
550 BOOST_CHECK_EQUAL(tx7_bumpfee->second, 0);
551 }
552 // Check linearization order
553 std::vector<node::MiniMinerMempoolEntry> miniminer_info;
554 miniminer_info.emplace_back(tx0,/*vsize_self=*/tx_vsizes[0], /*vsize_ancestor=*/tx_vsizes[0], /*fee_self=*/low_fee, /*fee_ancestor=*/low_fee);
555 miniminer_info.emplace_back(tx1, tx_vsizes[1], tx_vsizes[1], med_fee, med_fee);
556 miniminer_info.emplace_back(tx2, tx_vsizes[2], tx_vsizes[2], high_fee, high_fee);
557 miniminer_info.emplace_back(tx3, tx_vsizes[3], tx_vsizes[0]+tx_vsizes[1]+tx_vsizes[2]+tx_vsizes[3], high_fee, low_fee+med_fee+2*high_fee);
558 miniminer_info.emplace_back(tx4, tx_vsizes[4], tx_vsizes[4], high_fee, high_fee);
559 miniminer_info.emplace_back(tx5, tx_vsizes[5], tx_vsizes[4]+tx_vsizes[5], low_fee, low_fee + high_fee);
560 miniminer_info.emplace_back(tx6, tx_vsizes[6], tx_vsizes[4]+tx_vsizes[5]+tx_vsizes[6], med_fee, high_fee+low_fee+med_fee);
561 miniminer_info.emplace_back(tx7, tx_vsizes[7], tx_vsizes[4]+tx_vsizes[5]+tx_vsizes[7], high_fee, high_fee+low_fee+high_fee);
562
563 std::map<Txid, std::set<Txid>> descendant_caches;
564 descendant_caches.emplace(tx0->GetHash(), std::set<Txid>{tx0->GetHash(), tx3->GetHash()});
565 descendant_caches.emplace(tx1->GetHash(), std::set<Txid>{tx1->GetHash(), tx3->GetHash()});
566 descendant_caches.emplace(tx2->GetHash(), std::set<Txid>{tx2->GetHash(), tx3->GetHash()});
567 descendant_caches.emplace(tx3->GetHash(), std::set<Txid>{tx3->GetHash()});
568 descendant_caches.emplace(tx4->GetHash(), std::set<Txid>{tx4->GetHash(), tx5->GetHash(), tx6->GetHash(), tx7->GetHash()});
569 descendant_caches.emplace(tx5->GetHash(), std::set<Txid>{tx5->GetHash(), tx6->GetHash(), tx7->GetHash()});
570 descendant_caches.emplace(tx6->GetHash(), std::set<Txid>{tx6->GetHash()});
571 descendant_caches.emplace(tx7->GetHash(), std::set<Txid>{tx7->GetHash()});
572
573 node::MiniMiner miniminer_manual(miniminer_info, descendant_caches);
574 // Use unspent outpoints to avoid entries being omitted.
575 node::MiniMiner miniminer_pool(pool, all_unspent_outpoints);
576 BOOST_CHECK(miniminer_manual.IsReadyToCalculate());
577 BOOST_CHECK(miniminer_pool.IsReadyToCalculate());
578 for (const auto& sequences : {miniminer_manual.Linearize(), miniminer_pool.Linearize()}) {
579 // tx2 and tx4 selected first: high feerate with nothing to bump
580 BOOST_CHECK_EQUAL(Find(sequences, tx4->GetHash()), 0);
581 BOOST_CHECK_EQUAL(Find(sequences, tx2->GetHash()), 1);
582
583 // tx5 + tx7 CPFP
584 BOOST_CHECK_EQUAL(Find(sequences, tx5->GetHash()), 2);
585 BOOST_CHECK_EQUAL(Find(sequences, tx7->GetHash()), 2);
586
587 // tx0 and tx1 CPFP'd by tx3
588 BOOST_CHECK_EQUAL(Find(sequences, tx0->GetHash()), 3);
589 BOOST_CHECK_EQUAL(Find(sequences, tx1->GetHash()), 3);
590 BOOST_CHECK_EQUAL(Find(sequences, tx3->GetHash()), 3);
591
592 // tx6 at medium feerate
593 BOOST_CHECK_EQUAL(Find(sequences, tx6->GetHash()), 4);
594 }
595}
597{
599 LOCK2(cs_main, pool.cs);
600
601 // Add 500 transactions in 10 clusters
602 std::vector<Txid> last_txs;
603 std::vector<Txid> chain_txids;
604 auto& lasttx = m_coinbase_txns[0];
606 for (int cluster_count=0; cluster_count < 10; ++cluster_count) {
607 // Add chain of size 50
608 lasttx = m_coinbase_txns[cluster_count];
609 for (auto i{0}; i < 50; ++i) {
610 const auto tx = make_tx({COutPoint{lasttx->GetHash(), 0}}, /*num_outputs=*/1);
611 AddToMempool(pool, entry.Fee(CENT).FromTx(tx));
612 chain_txids.push_back(tx->GetHash());
613 lasttx = tx;
614 }
615 last_txs.emplace_back(lasttx->GetHash());
616 }
617 const auto cluster_500tx = pool.GatherClusters(last_txs);
618 CTxMemPool::setEntries cluster_500tx_set{cluster_500tx.begin(), cluster_500tx.end()};
619 BOOST_CHECK_EQUAL(cluster_500tx.size(), cluster_500tx_set.size());
620 const auto vec_iters_500 = pool.GetIterVec(chain_txids);
621 for (const auto& iter : vec_iters_500) BOOST_CHECK(cluster_500tx_set.count(iter));
622
623 // GatherClusters stops at 500 transactions.
624 const auto tx_501 = make_tx({COutPoint{lasttx->GetHash(), 0}}, /*num_outputs=*/1);
625 AddToMempool(pool, entry.Fee(CENT).FromTx(tx_501));
626 const auto cluster_501 = pool.GatherClusters(last_txs);
627 BOOST_CHECK_EQUAL(cluster_501.size(), 0);
628
629 /* Zig Zag cluster:
630 * txp0 txp1 txp2 ... txp30 txp31
631 * \ / \ / \ \ /
632 * txc0 txc1 txc2 ... txc30
633 * Note that each transaction's ancestor size is 1 or 3, and each descendant size is 1, 2 or 3.
634 * However, all of these transactions are in the same cluster. */
635 std::vector<Txid> zigzag_txids;
636 for (auto p{0}; p < 32; ++p) {
637 const auto txp = make_tx({COutPoint{Txid::FromUint256(GetRandHash()), 0}}, /*num_outputs=*/2);
638 AddToMempool(pool, entry.Fee(CENT).FromTx(txp));
639 zigzag_txids.push_back(txp->GetHash());
640 }
641 for (auto c{0}; c < 31; ++c) {
642 const auto txc = make_tx({COutPoint{zigzag_txids[c], 1}, COutPoint{zigzag_txids[c+1], 0}}, /*num_outputs=*/1);
643 AddToMempool(pool, entry.Fee(CENT).FromTx(txc));
644 zigzag_txids.push_back(txc->GetHash());
645 }
646 const auto vec_iters_zigzag = pool.GetIterVec(zigzag_txids);
647 // It doesn't matter which tx we calculate cluster for, everybody is in it.
648 const std::vector<size_t> indices{0, 22, 52, zigzag_txids.size() - 1};
649 for (const auto index : indices) {
650 const auto cluster = pool.GatherClusters({zigzag_txids[index]});
651 BOOST_CHECK_EQUAL(cluster.size(), zigzag_txids.size());
652 CTxMemPool::setEntries clusterset{cluster.begin(), cluster.end()};
653 BOOST_CHECK_EQUAL(cluster.size(), clusterset.size());
654 for (const auto& iter : vec_iters_zigzag) BOOST_CHECK(clusterset.count(iter));
655 }
656}
657
659{
661 LOCK2(cs_main, pool.cs);
662 {
663 // 3 pairs of grandparent + fee-bumping parent, plus 1 low-feerate child.
664 // 0 fee + high fee
665 auto grandparent_zero_fee = make_tx({{m_coinbase_txns.at(0)->GetHash(), 0}}, 1);
666 auto parent_high_feerate = make_tx({{grandparent_zero_fee->GetHash(), 0}}, 1);
667 // double low fee + med fee
668 auto grandparent_double_low_feerate = make_tx({{m_coinbase_txns.at(2)->GetHash(), 0}}, 1);
669 auto parent_med_feerate = make_tx({{grandparent_double_low_feerate->GetHash(), 0}}, 1);
670 // low fee + double low fee
671 auto grandparent_low_feerate = make_tx({{m_coinbase_txns.at(1)->GetHash(), 0}}, 1);
672 auto parent_double_low_feerate = make_tx({{grandparent_low_feerate->GetHash(), 0}}, 1);
673 // child is below the cpfp package feerates because it is larger than everything else
674 auto child = make_tx({{parent_high_feerate->GetHash(), 0}, {parent_double_low_feerate->GetHash(), 0}, {parent_med_feerate->GetHash(), 0}}, 1);
675
676 // We artificially record each transaction (except the child) with a uniform vsize of 100vB.
677 const int64_t tx_vsize{100};
678 const int64_t child_vsize{1000};
679
680 std::vector<node::MiniMinerMempoolEntry> miniminer_info;
681 miniminer_info.emplace_back(grandparent_zero_fee, /*vsize_self=*/tx_vsize,/*vsize_ancestor=*/tx_vsize, /*fee_self=*/0,/*fee_ancestor=*/0);
682 miniminer_info.emplace_back(parent_high_feerate, tx_vsize, 2*tx_vsize, high_fee, high_fee);
683 miniminer_info.emplace_back(grandparent_double_low_feerate, tx_vsize, tx_vsize, 2*low_fee, 2*low_fee);
684 miniminer_info.emplace_back(parent_med_feerate, tx_vsize, 2*tx_vsize, med_fee, 2*low_fee+med_fee);
685 miniminer_info.emplace_back(grandparent_low_feerate, tx_vsize, tx_vsize, low_fee, low_fee);
686 miniminer_info.emplace_back(parent_double_low_feerate, tx_vsize, 2*tx_vsize, 2*low_fee, 3*low_fee);
687 miniminer_info.emplace_back(child, child_vsize, 6*tx_vsize+child_vsize, low_fee, high_fee+med_fee+6*low_fee);
688 std::map<Txid, std::set<Txid>> descendant_caches;
689 descendant_caches.emplace(grandparent_zero_fee->GetHash(), std::set<Txid>{grandparent_zero_fee->GetHash(), parent_high_feerate->GetHash(), child->GetHash()});
690 descendant_caches.emplace(grandparent_low_feerate->GetHash(), std::set<Txid>{grandparent_low_feerate->GetHash(), parent_double_low_feerate->GetHash(), child->GetHash()});
691 descendant_caches.emplace(grandparent_double_low_feerate->GetHash(), std::set<Txid>{grandparent_double_low_feerate->GetHash(), parent_med_feerate->GetHash(), child->GetHash()});
692 descendant_caches.emplace(parent_high_feerate->GetHash(), std::set<Txid>{parent_high_feerate->GetHash(), child->GetHash()});
693 descendant_caches.emplace(parent_med_feerate->GetHash(), std::set<Txid>{parent_med_feerate->GetHash(), child->GetHash()});
694 descendant_caches.emplace(parent_double_low_feerate->GetHash(), std::set<Txid>{parent_double_low_feerate->GetHash(), child->GetHash()});
695 descendant_caches.emplace(child->GetHash(), std::set<Txid>{child->GetHash()});
696
697 node::MiniMiner miniminer_manual(miniminer_info, descendant_caches);
698 BOOST_CHECK(miniminer_manual.IsReadyToCalculate());
699 const auto sequences{miniminer_manual.Linearize()};
700
701 // CPFP zero + high
702 BOOST_CHECK_EQUAL(sequences.at(grandparent_zero_fee->GetHash()), 0);
703 BOOST_CHECK_EQUAL(sequences.at(parent_high_feerate->GetHash()), 0);
704
705 // CPFP double low + med
706 BOOST_CHECK_EQUAL(sequences.at(grandparent_double_low_feerate->GetHash()), 1);
707 BOOST_CHECK_EQUAL(sequences.at(parent_med_feerate->GetHash()), 1);
708
709 // CPFP low + double low
710 BOOST_CHECK_EQUAL(sequences.at(grandparent_low_feerate->GetHash()), 2);
711 BOOST_CHECK_EQUAL(sequences.at(parent_double_low_feerate->GetHash()), 2);
712
713 // Child at the end
714 BOOST_CHECK_EQUAL(sequences.at(child->GetHash()), 3);
715 }
716}
717
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
static constexpr CAmount COIN
The amount of satoshis in one BTC.
Definition: amount.h:15
AddToMempool(pool, CTxMemPoolEntry(TxGraph::Ref(), tx, fee, 0, 1, 0, false, 4, lp))
node::NodeContext m_node
Definition: bitcoin-gui.cpp:43
#define Assert(val)
Identity function.
Definition: check.h:113
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
Definition: feerate.h:35
CAmount GetFee(int32_t virtual_bytes) const
Return the fee in satoshis for the given vsize in vbytes.
Definition: feerate.cpp:20
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:29
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:413
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:189
void PrioritiseTransaction(const Txid &hash, const CAmount &nFeeDelta)
Affect CreateNewBlock prioritisation of transactions.
Definition: txmempool.cpp:584
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
Definition: txmempool.h:263
std::vector< txiter > GetIterVec(const std::vector< Txid > &txids) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Translate a list of hashes into a list of mempool iterators to avoid repeated lookups.
Definition: txmempool.cpp:673
std::set< txiter, CompareIteratorByHash > setEntries
Definition: txmempool.h:271
std::vector< txiter > GatherClusters(const std::vector< Txid > &txids) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Collect the entire cluster of connected transactions for each transaction in txids.
Definition: txmempool.cpp:922
const CTransaction * GetConflictTx(const COutPoint &prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Get the transaction in the pool that spends the same prevout.
Definition: txmempool.cpp:643
std::tuple< size_t, size_t, CAmount > CalculateAncestorData(const CTxMemPoolEntry &entry) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:867
bool isSpent(const COutPoint &outpoint) const
Definition: txmempool.cpp:180
const CTxMemPoolEntry * GetEntry(const Txid &txid) const LIFETIMEBOUND EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:568
A minimal version of BlockAssembler, using the same ancestor set scoring algorithm.
Definition: mini_miner.h:79
std::map< Txid, uint32_t > Linearize()
Construct a new block template with all of the transactions and calculate the order in which they are...
Definition: mini_miner.cpp:305
std::map< COutPoint, CAmount > CalculateBumpFees(const CFeeRate &target_feerate)
Construct a new block template and, for each outpoint corresponding to a transaction that did not mak...
Definition: mini_miner.cpp:311
bool IsReadyToCalculate() const
Returns true if CalculateBumpFees may be called, false if not.
Definition: mini_miner.h:125
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()
uint64_t fee
const CAmount med_fee
BOOST_FIXTURE_TEST_CASE(miniminer_negative, TestChain100Setup)
static bool sanity_check(const std::vector< CTransactionRef > &transactions, const std::map< COutPoint, CAmount > &bumpfees)
static CTransactionRef make_tx(const std::vector< COutPoint > &inputs, size_t num_outputs)
const CAmount high_fee
const CAmount low_fee
Value Find(const std::map< Key, Value > &map, const Key &key)
RPCHelpMan bumpfee()
Definition: spend.cpp:1214
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:18
#define BOOST_CHECK(expr)
Definition: object.cpp:17
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost, unsigned int bytes_per_sigop)
Compute the virtual transaction size (weight reinterpreted as bytes).
Definition: policy.cpp:381
static CTransactionRef MakeTransactionRef(Tx &&txIn)
Definition: transaction.h:424
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:423
uint256 GetRandHash() noexcept
Generate a random uint256.
Definition: random.h:463
@ OP_EQUAL
Definition: script.h:146
@ OP_11
Definition: script.h:94
static constexpr CAmount CENT
Definition: setup_common.h:47
A mutable version of CTransaction.
Definition: transaction.h:378
std::vector< CTxOut > vout
Definition: transaction.h:380
std::vector< CTxIn > vin
Definition: transaction.h:379
Testing fixture that pre-creates a 100-block REGTEST-mode block chain.
Definition: setup_common.h:146
Definition: txmempool.h:19
CTxMemPoolEntry FromTx(const CMutableTransaction &tx) const
Definition: txmempool.cpp:34
TestMemPoolEntryHelper & Fee(CAmount _fee)
Definition: txmempool.h:33
Testing setup that configures a complete environment.
Definition: setup_common.h:121
std::unique_ptr< CTxMemPool > mempool
Definition: context.h:68
#define LOCK2(cs1, cs2)
Definition: sync.h:260
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1172