Bitcoin Core 30.99.0
P2P Digital Currency
package_eval.cpp
Go to the documentation of this file.
1// Copyright (c) 2023 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
6#include <node/context.h>
7#include <node/mempool_args.h>
8#include <node/miner.h>
11#include <test/fuzz/fuzz.h>
12#include <test/fuzz/util.h>
14#include <test/util/mining.h>
15#include <test/util/script.h>
17#include <test/util/txmempool.h>
18#include <util/check.h>
19#include <util/rbf.h>
20#include <util/translation.h>
21#include <validation.h>
22#include <validationinterface.h>
23
26
27namespace {
28
29const TestingSetup* g_setup;
30std::vector<COutPoint> g_outpoints_coinbase_init_mature;
31
32struct MockedTxPool : public CTxMemPool {
33 void RollingFeeUpdate() EXCLUSIVE_LOCKS_REQUIRED(!cs)
34 {
35 LOCK(cs);
36 lastRollingFeeUpdate = GetTime();
37 blockSinceLastRollingFeeBump = true;
38 }
39};
40
41void initialize_tx_pool()
42{
43 static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
44 g_setup = testing_setup.get();
45 SetMockTime(WITH_LOCK(g_setup->m_node.chainman->GetMutex(), return g_setup->m_node.chainman->ActiveTip()->Time()));
46
47 BlockAssembler::Options options;
48 options.coinbase_output_script = P2WSH_EMPTY;
49
50 for (int i = 0; i < 2 * COINBASE_MATURITY; ++i) {
51 COutPoint prevout{MineBlock(g_setup->m_node, options)};
52 if (i < COINBASE_MATURITY) {
53 // Remember the txids to avoid expensive disk access later on
54 g_outpoints_coinbase_init_mature.push_back(prevout);
55 }
56 }
57 g_setup->m_node.validation_signals->SyncWithValidationInterfaceQueue();
58}
59
60struct OutpointsUpdater final : public CValidationInterface {
61 std::set<COutPoint>& m_mempool_outpoints;
62
63 explicit OutpointsUpdater(std::set<COutPoint>& r)
64 : m_mempool_outpoints{r} {}
65
66 void TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t /* mempool_sequence */) override
67 {
68 // for coins spent we always want to be able to rbf so they're not removed
69
70 // outputs from this tx can now be spent
71 for (uint32_t index{0}; index < tx.info.m_tx->vout.size(); ++index) {
72 m_mempool_outpoints.insert(COutPoint{tx.info.m_tx->GetHash(), index});
73 }
74 }
75
76 void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t /* mempool_sequence */) override
77 {
78 // outpoints spent by this tx are now available
79 for (const auto& input : tx->vin) {
80 // Could already exist if this was a replacement
81 m_mempool_outpoints.insert(input.prevout);
82 }
83 // outpoints created by this tx no longer exist
84 for (uint32_t index{0}; index < tx->vout.size(); ++index) {
85 m_mempool_outpoints.erase(COutPoint{tx->GetHash(), index});
86 }
87 }
88};
89
90struct TransactionsDelta final : public CValidationInterface {
91 std::set<CTransactionRef>& m_added;
92
93 explicit TransactionsDelta(std::set<CTransactionRef>& a)
94 : m_added{a} {}
95
96 void TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t /* mempool_sequence */) override
97 {
98 // Transactions may be entered and booted any number of times
99 m_added.insert(tx.info.m_tx);
100 }
101
102 void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t /* mempool_sequence */) override
103 {
104 // Transactions may be entered and booted any number of times
105 m_added.erase(tx);
106 }
107};
108
109void MockTime(FuzzedDataProvider& fuzzed_data_provider, const Chainstate& chainstate)
110{
111 const auto time = ConsumeTime(fuzzed_data_provider,
112 chainstate.m_chain.Tip()->GetMedianTimePast() + 1,
113 std::numeric_limits<decltype(chainstate.m_chain.Tip()->nTime)>::max());
114 SetMockTime(time);
115}
116
117std::unique_ptr<CTxMemPool> MakeMempool(FuzzedDataProvider& fuzzed_data_provider, const NodeContext& node)
118{
119 // Take the default options for tests...
121
122
123 // ...override specific options for this specific fuzz suite
125 mempool_opts.limits.descendant_count = fuzzed_data_provider.ConsumeIntegralInRange<unsigned>(0, 50);
126 mempool_opts.max_size_bytes = fuzzed_data_provider.ConsumeIntegralInRange<unsigned>(0, 200) * 1'000'000;
127 mempool_opts.expiry = std::chrono::hours{fuzzed_data_provider.ConsumeIntegralInRange<unsigned>(0, 999)};
128 // Only interested in 2 cases: sigop cost 0 or when single legacy sigop cost is >> 1KvB
130
131 mempool_opts.check_ratio = 1;
132 mempool_opts.require_standard = fuzzed_data_provider.ConsumeBool();
133
134 bilingual_str error;
135 // ...and construct a CTxMemPool from it
136 auto mempool{std::make_unique<CTxMemPool>(std::move(mempool_opts), error)};
137 // ... ignore the error since it might be beneficial to fuzz even when the
138 // mempool size is unreasonably small
139 Assert(error.empty() || error.original.starts_with("-maxmempool must be at least "));
140 return mempool;
141}
142
143std::unique_ptr<CTxMemPool> MakeEphemeralMempool(const NodeContext& node)
144{
145 // Take the default options for tests...
147
148 mempool_opts.check_ratio = 1;
149
150 // Require standardness rules otherwise ephemeral dust is no-op
151 mempool_opts.require_standard = true;
152
153 // And set minrelay to 0 to allow ephemeral parent tx even with non-TRUC
154 mempool_opts.min_relay_feerate = CFeeRate(0);
155
156 bilingual_str error;
157 // ...and construct a CTxMemPool from it
158 auto mempool{std::make_unique<CTxMemPool>(std::move(mempool_opts), error)};
159 Assert(error.empty());
160 return mempool;
161}
162
163// Scan mempool for a tx that has spent dust and return a
164// prevout of the child that isn't the dusty parent itself.
165// This is used to double-spend the child out of the mempool,
166// leaving the parent childless.
167// This assumes CheckMempoolEphemeralInvariants has passed for tx_pool.
168std::optional<COutPoint> GetChildEvictingPrevout(const CTxMemPool& tx_pool)
169{
170 LOCK(tx_pool.cs);
171 for (const auto& tx_info : tx_pool.infoAll()) {
172 const auto& entry = *Assert(tx_pool.GetEntry(tx_info.tx->GetHash()));
173 std::vector<uint32_t> dust_indexes{GetDust(*tx_info.tx, tx_pool.m_opts.dust_relay_feerate)};
174 if (!dust_indexes.empty()) {
175 const auto& children = tx_pool.GetChildren(entry);
176 if (!children.empty()) {
177 Assert(children.size() == 1);
178 // Find an input that doesn't spend from parent's txid
179 const auto& only_child = children.begin()->get().GetTx();
180 for (const auto& tx_input : only_child.vin) {
181 if (tx_input.prevout.hash != tx_info.tx->GetHash()) {
182 return tx_input.prevout;
183 }
184 }
185 }
186 }
187 }
188
189 return std::nullopt;
190}
191
192FUZZ_TARGET(ephemeral_package_eval, .init = initialize_tx_pool)
193{
195 FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
196 const auto& node = g_setup->m_node;
197 auto& chainstate{static_cast<DummyChainState&>(node.chainman->ActiveChainstate())};
198
199 MockTime(fuzzed_data_provider, chainstate);
200
201 // All RBF-spendable outpoints outside of the unsubmitted package
202 std::set<COutPoint> mempool_outpoints;
203 std::unordered_map<COutPoint, CAmount, SaltedOutpointHasher> outpoints_value;
204 for (const auto& outpoint : g_outpoints_coinbase_init_mature) {
205 Assert(mempool_outpoints.insert(outpoint).second);
206 outpoints_value[outpoint] = 50 * COIN;
207 }
208
209 auto outpoints_updater = std::make_shared<OutpointsUpdater>(mempool_outpoints);
210 node.validation_signals->RegisterSharedValidationInterface(outpoints_updater);
211
212 auto tx_pool_{MakeEphemeralMempool(node)};
213 MockedTxPool& tx_pool = *static_cast<MockedTxPool*>(tx_pool_.get());
214
215 chainstate.SetMempool(&tx_pool);
216
218 {
219 Assert(!mempool_outpoints.empty());
220
221 std::vector<CTransactionRef> txs;
222
223 // Find something we may want to double-spend with two input single tx
224 std::optional<COutPoint> outpoint_to_rbf{fuzzed_data_provider.ConsumeBool() ? GetChildEvictingPrevout(tx_pool) : std::nullopt};
225
226 // Make small packages
227 const auto num_txs = outpoint_to_rbf ? 1 : fuzzed_data_provider.ConsumeIntegralInRange<size_t>(1, 4);
228
229 std::set<COutPoint> package_outpoints;
230 while (txs.size() < num_txs) {
231 // Create transaction to add to the mempool
232 txs.emplace_back([&] {
233 CMutableTransaction tx_mut;
235 tx_mut.nLockTime = 0;
236 // Last transaction in a package needs to be a child of parents to get further in validation
237 // so the last transaction to be generated(in a >1 package) must spend all package-made outputs
238 // Note that this test currently only spends package outputs in last transaction.
239 bool last_tx = num_txs > 1 && txs.size() == num_txs - 1;
240 const auto num_in = outpoint_to_rbf ? 2 :
241 last_tx ? fuzzed_data_provider.ConsumeIntegralInRange<int>(package_outpoints.size()/2 + 1, package_outpoints.size()) :
243 const auto num_out = outpoint_to_rbf ? 1 : fuzzed_data_provider.ConsumeIntegralInRange<int>(1, 4);
244
245 auto& outpoints = last_tx ? package_outpoints : mempool_outpoints;
246
247 Assert((int)outpoints.size() >= num_in && num_in > 0);
248
249 CAmount amount_in{0};
250 for (int i = 0; i < num_in; ++i) {
251 // Pop random outpoint. We erase them to avoid double-spending
252 // while in this loop, but later add them back (unless last_tx).
253 auto pop = outpoints.begin();
254 std::advance(pop, fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, outpoints.size() - 1));
255 auto outpoint = *pop;
256
257 if (i == 0 && outpoint_to_rbf) {
258 outpoint = *outpoint_to_rbf;
259 outpoints.erase(outpoint);
260 } else {
261 outpoints.erase(pop);
262 }
263 // no need to update or erase from outpoints_value
264 amount_in += outpoints_value.at(outpoint);
265
266 // Create input
267 CTxIn in;
268 in.prevout = outpoint;
270
271 tx_mut.vin.push_back(in);
272 }
273
274 const auto amount_fee = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(0, amount_in);
275 const auto amount_out = (amount_in - amount_fee) / num_out;
276 for (int i = 0; i < num_out; ++i) {
277 tx_mut.vout.emplace_back(amount_out, P2WSH_EMPTY);
278 }
279
280 // Note output amounts can naturally drop to dust on their own.
281 if (!outpoint_to_rbf && fuzzed_data_provider.ConsumeBool()) {
282 uint32_t dust_index = fuzzed_data_provider.ConsumeIntegralInRange<uint32_t>(0, num_out);
283 tx_mut.vout.insert(tx_mut.vout.begin() + dust_index, CTxOut(0, P2WSH_EMPTY));
284 }
285
286 auto tx = MakeTransactionRef(tx_mut);
287 // Restore previously removed outpoints, except in-package outpoints (to allow RBF)
288 if (!last_tx) {
289 for (const auto& in : tx->vin) {
290 Assert(outpoints.insert(in.prevout).second);
291 }
292 // Cache the in-package outpoints being made
293 for (size_t i = 0; i < tx->vout.size(); ++i) {
294 package_outpoints.emplace(tx->GetHash(), i);
295 }
296 }
297 // We need newly-created values for the duration of this run
298 for (size_t i = 0; i < tx->vout.size(); ++i) {
299 outpoints_value[COutPoint(tx->GetHash(), i)] = tx->vout[i].nValue;
300 }
301 return tx;
302 }());
303 }
304
306 const auto& txid = fuzzed_data_provider.ConsumeBool() ?
307 txs.back()->GetHash() :
308 PickValue(fuzzed_data_provider, mempool_outpoints).hash;
309 const auto delta = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-50 * COIN, +50 * COIN);
310 // We only prioritise out of mempool transactions since PrioritiseTransaction doesn't
311 // filter for ephemeral dust
312 if (tx_pool.exists(txid)) {
313 const auto tx_info{tx_pool.info(txid)};
314 if (GetDust(*tx_info.tx, tx_pool.m_opts.dust_relay_feerate).empty()) {
315 tx_pool.PrioritiseTransaction(txid, delta);
316 }
317 }
318 }
319
320 auto single_submit = txs.size() == 1;
321
322 const auto result_package = WITH_LOCK(::cs_main,
323 return ProcessNewPackage(chainstate, tx_pool, txs, /*test_accept=*/single_submit, /*client_maxfeerate=*/{}));
324
325 const auto res = WITH_LOCK(::cs_main, return AcceptToMemoryPool(chainstate, txs.back(), GetTime(),
326 /*bypass_limits=*/false, /*test_accept=*/!single_submit));
327
328 if (!single_submit && result_package.m_state.GetResult() != PackageValidationResult::PCKG_POLICY) {
329 // We don't know anything about the validity since transactions were randomly generated, so
330 // just use result_package.m_state here. This makes the expect_valid check meaningless, but
331 // we can still verify that the contents of m_tx_results are consistent with m_state.
332 const bool expect_valid{result_package.m_state.IsValid()};
333 Assert(!CheckPackageMempoolAcceptResult(txs, result_package, expect_valid, &tx_pool));
334 }
335
336 node.validation_signals->SyncWithValidationInterfaceQueue();
337
339 }
340
341 node.validation_signals->UnregisterSharedValidationInterface(outpoints_updater);
342
343 WITH_LOCK(::cs_main, tx_pool.check(chainstate.CoinsTip(), chainstate.m_chain.Height() + 1));
344}
345
346
347FUZZ_TARGET(tx_package_eval, .init = initialize_tx_pool)
348{
350 FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
351 const auto& node = g_setup->m_node;
352 auto& chainstate{static_cast<DummyChainState&>(node.chainman->ActiveChainstate())};
353
354 MockTime(fuzzed_data_provider, chainstate);
355
356 // All RBF-spendable outpoints outside of the unsubmitted package
357 std::set<COutPoint> mempool_outpoints;
358 std::unordered_map<COutPoint, CAmount, SaltedOutpointHasher> outpoints_value;
359 for (const auto& outpoint : g_outpoints_coinbase_init_mature) {
360 Assert(mempool_outpoints.insert(outpoint).second);
361 outpoints_value[outpoint] = 50 * COIN;
362 }
363
364 auto outpoints_updater = std::make_shared<OutpointsUpdater>(mempool_outpoints);
365 node.validation_signals->RegisterSharedValidationInterface(outpoints_updater);
366
367 auto tx_pool_{MakeMempool(fuzzed_data_provider, node)};
368 MockedTxPool& tx_pool = *static_cast<MockedTxPool*>(tx_pool_.get());
369
370 chainstate.SetMempool(&tx_pool);
371
373 {
374 Assert(!mempool_outpoints.empty());
375
376 std::vector<CTransactionRef> txs;
377
378 // Make packages of 1-to-26 transactions
379 const auto num_txs = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(1, 26);
380 std::set<COutPoint> package_outpoints;
381 while (txs.size() < num_txs) {
382 // Create transaction to add to the mempool
383 txs.emplace_back([&] {
384 CMutableTransaction tx_mut;
387 // Last transaction in a package needs to be a child of parents to get further in validation
388 // so the last transaction to be generated(in a >1 package) must spend all package-made outputs
389 // Note that this test currently only spends package outputs in last transaction.
390 bool last_tx = num_txs > 1 && txs.size() == num_txs - 1;
391 const auto num_in = last_tx ? package_outpoints.size() : fuzzed_data_provider.ConsumeIntegralInRange<int>(1, mempool_outpoints.size());
392 auto num_out = fuzzed_data_provider.ConsumeIntegralInRange<int>(1, mempool_outpoints.size() * 2);
393
394 auto& outpoints = last_tx ? package_outpoints : mempool_outpoints;
395
396 Assert(!outpoints.empty());
397
398 CAmount amount_in{0};
399 for (size_t i = 0; i < num_in; ++i) {
400 // Pop random outpoint. We erase them to avoid double-spending
401 // while in this loop, but later add them back (unless last_tx).
402 auto pop = outpoints.begin();
403 std::advance(pop, fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, outpoints.size() - 1));
404 const auto outpoint = *pop;
405 outpoints.erase(pop);
406 // no need to update or erase from outpoints_value
407 amount_in += outpoints_value.at(outpoint);
408
409 // Create input
411 const auto script_sig = CScript{};
413
414 CTxIn in;
415 in.prevout = outpoint;
416 in.nSequence = sequence;
417 in.scriptSig = script_sig;
418 in.scriptWitness.stack = script_wit_stack;
419
420 tx_mut.vin.push_back(in);
421 }
422
423 // Duplicate an input
424 bool dup_input = fuzzed_data_provider.ConsumeBool();
425 if (dup_input) {
426 tx_mut.vin.push_back(tx_mut.vin.back());
427 }
428
429 // Refer to a non-existent input
431 tx_mut.vin.emplace_back();
432 }
433
434 // Make a p2pk output to make sigops adjusted vsize to violate TRUC rules, potentially, which is never spent
435 if (last_tx && amount_in > 1000 && fuzzed_data_provider.ConsumeBool()) {
436 tx_mut.vout.emplace_back(1000, CScript() << std::vector<unsigned char>(33, 0x02) << OP_CHECKSIG);
437 // Don't add any other outputs.
438 num_out = 1;
439 amount_in -= 1000;
440 }
441
442 const auto amount_fee = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(0, amount_in);
443 const auto amount_out = (amount_in - amount_fee) / num_out;
444 for (int i = 0; i < num_out; ++i) {
445 tx_mut.vout.emplace_back(amount_out, P2WSH_EMPTY);
446 }
447 auto tx = MakeTransactionRef(tx_mut);
448 // Restore previously removed outpoints, except in-package outpoints
449 if (!last_tx) {
450 for (const auto& in : tx->vin) {
451 // It's a fake input, or a new input, or a duplicate
452 Assert(in == CTxIn() || outpoints.insert(in.prevout).second || dup_input);
453 }
454 // Cache the in-package outpoints being made
455 for (size_t i = 0; i < tx->vout.size(); ++i) {
456 package_outpoints.emplace(tx->GetHash(), i);
457 }
458 }
459 // We need newly-created values for the duration of this run
460 for (size_t i = 0; i < tx->vout.size(); ++i) {
461 outpoints_value[COutPoint(tx->GetHash(), i)] = tx->vout[i].nValue;
462 }
463 return tx;
464 }());
465 }
466
468 MockTime(fuzzed_data_provider, chainstate);
469 }
471 tx_pool.RollingFeeUpdate();
472 }
474 const auto& txid = fuzzed_data_provider.ConsumeBool() ?
475 txs.back()->GetHash() :
476 PickValue(fuzzed_data_provider, mempool_outpoints).hash;
477 const auto delta = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-50 * COIN, +50 * COIN);
478 tx_pool.PrioritiseTransaction(txid, delta);
479 }
480
481 // Remember all added transactions
482 std::set<CTransactionRef> added;
483 auto txr = std::make_shared<TransactionsDelta>(added);
484 node.validation_signals->RegisterSharedValidationInterface(txr);
485
486 // When there are multiple transactions in the package, we call ProcessNewPackage(txs, test_accept=false)
487 // and AcceptToMemoryPool(txs.back(), test_accept=true). When there is only 1 transaction, we might flip it
488 // (the package is a test accept and ATMP is a submission).
489 auto single_submit = txs.size() == 1 && fuzzed_data_provider.ConsumeBool();
490
491 // Exercise client_maxfeerate logic
492 std::optional<CFeeRate> client_maxfeerate{};
494 client_maxfeerate = CFeeRate(fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-1, 50 * COIN), 100);
495 }
496
497 const auto result_package = WITH_LOCK(::cs_main,
498 return ProcessNewPackage(chainstate, tx_pool, txs, /*test_accept=*/single_submit, client_maxfeerate));
499
500 // Always set bypass_limits to false because it is not supported in ProcessNewPackage and
501 // can be a source of divergence.
502 const auto res = WITH_LOCK(::cs_main, return AcceptToMemoryPool(chainstate, txs.back(), GetTime(),
503 /*bypass_limits=*/false, /*test_accept=*/!single_submit));
504 const bool passed = res.m_result_type == MempoolAcceptResult::ResultType::VALID;
505
506 node.validation_signals->SyncWithValidationInterfaceQueue();
507 node.validation_signals->UnregisterSharedValidationInterface(txr);
508
509 // There is only 1 transaction in the package. We did a test-package-accept and a ATMP
510 if (single_submit) {
511 Assert(passed != added.empty());
512 Assert(passed == res.m_state.IsValid());
513 if (passed) {
514 Assert(added.size() == 1);
515 Assert(txs.back() == *added.begin());
516 }
517 } else if (result_package.m_state.GetResult() != PackageValidationResult::PCKG_POLICY) {
518 // We don't know anything about the validity since transactions were randomly generated, so
519 // just use result_package.m_state here. This makes the expect_valid check meaningless, but
520 // we can still verify that the contents of m_tx_results are consistent with m_state.
521 const bool expect_valid{result_package.m_state.IsValid()};
522 Assert(!CheckPackageMempoolAcceptResult(txs, result_package, expect_valid, &tx_pool));
523 } else {
524 // This is empty if it fails early checks, or "full" if transactions are looked at deeper
525 Assert(result_package.m_tx_results.size() == txs.size() || result_package.m_tx_results.empty());
526 }
527
529
530 // Dust checks only make sense when dust is enforced
531 if (tx_pool.m_opts.require_standard) {
533 }
534 }
535
536 node.validation_signals->UnregisterSharedValidationInterface(outpoints_updater);
537
538 WITH_LOCK(::cs_main, tx_pool.check(chainstate.CoinsTip(), chainstate.m_chain.Height() + 1));
539}
540} // namespace
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
static void pool cs
#define Assert(val)
Identity function.
Definition: check.h:113
uint32_t nTime
Definition: chain.h:151
int64_t GetMedianTimePast() const
Definition: chain.h:242
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
Definition: chain.h:397
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
Definition: feerate.h:35
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
static const uint32_t CURRENT_VERSION
Definition: transaction.h:299
An input of a transaction.
Definition: transaction.h:67
uint32_t nSequence
Definition: transaction.h:71
CScript scriptSig
Definition: transaction.h:70
CScriptWitness scriptWitness
Only serialized through CTransaction.
Definition: transaction.h:72
COutPoint prevout
Definition: transaction.h:69
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:189
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
Definition: txmempool.h:263
const Options m_opts
Definition: txmempool.h:306
std::vector< TxMempoolInfo > infoAll() const
Definition: txmempool.cpp:583
std::vector< CTxMemPoolEntry::CTxMemPoolEntryRef > GetChildren(const CTxMemPoolEntry &entry) const
Definition: txmempool.cpp:57
const CTxMemPoolEntry * GetEntry(const Txid &txid) const LIFETIMEBOUND EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:597
An output of a transaction.
Definition: transaction.h:150
Implement this to subscribe to events generated in validation and mempool.
virtual void TransactionRemovedFromMempool(const CTransactionRef &tx, MemPoolRemovalReason reason, uint64_t mempool_sequence)
Notifies listeners of a transaction leaving mempool.
virtual void TransactionAddedToMempool(const NewMempoolTransactionInfo &tx, uint64_t mempool_sequence)
Notifies listeners of a transaction having been added to mempool.
Chainstate stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:532
CChain m_chain
The current chain of blockheaders we consult and build on.
Definition: validation.h:614
T ConsumeIntegralInRange(T min, T max)
Generate a new block, without valid proof-of-work.
Definition: miner.h:57
static const int COINBASE_MATURITY
Coinbase transaction outputs can only be spent after this number of new blocks (network rule)
Definition: consensus.h:19
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: cs_main.cpp:8
#define FUZZ_TARGET(...)
Definition: fuzz.h:35
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
Definition: fuzz.h:22
uint64_t sequence
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal.
Definition: messages.h:21
@ PCKG_POLICY
The package itself is invalid (e.g. too many transactions).
unsigned int nBytesPerSigOp
Definition: settings.cpp:10
std::vector< uint32_t > GetDust(const CTransaction &tx, CFeeRate dust_relay_rate)
Get the vout index numbers of all dust outputs.
Definition: policy.cpp:70
static CTransactionRef MakeTransactionRef(Tx &&txIn)
Definition: transaction.h:424
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:423
@ OP_CHECKSIG
Definition: script.h:190
node::NodeContext m_node
Definition: setup_common.h:66
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
std::vector< std::vector< unsigned char > > stack
Definition: script.h:588
Testing setup that configures a complete environment.
Definition: setup_common.h:121
const CTransactionRef m_tx
Bilingual messages:
Definition: translation.h:24
bool empty() const
Definition: translation.h:35
std::string original
Definition: translation.h:25
int64_t ancestor_count
The maximum allowed number of transactions in a package including the entry and its ancestors.
Options struct containing options for constructing a CTxMemPool.
NodeContext struct containing references to chain state and connection state.
Definition: context.h:56
std::unique_ptr< ValidationSignals > validation_signals
Issues calls about blocks and transactions.
Definition: context.h:88
std::unique_ptr< ChainstateManager > chainman
Definition: context.h:72
#define LOCK(cs)
Definition: sync.h:259
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:290
uint32_t ConsumeSequence(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.cpp:155
int64_t ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
Definition: util.cpp:34
auto & PickValue(FuzzedDataProvider &fuzzed_data_provider, Collection &col)
Definition: util.h:47
COutPoint MineBlock(const NodeContext &node, const node::BlockAssembler::Options &assembler_options)
Returns the generated coin.
Definition: mining.cpp:70
void SeedRandomStateForTest(SeedRand seedtype)
Seed the global RNG state for testing and log the seed value.
Definition: random.cpp:19
@ ZEROS
Seed with a compile time constant of zeros.
static const std::vector< std::vector< uint8_t > > P2WSH_EMPTY_TRUE_STACK
Definition: script.h:31
static const std::vector< std::vector< uint8_t > > P2WSH_EMPTY_TWO_STACK
Definition: script.h:32
static const CScript P2WSH_EMPTY
Definition: script.h:23
void CheckMempoolTRUCInvariants(const CTxMemPool &tx_pool)
For every transaction in tx_pool, check TRUC invariants:
Definition: txmempool.cpp:182
CTxMemPool::Options MemPoolOptionsForTest(const NodeContext &node)
Definition: txmempool.cpp:21
std::optional< std::string > CheckPackageMempoolAcceptResult(const Package &txns, const PackageMempoolAcceptResult &result, bool expect_valid, const CTxMemPool *mempool)
Check expected properties for every PackageMempoolAcceptResult, regardless of value.
Definition: txmempool.cpp:44
void CheckMempoolEphemeralInvariants(const CTxMemPool &tx_pool)
Check that we never get into a state where an ephemeral dust transaction would be mined without the s...
Definition: txmempool.cpp:145
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:51
static constexpr decltype(CTransaction::version) TRUC_VERSION
Definition: truc_policy.h:20
int64_t GetTime()
DEPRECATED Use either ClockType::now() or Now<TimePointType>() if a cast is needed.
Definition: time.cpp:77
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
Definition: time.cpp:40
PackageMempoolAcceptResult ProcessNewPackage(Chainstate &active_chainstate, CTxMemPool &pool, const Package &package, bool test_accept, const std::optional< CFeeRate > &client_maxfeerate)
Validate (and maybe submit) a package to the mempool.
MempoolAcceptResult AcceptToMemoryPool(Chainstate &active_chainstate, const CTransactionRef &tx, int64_t accept_time, bool bypass_limits, bool test_accept)
Try to add a transaction to the mempool.
FuzzedDataProvider & fuzzed_data_provider
Definition: fees.cpp:38