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());
142  Assert(res.m_vsize);
143  Assert(res.m_base_fees);
146  Assert(!res.m_other_wtxid);
147  break;
148  }
150  {
151  // It may be already in the mempool since in ATMP cases we don't set MEMPOOL_ENTRY or DIFFERENT_WITNESS
152  Assert(!res.m_state.IsValid());
153  Assert(res.m_state.IsInvalid());
154 
155  const bool is_reconsiderable{res.m_state.GetResult() == TxValidationResult::TX_RECONSIDERABLE};
156  Assert(!res.m_vsize);
157  Assert(!res.m_base_fees);
158  // Fee information is provided if the failure is TX_RECONSIDERABLE.
159  // In other cases, validation may be unable or unwilling to calculate the fees.
160  Assert(res.m_effective_feerate.has_value() == is_reconsiderable);
161  Assert(res.m_wtxids_fee_calculations.has_value() == is_reconsiderable);
162  Assert(!res.m_other_wtxid);
163  break;
164  }
166  {
167  // ATMP never sets this; only set in package settings
168  Assert(false);
169  break;
170  }
172  {
173  // ATMP never sets this; only set in package settings
174  Assert(false);
175  break;
176  }
177  }
178 }
179 
180 FUZZ_TARGET(tx_pool_standard, .init = initialize_tx_pool)
181 {
182  FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
183  const auto& node = g_setup->m_node;
184  auto& chainstate{static_cast<DummyChainState&>(node.chainman->ActiveChainstate())};
185 
186  MockTime(fuzzed_data_provider, chainstate);
187 
188  // All RBF-spendable outpoints
189  std::set<COutPoint> outpoints_rbf;
190  // All outpoints counting toward the total supply (subset of outpoints_rbf)
191  std::set<COutPoint> outpoints_supply;
192  for (const auto& outpoint : g_outpoints_coinbase_init_mature) {
193  Assert(outpoints_supply.insert(outpoint).second);
194  }
195  outpoints_rbf = outpoints_supply;
196 
197  // The sum of the values of all spendable outpoints
198  constexpr CAmount SUPPLY_TOTAL{COINBASE_MATURITY * 50 * COIN};
199 
200  SetMempoolConstraints(*node.args, fuzzed_data_provider);
201  CTxMemPool tx_pool_{MakeMempool(fuzzed_data_provider, node)};
202  MockedTxPool& tx_pool = *static_cast<MockedTxPool*>(&tx_pool_);
203 
204  chainstate.SetMempool(&tx_pool);
205 
206  // Helper to query an amount
207  const CCoinsViewMemPool amount_view{WITH_LOCK(::cs_main, return &chainstate.CoinsTip()), tx_pool};
208  const auto GetAmount = [&](const COutPoint& outpoint) {
209  Coin c;
210  Assert(amount_view.GetCoin(outpoint, c));
211  return c.out.nValue;
212  };
213 
214  LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 300)
215  {
216  {
217  // Total supply is the mempool fee + all outpoints
218  CAmount supply_now{WITH_LOCK(tx_pool.cs, return tx_pool.GetTotalFee())};
219  for (const auto& op : outpoints_supply) {
220  supply_now += GetAmount(op);
221  }
222  Assert(supply_now == SUPPLY_TOTAL);
223  }
224  Assert(!outpoints_supply.empty());
225 
226  // Create transaction to add to the mempool
227  const CTransactionRef tx = [&] {
228  CMutableTransaction tx_mut;
229  tx_mut.nVersion = fuzzed_data_provider.ConsumeBool() ? 3 : CTransaction::CURRENT_VERSION;
230  tx_mut.nLockTime = fuzzed_data_provider.ConsumeBool() ? 0 : fuzzed_data_provider.ConsumeIntegral<uint32_t>();
231  const auto num_in = fuzzed_data_provider.ConsumeIntegralInRange<int>(1, outpoints_rbf.size());
232  const auto num_out = fuzzed_data_provider.ConsumeIntegralInRange<int>(1, outpoints_rbf.size() * 2);
233 
234  CAmount amount_in{0};
235  for (int i = 0; i < num_in; ++i) {
236  // Pop random outpoint
237  auto pop = outpoints_rbf.begin();
238  std::advance(pop, fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, outpoints_rbf.size() - 1));
239  const auto outpoint = *pop;
240  outpoints_rbf.erase(pop);
241  amount_in += GetAmount(outpoint);
242 
243  // Create input
244  const auto sequence = ConsumeSequence(fuzzed_data_provider);
245  const auto script_sig = CScript{};
246  const auto script_wit_stack = std::vector<std::vector<uint8_t>>{WITNESS_STACK_ELEM_OP_TRUE};
247  CTxIn in;
248  in.prevout = outpoint;
249  in.nSequence = sequence;
250  in.scriptSig = script_sig;
251  in.scriptWitness.stack = script_wit_stack;
252 
253  tx_mut.vin.push_back(in);
254  }
255  const auto amount_fee = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-1000, amount_in);
256  const auto amount_out = (amount_in - amount_fee) / num_out;
257  for (int i = 0; i < num_out; ++i) {
258  tx_mut.vout.emplace_back(amount_out, P2WSH_OP_TRUE);
259  }
260  auto tx = MakeTransactionRef(tx_mut);
261  // Restore previously removed outpoints
262  for (const auto& in : tx->vin) {
263  Assert(outpoints_rbf.insert(in.prevout).second);
264  }
265  return tx;
266  }();
267 
268  if (fuzzed_data_provider.ConsumeBool()) {
269  MockTime(fuzzed_data_provider, chainstate);
270  }
271  if (fuzzed_data_provider.ConsumeBool()) {
272  tx_pool.RollingFeeUpdate();
273  }
274  if (fuzzed_data_provider.ConsumeBool()) {
275  const auto& txid = fuzzed_data_provider.ConsumeBool() ?
276  tx->GetHash() :
277  PickValue(fuzzed_data_provider, outpoints_rbf).hash;
278  const auto delta = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-50 * COIN, +50 * COIN);
279  tx_pool.PrioritiseTransaction(txid.ToUint256(), delta);
280  }
281 
282  // Remember all removed and added transactions
283  std::set<CTransactionRef> removed;
284  std::set<CTransactionRef> added;
285  auto txr = std::make_shared<TransactionsDelta>(removed, added);
286  node.validation_signals->RegisterSharedValidationInterface(txr);
287  const bool bypass_limits = fuzzed_data_provider.ConsumeBool();
288 
289  // Make sure ProcessNewPackage on one transaction works.
290  // The result is not guaranteed to be the same as what is returned by ATMP.
291  const auto result_package = WITH_LOCK(::cs_main,
292  return ProcessNewPackage(chainstate, tx_pool, {tx}, true, /*client_maxfeerate=*/{}));
293  // If something went wrong due to a package-specific policy, it might not return a
294  // validation result for the transaction.
295  if (result_package.m_state.GetResult() != PackageValidationResult::PCKG_POLICY) {
296  auto it = result_package.m_tx_results.find(tx->GetWitnessHash());
297  Assert(it != result_package.m_tx_results.end());
298  Assert(it->second.m_result_type == MempoolAcceptResult::ResultType::VALID ||
299  it->second.m_result_type == MempoolAcceptResult::ResultType::INVALID);
300  }
301 
302  const auto res = WITH_LOCK(::cs_main, return AcceptToMemoryPool(chainstate, tx, GetTime(), bypass_limits, /*test_accept=*/false));
303  const bool accepted = res.m_result_type == MempoolAcceptResult::ResultType::VALID;
304  node.validation_signals->SyncWithValidationInterfaceQueue();
305  node.validation_signals->UnregisterSharedValidationInterface(txr);
306 
307  bool txid_in_mempool = tx_pool.exists(GenTxid::Txid(tx->GetHash()));
308  bool wtxid_in_mempool = tx_pool.exists(GenTxid::Wtxid(tx->GetWitnessHash()));
309  CheckATMPInvariants(res, txid_in_mempool, wtxid_in_mempool);
310 
311  Assert(accepted != added.empty());
312  if (accepted) {
313  Assert(added.size() == 1); // For now, no package acceptance
314  Assert(tx == *added.begin());
315  CheckMempoolV3Invariants(tx_pool);
316  } else {
317  // Do not consider rejected transaction removed
318  removed.erase(tx);
319  }
320 
321  // Helper to insert spent and created outpoints of a tx into collections
322  using Sets = std::vector<std::reference_wrapper<std::set<COutPoint>>>;
323  const auto insert_tx = [](Sets created_by_tx, Sets consumed_by_tx, const auto& tx) {
324  for (size_t i{0}; i < tx.vout.size(); ++i) {
325  for (auto& set : created_by_tx) {
326  Assert(set.get().emplace(tx.GetHash(), i).second);
327  }
328  }
329  for (const auto& in : tx.vin) {
330  for (auto& set : consumed_by_tx) {
331  Assert(set.get().insert(in.prevout).second);
332  }
333  }
334  };
335  // Add created outpoints, remove spent outpoints
336  {
337  // Outpoints that no longer exist at all
338  std::set<COutPoint> consumed_erased;
339  // Outpoints that no longer count toward the total supply
340  std::set<COutPoint> consumed_supply;
341  for (const auto& removed_tx : removed) {
342  insert_tx(/*created_by_tx=*/{consumed_erased}, /*consumed_by_tx=*/{outpoints_supply}, /*tx=*/*removed_tx);
343  }
344  for (const auto& added_tx : added) {
345  insert_tx(/*created_by_tx=*/{outpoints_supply, outpoints_rbf}, /*consumed_by_tx=*/{consumed_supply}, /*tx=*/*added_tx);
346  }
347  for (const auto& p : consumed_erased) {
348  Assert(outpoints_supply.erase(p) == 1);
349  Assert(outpoints_rbf.erase(p) == 1);
350  }
351  for (const auto& p : consumed_supply) {
352  Assert(outpoints_supply.erase(p) == 1);
353  }
354  }
355  }
356  Finish(fuzzed_data_provider, tx_pool, chainstate);
357 }
358 
359 FUZZ_TARGET(tx_pool, .init = initialize_tx_pool)
360 {
361  FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
362  const auto& node = g_setup->m_node;
363  auto& chainstate{static_cast<DummyChainState&>(node.chainman->ActiveChainstate())};
364 
365  MockTime(fuzzed_data_provider, chainstate);
366 
367  std::vector<Txid> txids;
368  txids.reserve(g_outpoints_coinbase_init_mature.size());
369  for (const auto& outpoint : g_outpoints_coinbase_init_mature) {
370  txids.push_back(outpoint.hash);
371  }
372  for (int i{0}; i <= 3; ++i) {
373  // Add some immature and non-existent outpoints
374  txids.push_back(g_outpoints_coinbase_init_immature.at(i).hash);
375  txids.push_back(Txid::FromUint256(ConsumeUInt256(fuzzed_data_provider)));
376  }
377 
378  SetMempoolConstraints(*node.args, fuzzed_data_provider);
379  CTxMemPool tx_pool_{MakeMempool(fuzzed_data_provider, node)};
380  MockedTxPool& tx_pool = *static_cast<MockedTxPool*>(&tx_pool_);
381 
382  chainstate.SetMempool(&tx_pool);
383 
384  LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 300)
385  {
386  const auto mut_tx = ConsumeTransaction(fuzzed_data_provider, txids);
387 
388  if (fuzzed_data_provider.ConsumeBool()) {
389  MockTime(fuzzed_data_provider, chainstate);
390  }
391  if (fuzzed_data_provider.ConsumeBool()) {
392  tx_pool.RollingFeeUpdate();
393  }
394  if (fuzzed_data_provider.ConsumeBool()) {
395  const auto txid = fuzzed_data_provider.ConsumeBool() ?
396  mut_tx.GetHash() :
397  PickValue(fuzzed_data_provider, txids);
398  const auto delta = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-50 * COIN, +50 * COIN);
399  tx_pool.PrioritiseTransaction(txid.ToUint256(), delta);
400  }
401 
402  const auto tx = MakeTransactionRef(mut_tx);
403  const bool bypass_limits = fuzzed_data_provider.ConsumeBool();
404  const auto res = WITH_LOCK(::cs_main, return AcceptToMemoryPool(chainstate, tx, GetTime(), bypass_limits, /*test_accept=*/false));
405  const bool accepted = res.m_result_type == MempoolAcceptResult::ResultType::VALID;
406  if (accepted) {
407  txids.push_back(tx->GetHash());
408  CheckMempoolV3Invariants(tx_pool);
409  }
410  }
411  Finish(fuzzed_data_provider, tx_pool, chainstate);
412 }
413 } // 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:267
#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:834
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:490
CChain m_chain
The current chain of blockheaders we consult and build on.
Definition: validation.h:570
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:596
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:56
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:126
const std::optional< int64_t > m_vsize
Virtual size as used by the mempool, calculated using serialized size and sigops.
Definition: validation.h:143
const ResultType m_result_type
Result type.
Definition: validation.h:135
const std::optional< CAmount > m_base_fees
Raw base fees in satoshis.
Definition: validation.h:145
const TxValidationState m_state
Contains information about why the transaction failed.
Definition: validation.h:138
@ 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:151
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:160
const std::optional< std::vector< Wtxid > > m_wtxids_fee_calculations
Contains the wtxids of the transactions used for fee-related checks.
Definition: validation.h:157
Testing setup that configures a complete environment.
Definition: setup_common.h:85
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:53
std::unique_ptr< ValidationSignals > validation_signals
Issues calls about blocks and transactions.
Definition: context.h:82
#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:116
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
int64_t GetTime()
Definition: time.cpp:44
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())