Bitcoin Core  31.0.0
P2P Digital Currency
tx_pool.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 
5 #include <consensus/validation.h>
6 #include <node/context.h>
7 #include <node/mempool_args.h>
8 #include <node/miner.h>
9 #include <policy/truc_policy.h>
11 #include <test/fuzz/fuzz.h>
12 #include <test/fuzz/util.h>
13 #include <test/fuzz/util/mempool.h>
14 #include <test/util/mining.h>
15 #include <test/util/script.h>
16 #include <test/util/setup_common.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 
25 using node::NodeContext;
26 using util::ToString;
27 
28 namespace {
29 
30 const TestingSetup* g_setup;
31 std::vector<COutPoint> g_outpoints_coinbase_init_mature;
32 std::vector<COutPoint> g_outpoints_coinbase_init_immature;
33 
34 struct MockedTxPool : public CTxMemPool {
35  void RollingFeeUpdate() EXCLUSIVE_LOCKS_REQUIRED(!cs)
36  {
37  LOCK(cs);
38  lastRollingFeeUpdate = GetTime();
39  blockSinceLastRollingFeeBump = true;
40  }
41 };
42 
43 void initialize_tx_pool()
44 {
45  static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
46  g_setup = testing_setup.get();
47  SetMockTime(WITH_LOCK(g_setup->m_node.chainman->GetMutex(), return g_setup->m_node.chainman->ActiveTip()->Time()));
48 
49  BlockAssembler::Options options;
50  options.coinbase_output_script = P2WSH_OP_TRUE;
51  options.include_dummy_extranonce = true;
52 
53  for (int i = 0; i < 2 * COINBASE_MATURITY; ++i) {
54  COutPoint prevout{MineBlock(g_setup->m_node, options)};
55  // Remember the txids to avoid expensive disk access later on
56  auto& outpoints = i < COINBASE_MATURITY ?
57  g_outpoints_coinbase_init_mature :
58  g_outpoints_coinbase_init_immature;
59  outpoints.push_back(prevout);
60  }
61  g_setup->m_node.validation_signals->SyncWithValidationInterfaceQueue();
62 }
63 
64 struct TransactionsDelta final : public CValidationInterface {
65  std::set<CTransactionRef>& m_removed;
66  std::set<CTransactionRef>& m_added;
67 
68  explicit TransactionsDelta(std::set<CTransactionRef>& r, std::set<CTransactionRef>& a)
69  : m_removed{r}, m_added{a} {}
70 
71  void TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t /* mempool_sequence */) override
72  {
73  Assert(m_added.insert(tx.info.m_tx).second);
74  }
75 
76  void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t /* mempool_sequence */) override
77  {
78  Assert(m_removed.insert(tx).second);
79  }
80 };
81 
82 void SetMempoolConstraints(ArgsManager& args, FuzzedDataProvider& fuzzed_data_provider)
83 {
84  args.ForceSetArg("-limitclustercount",
86  args.ForceSetArg("-limitclustersize",
88  args.ForceSetArg("-maxmempool",
90  args.ForceSetArg("-mempoolexpiry",
92 }
93 
94 void Finish(FuzzedDataProvider& fuzzed_data_provider, MockedTxPool& tx_pool, Chainstate& chainstate)
95 {
96  WITH_LOCK(::cs_main, tx_pool.check(chainstate.CoinsTip(), chainstate.m_chain.Height() + 1));
97  {
98  BlockAssembler::Options options;
99  options.nBlockMaxWeight = fuzzed_data_provider.ConsumeIntegralInRange(0U, MAX_BLOCK_WEIGHT);
100  options.blockMinFeeRate = CFeeRate{ConsumeMoney(fuzzed_data_provider, /*max=*/COIN)};
101  options.include_dummy_extranonce = true;
102  auto assembler = BlockAssembler{chainstate, &tx_pool, options};
103  auto block_template = assembler.CreateNewBlock();
104  Assert(block_template->block.vtx.size() >= 1);
105 
106  // Try updating the mempool for this block, as though it were mined.
107  LOCK2(::cs_main, tx_pool.cs);
108  tx_pool.removeForBlock(block_template->block.vtx, chainstate.m_chain.Height() + 1);
109 
110  // Now try to add those transactions back, as though a reorg happened.
111  std::vector<Txid> hashes_to_update;
112  for (const auto& tx : block_template->block.vtx) {
113  const auto res = AcceptToMemoryPool(chainstate, tx, GetTime(), true, /*test_accept=*/false);
114  if (res.m_result_type == MempoolAcceptResult::ResultType::VALID) {
115  hashes_to_update.push_back(tx->GetHash());
116  } else {
117  tx_pool.removeRecursive(*tx, MemPoolRemovalReason::REORG);
118  }
119  }
120  tx_pool.UpdateTransactionsFromBlock(hashes_to_update);
121  }
122  const auto info_all = tx_pool.infoAll();
123  if (!info_all.empty()) {
124  const auto& tx_to_remove = *PickValue(fuzzed_data_provider, info_all).tx;
125  WITH_LOCK(tx_pool.cs, tx_pool.removeRecursive(tx_to_remove, MemPoolRemovalReason::BLOCK /* dummy */));
126  assert(tx_pool.size() < info_all.size());
127  }
128 
130  // Try eviction
131  LOCK2(::cs_main, tx_pool.cs);
132  tx_pool.TrimToSize(fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0U, tx_pool.DynamicMemoryUsage() * 2));
133  }
135  // Try expiry
136  LOCK2(::cs_main, tx_pool.cs);
137  tx_pool.Expire(GetMockTime() - std::chrono::seconds(fuzzed_data_provider.ConsumeIntegral<uint32_t>()));
138  }
139  WITH_LOCK(::cs_main, tx_pool.check(chainstate.CoinsTip(), chainstate.m_chain.Height() + 1));
140  g_setup->m_node.validation_signals->SyncWithValidationInterfaceQueue();
141 }
142 
143 void MockTime(FuzzedDataProvider& fuzzed_data_provider, const Chainstate& chainstate)
144 {
145  const auto time = ConsumeTime(fuzzed_data_provider,
146  chainstate.m_chain.Tip()->GetMedianTimePast() + 1,
147  std::numeric_limits<decltype(chainstate.m_chain.Tip()->nTime)>::max());
148  SetMockTime(time);
149 }
150 
151 std::unique_ptr<CTxMemPool> MakeMempool(FuzzedDataProvider& fuzzed_data_provider, const NodeContext& node)
152 {
153  // Take the default options for tests...
155 
156  // ...override specific options for this specific fuzz suite
157  mempool_opts.check_ratio = 1;
158  mempool_opts.require_standard = fuzzed_data_provider.ConsumeBool();
159 
160  // ...and construct a CTxMemPool from it
161  bilingual_str error;
162  auto mempool{std::make_unique<CTxMemPool>(std::move(mempool_opts), error)};
163  // ... ignore the error since it might be beneficial to fuzz even when the
164  // mempool size is unreasonably small
165  Assert(error.empty() || error.original.starts_with("-maxmempool must be at least "));
166  return mempool;
167 }
168 
169 void CheckATMPInvariants(const MempoolAcceptResult& res, bool txid_in_mempool, bool wtxid_in_mempool)
170 {
171 
172  switch (res.m_result_type) {
174  {
175  Assert(txid_in_mempool);
176  Assert(wtxid_in_mempool);
177  Assert(res.m_state.IsValid());
178  Assert(!res.m_state.IsInvalid());
179  Assert(res.m_vsize);
180  Assert(res.m_base_fees);
183  Assert(!res.m_other_wtxid);
184  break;
185  }
187  {
188  // It may be already in the mempool since in ATMP cases we don't set MEMPOOL_ENTRY or DIFFERENT_WITNESS
189  Assert(!res.m_state.IsValid());
190  Assert(res.m_state.IsInvalid());
191 
192  const bool is_reconsiderable{res.m_state.GetResult() == TxValidationResult::TX_RECONSIDERABLE};
193  Assert(!res.m_vsize);
194  Assert(!res.m_base_fees);
195  // Fee information is provided if the failure is TX_RECONSIDERABLE.
196  // In other cases, validation may be unable or unwilling to calculate the fees.
197  Assert(res.m_effective_feerate.has_value() == is_reconsiderable);
198  Assert(res.m_wtxids_fee_calculations.has_value() == is_reconsiderable);
199  Assert(!res.m_other_wtxid);
200  break;
201  }
203  {
204  // ATMP never sets this; only set in package settings
205  Assert(false);
206  break;
207  }
209  {
210  // ATMP never sets this; only set in package settings
211  Assert(false);
212  break;
213  }
214  }
215 }
216 
217 FUZZ_TARGET(tx_pool_standard, .init = initialize_tx_pool)
218 {
220  FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
221  const auto& node = g_setup->m_node;
222  auto& chainstate{static_cast<DummyChainState&>(node.chainman->ActiveChainstate())};
223 
224  MockTime(fuzzed_data_provider, chainstate);
225 
226  // All RBF-spendable outpoints
227  std::set<COutPoint> outpoints_rbf;
228  // All outpoints counting toward the total supply (subset of outpoints_rbf)
229  std::set<COutPoint> outpoints_supply;
230  for (const auto& outpoint : g_outpoints_coinbase_init_mature) {
231  Assert(outpoints_supply.insert(outpoint).second);
232  }
233  outpoints_rbf = outpoints_supply;
234 
235  // The sum of the values of all spendable outpoints
236  constexpr CAmount SUPPLY_TOTAL{COINBASE_MATURITY * 50 * COIN};
237 
238  SetMempoolConstraints(*node.args, fuzzed_data_provider);
239  auto tx_pool_{MakeMempool(fuzzed_data_provider, node)};
240  MockedTxPool& tx_pool = *static_cast<MockedTxPool*>(tx_pool_.get());
241 
242  chainstate.SetMempool(&tx_pool);
243 
244  // Helper to query an amount
245  const CCoinsViewMemPool amount_view{WITH_LOCK(::cs_main, return &chainstate.CoinsTip()), tx_pool};
246  const auto GetAmount = [&](const COutPoint& outpoint) {
247  auto coin{amount_view.GetCoin(outpoint).value()};
248  return coin.out.nValue;
249  };
250 
252  {
253  {
254  // Total supply is the mempool fee + all outpoints
255  CAmount supply_now{WITH_LOCK(tx_pool.cs, return tx_pool.GetTotalFee())};
256  for (const auto& op : outpoints_supply) {
257  supply_now += GetAmount(op);
258  }
259  Assert(supply_now == SUPPLY_TOTAL);
260  }
261  Assert(!outpoints_supply.empty());
262 
263  // Create transaction to add to the mempool
264  const CTransactionRef tx = [&] {
265  CMutableTransaction tx_mut;
268  const auto num_in = fuzzed_data_provider.ConsumeIntegralInRange<int>(1, outpoints_rbf.size());
269  const auto num_out = fuzzed_data_provider.ConsumeIntegralInRange<int>(1, outpoints_rbf.size() * 2);
270 
271  CAmount amount_in{0};
272  for (int i = 0; i < num_in; ++i) {
273  // Pop random outpoint
274  auto pop = outpoints_rbf.begin();
275  std::advance(pop, fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, outpoints_rbf.size() - 1));
276  const auto outpoint = *pop;
277  outpoints_rbf.erase(pop);
278  amount_in += GetAmount(outpoint);
279 
280  // Create input
282  const auto script_sig = CScript{};
283  const auto script_wit_stack = std::vector<std::vector<uint8_t>>{WITNESS_STACK_ELEM_OP_TRUE};
284  CTxIn in;
285  in.prevout = outpoint;
286  in.nSequence = sequence;
287  in.scriptSig = script_sig;
288  in.scriptWitness.stack = script_wit_stack;
289 
290  tx_mut.vin.push_back(in);
291  }
292 
293  // Check sigops in mempool + block template creation
294  bool add_sigops{fuzzed_data_provider.ConsumeBool()};
295 
296  const auto amount_fee = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-1000, amount_in);
297  const auto amount_out = (amount_in - amount_fee) / num_out;
298  for (int i = 0; i < num_out; ++i) {
299  if (i == 0 && add_sigops) {
300  tx_mut.vout.emplace_back(amount_out, CScript() << std::vector<unsigned char>(33, 0x02) << OP_CHECKSIG);
301  } else {
302  tx_mut.vout.emplace_back(amount_out, P2WSH_OP_TRUE);
303  }
304  }
305 
306  auto tx = MakeTransactionRef(tx_mut);
307  // Restore previously removed outpoints
308  for (const auto& in : tx->vin) {
309  Assert(outpoints_rbf.insert(in.prevout).second);
310  }
311  return tx;
312  }();
313 
315  MockTime(fuzzed_data_provider, chainstate);
316  }
318  tx_pool.RollingFeeUpdate();
319  }
321  const auto& txid = fuzzed_data_provider.ConsumeBool() ?
322  tx->GetHash() :
323  PickValue(fuzzed_data_provider, outpoints_rbf).hash;
324  const auto delta = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-50 * COIN, +50 * COIN);
325  tx_pool.PrioritiseTransaction(txid, delta);
326  }
327 
328  // Remember all removed and added transactions
329  std::set<CTransactionRef> removed;
330  std::set<CTransactionRef> added;
331  auto txr = std::make_shared<TransactionsDelta>(removed, added);
332  node.validation_signals->RegisterSharedValidationInterface(txr);
333 
334  // Make sure ProcessNewPackage on one transaction works.
335  // The result is not guaranteed to be the same as what is returned by ATMP.
336  const auto result_package = WITH_LOCK(::cs_main,
337  return ProcessNewPackage(chainstate, tx_pool, {tx}, true, /*client_maxfeerate=*/{}));
338  // If something went wrong due to a package-specific policy, it might not return a
339  // validation result for the transaction.
340  if (result_package.m_state.GetResult() != PackageValidationResult::PCKG_POLICY) {
341  auto it = result_package.m_tx_results.find(tx->GetWitnessHash());
342  Assert(it != result_package.m_tx_results.end());
343  Assert(it->second.m_result_type == MempoolAcceptResult::ResultType::VALID ||
344  it->second.m_result_type == MempoolAcceptResult::ResultType::INVALID);
345  }
346 
347  const auto res = WITH_LOCK(::cs_main, return AcceptToMemoryPool(chainstate, tx, GetTime(), /*bypass_limits=*/false, /*test_accept=*/false));
348  const bool accepted = res.m_result_type == MempoolAcceptResult::ResultType::VALID;
349  node.validation_signals->SyncWithValidationInterfaceQueue();
350  node.validation_signals->UnregisterSharedValidationInterface(txr);
351 
352  bool txid_in_mempool = tx_pool.exists(tx->GetHash());
353  bool wtxid_in_mempool = tx_pool.exists(tx->GetWitnessHash());
354  CheckATMPInvariants(res, txid_in_mempool, wtxid_in_mempool);
355 
356  Assert(accepted != added.empty());
357  if (accepted) {
358  Assert(added.size() == 1); // For now, no package acceptance
359  Assert(tx == *added.begin());
361  } else {
362  // Do not consider rejected transaction removed
363  removed.erase(tx);
364  }
365 
366  // Helper to insert spent and created outpoints of a tx into collections
367  using Sets = std::vector<std::reference_wrapper<std::set<COutPoint>>>;
368  const auto insert_tx = [](Sets created_by_tx, Sets consumed_by_tx, const auto& tx) {
369  for (size_t i{0}; i < tx.vout.size(); ++i) {
370  for (auto& set : created_by_tx) {
371  Assert(set.get().emplace(tx.GetHash(), i).second);
372  }
373  }
374  for (const auto& in : tx.vin) {
375  for (auto& set : consumed_by_tx) {
376  Assert(set.get().insert(in.prevout).second);
377  }
378  }
379  };
380  // Add created outpoints, remove spent outpoints
381  {
382  // Outpoints that no longer exist at all
383  std::set<COutPoint> consumed_erased;
384  // Outpoints that no longer count toward the total supply
385  std::set<COutPoint> consumed_supply;
386  for (const auto& removed_tx : removed) {
387  insert_tx(/*created_by_tx=*/{consumed_erased}, /*consumed_by_tx=*/{outpoints_supply}, /*tx=*/*removed_tx);
388  }
389  for (const auto& added_tx : added) {
390  insert_tx(/*created_by_tx=*/{outpoints_supply, outpoints_rbf}, /*consumed_by_tx=*/{consumed_supply}, /*tx=*/*added_tx);
391  }
392  for (const auto& p : consumed_erased) {
393  Assert(outpoints_supply.erase(p) == 1);
394  Assert(outpoints_rbf.erase(p) == 1);
395  }
396  for (const auto& p : consumed_supply) {
397  Assert(outpoints_supply.erase(p) == 1);
398  }
399  }
400  }
401  Finish(fuzzed_data_provider, tx_pool, chainstate);
402 }
403 
404 FUZZ_TARGET(tx_pool, .init = initialize_tx_pool)
405 {
407  FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
408  const auto& node = g_setup->m_node;
409  auto& chainstate{static_cast<DummyChainState&>(node.chainman->ActiveChainstate())};
410 
411  MockTime(fuzzed_data_provider, chainstate);
412 
413  std::vector<Txid> txids;
414  txids.reserve(g_outpoints_coinbase_init_mature.size());
415  for (const auto& outpoint : g_outpoints_coinbase_init_mature) {
416  txids.push_back(outpoint.hash);
417  }
418  for (int i{0}; i <= 3; ++i) {
419  // Add some immature and non-existent outpoints
420  txids.push_back(g_outpoints_coinbase_init_immature.at(i).hash);
422  }
423 
424  SetMempoolConstraints(*node.args, fuzzed_data_provider);
425  auto tx_pool_{MakeMempool(fuzzed_data_provider, node)};
426  MockedTxPool& tx_pool = *static_cast<MockedTxPool*>(tx_pool_.get());
427 
428  chainstate.SetMempool(&tx_pool);
429 
430  // If we ever bypass limits, do not do TRUC invariants checks
431  bool ever_bypassed_limits{false};
432 
434  {
435  const auto mut_tx = ConsumeTransaction(fuzzed_data_provider, txids);
436 
438  MockTime(fuzzed_data_provider, chainstate);
439  }
441  tx_pool.RollingFeeUpdate();
442  }
444  const auto txid = fuzzed_data_provider.ConsumeBool() ?
445  mut_tx.GetHash() :
447  const auto delta = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-50 * COIN, +50 * COIN);
448  tx_pool.PrioritiseTransaction(txid, delta);
449  }
450 
451  const bool bypass_limits{fuzzed_data_provider.ConsumeBool()};
452  ever_bypassed_limits |= bypass_limits;
453 
454  const auto tx = MakeTransactionRef(mut_tx);
455  const auto res = WITH_LOCK(::cs_main, return AcceptToMemoryPool(chainstate, tx, GetTime(), bypass_limits, /*test_accept=*/false));
456  const bool accepted = res.m_result_type == MempoolAcceptResult::ResultType::VALID;
457  if (accepted) {
458  txids.push_back(tx->GetHash());
459  if (!ever_bypassed_limits) {
461  }
462  }
463  }
464  Finish(fuzzed_data_provider, tx_pool, chainstate);
465 }
466 } // namespace
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:403
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:686
const std::optional< CFeeRate > m_effective_feerate
The feerate at which this transaction was considered.
Definition: validation.h:156
assert(!tx.IsCoinBase())
Generate a new block, without valid proof-of-work.
Definition: miner.h:60
const std::optional< std::vector< Wtxid > > m_wtxids_fee_calculations
Contains the wtxids of the transactions used for fee-related checks.
Definition: validation.h:162
The package itself is invalid (e.g. too many transactions).
Valid, transaction was already in the mempool.
Bilingual messages:
Definition: translation.h:24
bool empty() const
Definition: translation.h:35
std::vector< CTxIn > vin
Definition: transaction.h:359
static const CScript P2WSH_OP_TRUE
Definition: script.h:13
CScriptWitness scriptWitness
Only serialized through CTransaction.
Definition: transaction.h:67
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal...
int64_t GetTime()
DEPRECATED, see GetTime.
Definition: time.cpp:81
int Height() const
Return the maximal height in the chain.
Definition: chain.h:425
std::unique_ptr< ValidationSignals > validation_signals
Issues calls about blocks and transactions.
Definition: context.h:88
static const int COINBASE_MATURITY
Coinbase transaction outputs can only be spent after this number of new blocks (network rule) ...
Definition: consensus.h:19
std::vector< std::vector< unsigned char > > stack
Definition: script.h:580
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
Definition: fuzz.h:22
const std::optional< int64_t > m_vsize
Virtual size as used by the mempool, calculated using serialized size and sigops. ...
Definition: validation.h:148
const TxValidationState m_state
Contains information about why the transaction failed.
Definition: validation.h:143
void insert(Tdst &dst, const Tsrc &src)
Simplification of std insertion.
Definition: insert.h:14
const std::optional< CAmount > m_base_fees
Raw base fees in satoshis.
Definition: validation.h:150
const TestingSetup * g_setup
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.
uint32_t nTime
Definition: chain.h:142
const ResultType m_result_type
Result type.
Definition: validation.h:140
void ForceSetArg(const std::string &strArg, const std::string &strValue)
Definition: args.cpp:571
CChain m_chain
The current chain of blockheaders we consult and build on.
Definition: validation.h:625
Implement this to subscribe to events generated in validation and mempool.
static const unsigned int MAX_BLOCK_WEIGHT
The maximum allowed weight for a block, see BIP 141 (network rule)
Definition: consensus.h:15
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
bool IsValid() const
Definition: validation.h:105
static const uint32_t CURRENT_VERSION
Definition: transaction.h:284
NodeContext struct containing references to chain state and connection state.
Definition: context.h:56
#define LOCK2(cs1, cs2)
Definition: sync.h:259
ArgsManager & args
Definition: bitcoind.cpp:277
static decltype(CTransaction::version) constexpr TRUC_VERSION
Definition: truc_policy.h:20
Chainstate stores and provides an API to update our local knowledge of the current best chain...
Definition: validation.h:550
An input of a transaction.
Definition: transaction.h:61
COutPoint MineBlock(const NodeContext &node, const node::BlockAssembler::Options &assembler_options)
Returns the generated coin.
Definition: mining.cpp:72
Removed for reorganization.
#define LOCK(cs)
Definition: sync.h:258
static const std::vector< uint8_t > WITNESS_STACK_ELEM_OP_TRUE
Definition: script.h:12
Result GetResult() const
Definition: validation.h:108
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:28
std::vector< CTxOut > vout
Definition: transaction.h:360
fails some policy, but might be acceptable if submitted in a (different) package
Validation result for a transaction evaluated by MemPoolAccept (single or package).
Definition: validation.h:131
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:289
int64_t GetMedianTimePast() const
Definition: chain.h:233
NodeSeconds ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
Definition: util.cpp:34
static CTransactionRef MakeTransactionRef(Tx &&txIn)
Definition: transaction.h:404
Definition: messages.h:21
CScript scriptSig
Definition: transaction.h:65
void SeedRandomStateForTest(SeedRand seedtype)
Seed the global RNG state for testing and log the seed value.
Definition: random.cpp:19
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:51
void CheckMempoolTRUCInvariants(const CTxMemPool &tx_pool)
For every transaction in tx_pool, check TRUC invariants:
Definition: txmempool.cpp:182
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:186
CMutableTransaction ConsumeTransaction(FuzzedDataProvider &fuzzed_data_provider, const std::optional< std::vector< Txid >> &prevout_txids, const int max_num_in, const int max_num_out) noexcept
Definition: util.cpp:47
std::string original
Definition: translation.h:25
Removed for block.
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:404
static transaction_identifier FromUint256(const uint256 &id)
uint32_t nSequence
Definition: transaction.h:66
FuzzedDataProvider & fuzzed_data_provider
Definition: fees.cpp:38
CAmount ConsumeMoney(FuzzedDataProvider &fuzzed_data_provider, const std::optional< CAmount > &max) noexcept
Definition: util.cpp:29
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.
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
Definition: chain.h:396
const CTransactionRef m_tx
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac...
Definition: feerate.h:31
bool IsInvalid() const
Definition: validation.h:106
static void pool cs
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
Definition: time.cpp:44
A mutable version of CTransaction.
Definition: transaction.h:357
Options struct containing options for constructing a CTxMemPool.
auto & PickValue(FuzzedDataProvider &fuzzed_data_provider, Collection &col)
Definition: util.h:47
T ConsumeIntegralInRange(T min, T max)
uint64_t sequence
#define FUZZ_TARGET(...)
Definition: fuzz.h:35
std::chrono::seconds GetMockTime()
For testing.
Definition: time.cpp:52
Seed with a compile time constant of zeros.
uint256 ConsumeUInt256(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.h:167
COutPoint prevout
Definition: transaction.h:64
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
Definition: cs_main.cpp:8
node::NodeContext m_node
Definition: setup_common.h:66
CCoinsView that brings transactions from a mempool into view.
Definition: txmempool.h:752
std::unique_ptr< ChainstateManager > chainman
Definition: context.h:72
Testing setup that configures a complete environment.
Definition: setup_common.h:121
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Definition: string.h:246
const std::optional< Wtxid > m_other_wtxid
The wtxid of the transaction in the mempool which has the same txid but different witness...
Definition: validation.h:165
#define Assert(val)
Identity function.
Definition: check.h:113
uint32_t ConsumeSequence(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.cpp:160
CTxMemPool::Options MemPoolOptionsForTest(const NodeContext &node)
Definition: txmempool.cpp:21
static constexpr CAmount COIN
The amount of satoshis in one BTC.
Definition: amount.h:15