Bitcoin Core  27.99.0
P2P Digital Currency
tx_pool.cpp
Go to the documentation of this file.
1 // Copyright (c) 2021-2022 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/v3_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/rbf.h>
19 #include <validation.h>
20 #include <validationinterface.h>
21 
23 using node::NodeContext;
24 
25 namespace {
26 
27 const TestingSetup* g_setup;
28 std::vector<COutPoint> g_outpoints_coinbase_init_mature;
29 std::vector<COutPoint> g_outpoints_coinbase_init_immature;
30 
31 struct MockedTxPool : public CTxMemPool {
32  void RollingFeeUpdate() EXCLUSIVE_LOCKS_REQUIRED(!cs)
33  {
34  LOCK(cs);
35  lastRollingFeeUpdate = GetTime();
36  blockSinceLastRollingFeeBump = true;
37  }
38 };
39 
40 void initialize_tx_pool()
41 {
42  static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
43  g_setup = testing_setup.get();
44 
45  for (int i = 0; i < 2 * COINBASE_MATURITY; ++i) {
46  COutPoint prevout{MineBlock(g_setup->m_node, P2WSH_OP_TRUE)};
47  // Remember the txids to avoid expensive disk access later on
48  auto& outpoints = i < COINBASE_MATURITY ?
49  g_outpoints_coinbase_init_mature :
50  g_outpoints_coinbase_init_immature;
51  outpoints.push_back(prevout);
52  }
53  g_setup->m_node.validation_signals->SyncWithValidationInterfaceQueue();
54 }
55 
56 struct TransactionsDelta final : public CValidationInterface {
57  std::set<CTransactionRef>& m_removed;
58  std::set<CTransactionRef>& m_added;
59 
60  explicit TransactionsDelta(std::set<CTransactionRef>& r, std::set<CTransactionRef>& a)
61  : m_removed{r}, m_added{a} {}
62 
63  void TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t /* mempool_sequence */) override
64  {
65  Assert(m_added.insert(tx.info.m_tx).second);
66  }
67 
68  void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t /* mempool_sequence */) override
69  {
70  Assert(m_removed.insert(tx).second);
71  }
72 };
73 
74 void SetMempoolConstraints(ArgsManager& args, FuzzedDataProvider& fuzzed_data_provider)
75 {
76  args.ForceSetArg("-limitancestorcount",
77  ToString(fuzzed_data_provider.ConsumeIntegralInRange<unsigned>(0, 50)));
78  args.ForceSetArg("-limitancestorsize",
79  ToString(fuzzed_data_provider.ConsumeIntegralInRange<unsigned>(0, 202)));
80  args.ForceSetArg("-limitdescendantcount",
81  ToString(fuzzed_data_provider.ConsumeIntegralInRange<unsigned>(0, 50)));
82  args.ForceSetArg("-limitdescendantsize",
83  ToString(fuzzed_data_provider.ConsumeIntegralInRange<unsigned>(0, 202)));
84  args.ForceSetArg("-maxmempool",
85  ToString(fuzzed_data_provider.ConsumeIntegralInRange<unsigned>(0, 200)));
86  args.ForceSetArg("-mempoolexpiry",
87  ToString(fuzzed_data_provider.ConsumeIntegralInRange<unsigned>(0, 999)));
88 }
89 
90 void Finish(FuzzedDataProvider& fuzzed_data_provider, MockedTxPool& tx_pool, Chainstate& chainstate)
91 {
92  WITH_LOCK(::cs_main, tx_pool.check(chainstate.CoinsTip(), chainstate.m_chain.Height() + 1));
93  {
94  BlockAssembler::Options options;
95  options.nBlockMaxWeight = fuzzed_data_provider.ConsumeIntegralInRange(0U, MAX_BLOCK_WEIGHT);
96  options.blockMinFeeRate = CFeeRate{ConsumeMoney(fuzzed_data_provider, /*max=*/COIN)};
97  auto assembler = BlockAssembler{chainstate, &tx_pool, options};
98  auto block_template = assembler.CreateNewBlock(CScript{} << OP_TRUE);
99  Assert(block_template->block.vtx.size() >= 1);
100  }
101  const auto info_all = tx_pool.infoAll();
102  if (!info_all.empty()) {
103  const auto& tx_to_remove = *PickValue(fuzzed_data_provider, info_all).tx;
104  WITH_LOCK(tx_pool.cs, tx_pool.removeRecursive(tx_to_remove, MemPoolRemovalReason::BLOCK /* dummy */));
105  assert(tx_pool.size() < info_all.size());
106  WITH_LOCK(::cs_main, tx_pool.check(chainstate.CoinsTip(), chainstate.m_chain.Height() + 1));
107  }
108  g_setup->m_node.validation_signals->SyncWithValidationInterfaceQueue();
109 }
110 
111 void MockTime(FuzzedDataProvider& fuzzed_data_provider, const Chainstate& chainstate)
112 {
113  const auto time = ConsumeTime(fuzzed_data_provider,
114  chainstate.m_chain.Tip()->GetMedianTimePast() + 1,
115  std::numeric_limits<decltype(chainstate.m_chain.Tip()->nTime)>::max());
116  SetMockTime(time);
117 }
118 
119 CTxMemPool MakeMempool(FuzzedDataProvider& fuzzed_data_provider, const NodeContext& node)
120 {
121  // Take the default options for tests...
123 
124  // ...override specific options for this specific fuzz suite
125  mempool_opts.check_ratio = 1;
126  mempool_opts.require_standard = fuzzed_data_provider.ConsumeBool();
127 
128  // ...and construct a CTxMemPool from it
129  return CTxMemPool{mempool_opts};
130 }
131 
132 void CheckATMPInvariants(const MempoolAcceptResult& res, bool txid_in_mempool, bool wtxid_in_mempool)
133 {
134 
135  switch (res.m_result_type) {
137  {
138  Assert(txid_in_mempool);
139  Assert(wtxid_in_mempool);
140  Assert(res.m_state.IsValid());
141  Assert(!res.m_state.IsInvalid());
143  Assert(res.m_vsize);
144  Assert(res.m_base_fees);
147  Assert(!res.m_other_wtxid);
148  break;
149  }
151  {
152  // It may be already in the mempool since in ATMP cases we don't set MEMPOOL_ENTRY or DIFFERENT_WITNESS
153  Assert(!res.m_state.IsValid());
154  Assert(res.m_state.IsInvalid());
155 
156  const bool is_reconsiderable{res.m_state.GetResult() == TxValidationResult::TX_RECONSIDERABLE};
158  Assert(!res.m_vsize);
159  Assert(!res.m_base_fees);
160  // Fee information is provided if the failure is TX_RECONSIDERABLE.
161  // In other cases, validation may be unable or unwilling to calculate the fees.
162  Assert(res.m_effective_feerate.has_value() == is_reconsiderable);
163  Assert(res.m_wtxids_fee_calculations.has_value() == is_reconsiderable);
164  Assert(!res.m_other_wtxid);
165  break;
166  }
168  {
169  // ATMP never sets this; only set in package settings
170  Assert(false);
171  break;
172  }
174  {
175  // ATMP never sets this; only set in package settings
176  Assert(false);
177  break;
178  }
179  }
180 }
181 
182 FUZZ_TARGET(tx_pool_standard, .init = initialize_tx_pool)
183 {
184  FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
185  const auto& node = g_setup->m_node;
186  auto& chainstate{static_cast<DummyChainState&>(node.chainman->ActiveChainstate())};
187 
188  MockTime(fuzzed_data_provider, chainstate);
189 
190  // All RBF-spendable outpoints
191  std::set<COutPoint> outpoints_rbf;
192  // All outpoints counting toward the total supply (subset of outpoints_rbf)
193  std::set<COutPoint> outpoints_supply;
194  for (const auto& outpoint : g_outpoints_coinbase_init_mature) {
195  Assert(outpoints_supply.insert(outpoint).second);
196  }
197  outpoints_rbf = outpoints_supply;
198 
199  // The sum of the values of all spendable outpoints
200  constexpr CAmount SUPPLY_TOTAL{COINBASE_MATURITY * 50 * COIN};
201 
202  SetMempoolConstraints(*node.args, fuzzed_data_provider);
203  CTxMemPool tx_pool_{MakeMempool(fuzzed_data_provider, node)};
204  MockedTxPool& tx_pool = *static_cast<MockedTxPool*>(&tx_pool_);
205 
206  chainstate.SetMempool(&tx_pool);
207 
208  // Helper to query an amount
209  const CCoinsViewMemPool amount_view{WITH_LOCK(::cs_main, return &chainstate.CoinsTip()), tx_pool};
210  const auto GetAmount = [&](const COutPoint& outpoint) {
211  Coin c;
212  Assert(amount_view.GetCoin(outpoint, c));
213  return c.out.nValue;
214  };
215 
216  LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 300)
217  {
218  {
219  // Total supply is the mempool fee + all outpoints
220  CAmount supply_now{WITH_LOCK(tx_pool.cs, return tx_pool.GetTotalFee())};
221  for (const auto& op : outpoints_supply) {
222  supply_now += GetAmount(op);
223  }
224  Assert(supply_now == SUPPLY_TOTAL);
225  }
226  Assert(!outpoints_supply.empty());
227 
228  // Create transaction to add to the mempool
229  const CTransactionRef tx = [&] {
230  CMutableTransaction tx_mut;
231  tx_mut.nVersion = fuzzed_data_provider.ConsumeBool() ? 3 : CTransaction::CURRENT_VERSION;
232  tx_mut.nLockTime = fuzzed_data_provider.ConsumeBool() ? 0 : fuzzed_data_provider.ConsumeIntegral<uint32_t>();
233  const auto num_in = fuzzed_data_provider.ConsumeIntegralInRange<int>(1, outpoints_rbf.size());
234  const auto num_out = fuzzed_data_provider.ConsumeIntegralInRange<int>(1, outpoints_rbf.size() * 2);
235 
236  CAmount amount_in{0};
237  for (int i = 0; i < num_in; ++i) {
238  // Pop random outpoint
239  auto pop = outpoints_rbf.begin();
240  std::advance(pop, fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, outpoints_rbf.size() - 1));
241  const auto outpoint = *pop;
242  outpoints_rbf.erase(pop);
243  amount_in += GetAmount(outpoint);
244 
245  // Create input
246  const auto sequence = ConsumeSequence(fuzzed_data_provider);
247  const auto script_sig = CScript{};
248  const auto script_wit_stack = std::vector<std::vector<uint8_t>>{WITNESS_STACK_ELEM_OP_TRUE};
249  CTxIn in;
250  in.prevout = outpoint;
251  in.nSequence = sequence;
252  in.scriptSig = script_sig;
253  in.scriptWitness.stack = script_wit_stack;
254 
255  tx_mut.vin.push_back(in);
256  }
257  const auto amount_fee = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-1000, amount_in);
258  const auto amount_out = (amount_in - amount_fee) / num_out;
259  for (int i = 0; i < num_out; ++i) {
260  tx_mut.vout.emplace_back(amount_out, P2WSH_OP_TRUE);
261  }
262  auto tx = MakeTransactionRef(tx_mut);
263  // Restore previously removed outpoints
264  for (const auto& in : tx->vin) {
265  Assert(outpoints_rbf.insert(in.prevout).second);
266  }
267  return tx;
268  }();
269 
270  if (fuzzed_data_provider.ConsumeBool()) {
271  MockTime(fuzzed_data_provider, chainstate);
272  }
273  if (fuzzed_data_provider.ConsumeBool()) {
274  tx_pool.RollingFeeUpdate();
275  }
276  if (fuzzed_data_provider.ConsumeBool()) {
277  const auto& txid = fuzzed_data_provider.ConsumeBool() ?
278  tx->GetHash() :
279  PickValue(fuzzed_data_provider, outpoints_rbf).hash;
280  const auto delta = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-50 * COIN, +50 * COIN);
281  tx_pool.PrioritiseTransaction(txid.ToUint256(), delta);
282  }
283 
284  // Remember all removed and added transactions
285  std::set<CTransactionRef> removed;
286  std::set<CTransactionRef> added;
287  auto txr = std::make_shared<TransactionsDelta>(removed, added);
288  node.validation_signals->RegisterSharedValidationInterface(txr);
289  const bool bypass_limits = fuzzed_data_provider.ConsumeBool();
290 
291  // Make sure ProcessNewPackage on one transaction works.
292  // The result is not guaranteed to be the same as what is returned by ATMP.
293  const auto result_package = WITH_LOCK(::cs_main,
294  return ProcessNewPackage(chainstate, tx_pool, {tx}, true, /*client_maxfeerate=*/{}));
295  // If something went wrong due to a package-specific policy, it might not return a
296  // validation result for the transaction.
297  if (result_package.m_state.GetResult() != PackageValidationResult::PCKG_POLICY) {
298  auto it = result_package.m_tx_results.find(tx->GetWitnessHash());
299  Assert(it != result_package.m_tx_results.end());
300  Assert(it->second.m_result_type == MempoolAcceptResult::ResultType::VALID ||
301  it->second.m_result_type == MempoolAcceptResult::ResultType::INVALID);
302  }
303 
304  const auto res = WITH_LOCK(::cs_main, return AcceptToMemoryPool(chainstate, tx, GetTime(), bypass_limits, /*test_accept=*/false));
305  const bool accepted = res.m_result_type == MempoolAcceptResult::ResultType::VALID;
306  node.validation_signals->SyncWithValidationInterfaceQueue();
307  node.validation_signals->UnregisterSharedValidationInterface(txr);
308 
309  bool txid_in_mempool = tx_pool.exists(GenTxid::Txid(tx->GetHash()));
310  bool wtxid_in_mempool = tx_pool.exists(GenTxid::Wtxid(tx->GetWitnessHash()));
311  CheckATMPInvariants(res, txid_in_mempool, wtxid_in_mempool);
312 
313  Assert(accepted != added.empty());
314  if (accepted) {
315  Assert(added.size() == 1); // For now, no package acceptance
316  Assert(tx == *added.begin());
317  CheckMempoolV3Invariants(tx_pool);
318  } else {
319  // Do not consider rejected transaction removed
320  removed.erase(tx);
321  }
322 
323  // Helper to insert spent and created outpoints of a tx into collections
324  using Sets = std::vector<std::reference_wrapper<std::set<COutPoint>>>;
325  const auto insert_tx = [](Sets created_by_tx, Sets consumed_by_tx, const auto& tx) {
326  for (size_t i{0}; i < tx.vout.size(); ++i) {
327  for (auto& set : created_by_tx) {
328  Assert(set.get().emplace(tx.GetHash(), i).second);
329  }
330  }
331  for (const auto& in : tx.vin) {
332  for (auto& set : consumed_by_tx) {
333  Assert(set.get().insert(in.prevout).second);
334  }
335  }
336  };
337  // Add created outpoints, remove spent outpoints
338  {
339  // Outpoints that no longer exist at all
340  std::set<COutPoint> consumed_erased;
341  // Outpoints that no longer count toward the total supply
342  std::set<COutPoint> consumed_supply;
343  for (const auto& removed_tx : removed) {
344  insert_tx(/*created_by_tx=*/{consumed_erased}, /*consumed_by_tx=*/{outpoints_supply}, /*tx=*/*removed_tx);
345  }
346  for (const auto& added_tx : added) {
347  insert_tx(/*created_by_tx=*/{outpoints_supply, outpoints_rbf}, /*consumed_by_tx=*/{consumed_supply}, /*tx=*/*added_tx);
348  }
349  for (const auto& p : consumed_erased) {
350  Assert(outpoints_supply.erase(p) == 1);
351  Assert(outpoints_rbf.erase(p) == 1);
352  }
353  for (const auto& p : consumed_supply) {
354  Assert(outpoints_supply.erase(p) == 1);
355  }
356  }
357  }
358  Finish(fuzzed_data_provider, tx_pool, chainstate);
359 }
360 
361 FUZZ_TARGET(tx_pool, .init = initialize_tx_pool)
362 {
363  FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
364  const auto& node = g_setup->m_node;
365  auto& chainstate{static_cast<DummyChainState&>(node.chainman->ActiveChainstate())};
366 
367  MockTime(fuzzed_data_provider, chainstate);
368 
369  std::vector<Txid> txids;
370  txids.reserve(g_outpoints_coinbase_init_mature.size());
371  for (const auto& outpoint : g_outpoints_coinbase_init_mature) {
372  txids.push_back(outpoint.hash);
373  }
374  for (int i{0}; i <= 3; ++i) {
375  // Add some immature and non-existent outpoints
376  txids.push_back(g_outpoints_coinbase_init_immature.at(i).hash);
377  txids.push_back(Txid::FromUint256(ConsumeUInt256(fuzzed_data_provider)));
378  }
379 
380  SetMempoolConstraints(*node.args, fuzzed_data_provider);
381  CTxMemPool tx_pool_{MakeMempool(fuzzed_data_provider, node)};
382  MockedTxPool& tx_pool = *static_cast<MockedTxPool*>(&tx_pool_);
383 
384  chainstate.SetMempool(&tx_pool);
385 
386  LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 300)
387  {
388  const auto mut_tx = ConsumeTransaction(fuzzed_data_provider, txids);
389 
390  if (fuzzed_data_provider.ConsumeBool()) {
391  MockTime(fuzzed_data_provider, chainstate);
392  }
393  if (fuzzed_data_provider.ConsumeBool()) {
394  tx_pool.RollingFeeUpdate();
395  }
396  if (fuzzed_data_provider.ConsumeBool()) {
397  const auto txid = fuzzed_data_provider.ConsumeBool() ?
398  mut_tx.GetHash() :
399  PickValue(fuzzed_data_provider, txids);
400  const auto delta = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-50 * COIN, +50 * COIN);
401  tx_pool.PrioritiseTransaction(txid.ToUint256(), delta);
402  }
403 
404  const auto tx = MakeTransactionRef(mut_tx);
405  const bool bypass_limits = fuzzed_data_provider.ConsumeBool();
406  const auto res = WITH_LOCK(::cs_main, return AcceptToMemoryPool(chainstate, tx, GetTime(), bypass_limits, /*test_accept=*/false));
407  const bool accepted = res.m_result_type == MempoolAcceptResult::ResultType::VALID;
408  if (accepted) {
409  txids.push_back(tx->GetHash());
410  CheckMempoolV3Invariants(tx_pool);
411  }
412  }
413  Finish(fuzzed_data_provider, tx_pool, chainstate);
414 }
415 } // 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
ArgsManager & args
Definition: bitcoind.cpp:268
#define Assert(val)
Identity function.
Definition: check.h:77
void ForceSetArg(const std::string &strArg, const std::string &strValue)
Definition: args.cpp:544
uint32_t nTime
Definition: chain.h:190
int64_t GetMedianTimePast() const
Definition: chain.h:279
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
Definition: chain.h:434
int Height() const
Return the maximal height in the chain.
Definition: chain.h:463
CCoinsView that brings transactions from a mempool into view.
Definition: txmempool.h:848
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
Definition: feerate.h:33
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:414
static const int32_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:302
CAmount nValue
Definition: transaction.h:152
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:491
CChain m_chain
The current chain of blockheaders we consult and build on.
Definition: validation.h:571
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:597
A UTXO entry.
Definition: coins.h:32
CTxOut out
unspent transaction output
Definition: coins.h:35
T ConsumeIntegralInRange(T min, T max)
static GenTxid Wtxid(const uint256 &hash)
Definition: transaction.h:435
static GenTxid Txid(const uint256 &hash)
Definition: transaction.h:434
bool IsValid() const
Definition: validation.h:122
Result GetResult() const
Definition: validation.h:125
bool IsInvalid() const
Definition: validation.h:123
Generate a new block, without valid proof-of-work.
Definition: miner.h:135
static transaction_identifier FromUint256(const uint256 &id)
@ TX_RECONSIDERABLE
fails some policy, but might be acceptable if submitted in a (different) package
static const unsigned int MAX_BLOCK_WEIGHT
The maximum allowed weight for a block, see BIP 141 (network rule)
Definition: consensus.h:15
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:36
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
Definition: fuzz.h:23
uint64_t sequence
static void pool cs
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal.
@ BLOCK
Removed for block.
Definition: init.h:25
@ PCKG_POLICY
The package itself is invalid (e.g. too many transactions).
static CTransactionRef MakeTransactionRef(Tx &&txIn)
Definition: transaction.h:424
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:423
@ OP_TRUE
Definition: script.h:83
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Definition: string.h:110
node::NodeContext m_node
Definition: setup_common.h:54
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:569
Validation result for a transaction evaluated by MemPoolAccept (single or package).
Definition: validation.h:127
const std::optional< int64_t > m_vsize
Virtual size as used by the mempool, calculated using serialized size and sigops.
Definition: validation.h:144
const ResultType m_result_type
Result type.
Definition: validation.h:136
const std::optional< CAmount > m_base_fees
Raw base fees in satoshis.
Definition: validation.h:146
const std::optional< std::list< CTransactionRef > > m_replaced_transactions
Mempool transactions replaced by the tx.
Definition: validation.h:142
const TxValidationState m_state
Contains information about why the transaction failed.
Definition: validation.h:139
@ DIFFERENT_WITNESS
Valid, transaction was already in the mempool.
@ INVALID
Fully validated, valid.
const std::optional< CFeeRate > m_effective_feerate
The feerate at which this transaction was considered.
Definition: validation.h:152
const std::optional< uint256 > m_other_wtxid
The wtxid of the transaction in the mempool which has the same txid but different witness.
Definition: validation.h:161
const std::optional< std::vector< Wtxid > > m_wtxids_fee_calculations
Contains the wtxids of the transactions used for fee-related checks.
Definition: validation.h:158
Testing setup that configures a complete environment.
Definition: setup_common.h:83
const CTransactionRef m_tx
Options struct containing options for constructing a CTxMemPool.
NodeContext struct containing references to chain state and connection state.
Definition: context.h:49
std::unique_ptr< ValidationSignals > validation_signals
Issues calls about blocks and transactions.
Definition: context.h:77
#define LOCK(cs)
Definition: sync.h:257
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:301
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
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:42
CAmount ConsumeMoney(FuzzedDataProvider &fuzzed_data_provider, const std::optional< CAmount > &max) noexcept
Definition: util.cpp:29
auto & PickValue(FuzzedDataProvider &fuzzed_data_provider, Collection &col)
Definition: util.h:47
uint256 ConsumeUInt256(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.h:169
COutPoint MineBlock(const NodeContext &node, const CScript &coinbase_scriptPubKey)
Returns the generated coin.
Definition: mining.cpp:63
static const std::vector< uint8_t > WITNESS_STACK_ELEM_OP_TRUE
Definition: script.h:11
static const CScript P2WSH_OP_TRUE
Definition: script.h:12
CTxMemPool::Options MemPoolOptionsForTest(const NodeContext &node)
Definition: txmempool.cpp:19
void CheckMempoolV3Invariants(const CTxMemPool &tx_pool)
For every transaction in tx_pool, check v3 invariants:
Definition: txmempool.cpp:122
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
int64_t GetTime()
Definition: time.cpp:48
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
Definition: time.cpp:32
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) EXCLUSIVE_LOCKS_REQUIRED(
Try to add a transaction to the mempool.
assert(!tx.IsCoinBase())