Bitcoin Core  27.1.0
P2P Digital Currency
txvalidation_tests.cpp
Go to the documentation of this file.
1 // Copyright (c) 2017-2021 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <consensus/validation.h>
6 #include <key_io.h>
7 #include <policy/v3_policy.h>
8 #include <policy/packages.h>
9 #include <policy/policy.h>
10 #include <primitives/transaction.h>
11 #include <random.h>
12 #include <script/script.h>
13 #include <test/util/setup_common.h>
14 #include <test/util/txmempool.h>
15 #include <validation.h>
16 
17 #include <boost/test/unit_test.hpp>
18 
19 
20 BOOST_AUTO_TEST_SUITE(txvalidation_tests)
21 
22 
25 BOOST_FIXTURE_TEST_CASE(tx_mempool_reject_coinbase, TestChain100Setup)
26 {
27  CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG;
28  CMutableTransaction coinbaseTx;
29 
30  coinbaseTx.nVersion = 1;
31  coinbaseTx.vin.resize(1);
32  coinbaseTx.vout.resize(1);
33  coinbaseTx.vin[0].scriptSig = CScript() << OP_11 << OP_EQUAL;
34  coinbaseTx.vout[0].nValue = 1 * CENT;
35  coinbaseTx.vout[0].scriptPubKey = scriptPubKey;
36 
37  BOOST_CHECK(CTransaction(coinbaseTx).IsCoinBase());
38 
39  LOCK(cs_main);
40 
41  unsigned int initialPoolSize = m_node.mempool->size();
42  const MempoolAcceptResult result = m_node.chainman->ProcessTransaction(MakeTransactionRef(coinbaseTx));
43 
45 
46  // Check that the transaction hasn't been added to mempool.
47  BOOST_CHECK_EQUAL(m_node.mempool->size(), initialPoolSize);
48 
49  // Check that the validation state reflects the unsuccessful attempt.
50  BOOST_CHECK(result.m_state.IsInvalid());
51  BOOST_CHECK_EQUAL(result.m_state.GetRejectReason(), "coinbase");
53 }
54 
55 // Generate a number of random, nonexistent outpoints.
56 static inline std::vector<COutPoint> random_outpoints(size_t num_outpoints) {
57  std::vector<COutPoint> outpoints;
58  for (size_t i{0}; i < num_outpoints; ++i) {
59  outpoints.emplace_back(Txid::FromUint256(GetRandHash()), 0);
60  }
61  return outpoints;
62 }
63 
64 static inline std::vector<CPubKey> random_keys(size_t num_keys) {
65  std::vector<CPubKey> keys;
66  keys.reserve(num_keys);
67  for (size_t i{0}; i < num_keys; ++i) {
68  CKey key;
69  key.MakeNewKey(true);
70  keys.emplace_back(key.GetPubKey());
71  }
72  return keys;
73 }
74 
75 // Creates a placeholder tx (not valid) with 25 outputs. Specify the nVersion and the inputs.
76 static inline CTransactionRef make_tx(const std::vector<COutPoint>& inputs, int32_t version)
77 {
79  mtx.nVersion = version;
80  mtx.vin.resize(inputs.size());
81  mtx.vout.resize(25);
82  for (size_t i{0}; i < inputs.size(); ++i) {
83  mtx.vin[i].prevout = inputs[i];
84  }
85  for (auto i{0}; i < 25; ++i) {
86  mtx.vout[i].scriptPubKey = CScript() << OP_TRUE;
87  mtx.vout[i].nValue = 10000;
88  }
89  return MakeTransactionRef(mtx);
90 }
91 
93 {
94  // Test V3 policy helper functions
95  CTxMemPool& pool = *Assert(m_node.mempool);
96  LOCK2(cs_main, pool.cs);
98  std::set<Txid> empty_conflicts_set;
99  CTxMemPool::setEntries empty_ancestors;
100 
101  auto mempool_tx_v3 = make_tx(random_outpoints(1), /*version=*/3);
102  pool.addUnchecked(entry.FromTx(mempool_tx_v3));
103  auto mempool_tx_v2 = make_tx(random_outpoints(1), /*version=*/2);
104  pool.addUnchecked(entry.FromTx(mempool_tx_v2));
105  // Default values.
106  CTxMemPool::Limits m_limits{};
107 
108  // Cannot spend from an unconfirmed v3 transaction unless this tx is also v3.
109  {
110  // mempool_tx_v3
111  // ^
112  // tx_v2_from_v3
113  auto tx_v2_from_v3 = make_tx({COutPoint{mempool_tx_v3->GetHash(), 0}}, /*version=*/2);
114  auto ancestors_v2_from_v3{pool.CalculateMemPoolAncestors(entry.FromTx(tx_v2_from_v3), m_limits)};
115  const auto expected_error_str{strprintf("non-v3 tx %s (wtxid=%s) cannot spend from v3 tx %s (wtxid=%s)",
116  tx_v2_from_v3->GetHash().ToString(), tx_v2_from_v3->GetWitnessHash().ToString(),
117  mempool_tx_v3->GetHash().ToString(), mempool_tx_v3->GetWitnessHash().ToString())};
118  BOOST_CHECK(*SingleV3Checks(tx_v2_from_v3, *ancestors_v2_from_v3, empty_conflicts_set, GetVirtualTransactionSize(*tx_v2_from_v3)) == expected_error_str);
119 
120  Package package_v3_v2{mempool_tx_v3, tx_v2_from_v3};
121  BOOST_CHECK_EQUAL(*PackageV3Checks(tx_v2_from_v3, GetVirtualTransactionSize(*tx_v2_from_v3), package_v3_v2, empty_ancestors), expected_error_str);
122  CTxMemPool::setEntries entries_mempool_v3{pool.GetIter(mempool_tx_v3->GetHash().ToUint256()).value()};
123  BOOST_CHECK_EQUAL(*PackageV3Checks(tx_v2_from_v3, GetVirtualTransactionSize(*tx_v2_from_v3), {tx_v2_from_v3}, entries_mempool_v3), expected_error_str);
124 
125  // mempool_tx_v3 mempool_tx_v2
126  // ^ ^
127  // tx_v2_from_v2_and_v3
128  auto tx_v2_from_v2_and_v3 = make_tx({COutPoint{mempool_tx_v3->GetHash(), 0}, COutPoint{mempool_tx_v2->GetHash(), 0}}, /*version=*/2);
129  auto ancestors_v2_from_both{pool.CalculateMemPoolAncestors(entry.FromTx(tx_v2_from_v2_and_v3), m_limits)};
130  const auto expected_error_str_2{strprintf("non-v3 tx %s (wtxid=%s) cannot spend from v3 tx %s (wtxid=%s)",
131  tx_v2_from_v2_and_v3->GetHash().ToString(), tx_v2_from_v2_and_v3->GetWitnessHash().ToString(),
132  mempool_tx_v3->GetHash().ToString(), mempool_tx_v3->GetWitnessHash().ToString())};
133  BOOST_CHECK(*SingleV3Checks(tx_v2_from_v2_and_v3, *ancestors_v2_from_both, empty_conflicts_set, GetVirtualTransactionSize(*tx_v2_from_v2_and_v3))
134  == expected_error_str_2);
135 
136  Package package_v3_v2_v2{mempool_tx_v3, mempool_tx_v2, tx_v2_from_v2_and_v3};
137  BOOST_CHECK_EQUAL(*PackageV3Checks(tx_v2_from_v2_and_v3, GetVirtualTransactionSize(*tx_v2_from_v2_and_v3), package_v3_v2_v2, empty_ancestors), expected_error_str_2);
138  }
139 
140  // V3 cannot spend from an unconfirmed non-v3 transaction.
141  {
142  // mempool_tx_v2
143  // ^
144  // tx_v3_from_v2
145  auto tx_v3_from_v2 = make_tx({COutPoint{mempool_tx_v2->GetHash(), 0}}, /*version=*/3);
146  auto ancestors_v3_from_v2{pool.CalculateMemPoolAncestors(entry.FromTx(tx_v3_from_v2), m_limits)};
147  const auto expected_error_str{strprintf("v3 tx %s (wtxid=%s) cannot spend from non-v3 tx %s (wtxid=%s)",
148  tx_v3_from_v2->GetHash().ToString(), tx_v3_from_v2->GetWitnessHash().ToString(),
149  mempool_tx_v2->GetHash().ToString(), mempool_tx_v2->GetWitnessHash().ToString())};
150  BOOST_CHECK(*SingleV3Checks(tx_v3_from_v2, *ancestors_v3_from_v2, empty_conflicts_set, GetVirtualTransactionSize(*tx_v3_from_v2)) == expected_error_str);
151 
152  Package package_v2_v3{mempool_tx_v2, tx_v3_from_v2};
153  BOOST_CHECK_EQUAL(*PackageV3Checks(tx_v3_from_v2, GetVirtualTransactionSize(*tx_v3_from_v2), package_v2_v3, empty_ancestors), expected_error_str);
154  CTxMemPool::setEntries entries_mempool_v2{pool.GetIter(mempool_tx_v2->GetHash().ToUint256()).value()};
155  BOOST_CHECK_EQUAL(*PackageV3Checks(tx_v3_from_v2, GetVirtualTransactionSize(*tx_v3_from_v2), {tx_v3_from_v2}, entries_mempool_v2), expected_error_str);
156 
157  // mempool_tx_v3 mempool_tx_v2
158  // ^ ^
159  // tx_v3_from_v2_and_v3
160  auto tx_v3_from_v2_and_v3 = make_tx({COutPoint{mempool_tx_v3->GetHash(), 0}, COutPoint{mempool_tx_v2->GetHash(), 0}}, /*version=*/3);
161  auto ancestors_v3_from_both{pool.CalculateMemPoolAncestors(entry.FromTx(tx_v3_from_v2_and_v3), m_limits)};
162  const auto expected_error_str_2{strprintf("v3 tx %s (wtxid=%s) cannot spend from non-v3 tx %s (wtxid=%s)",
163  tx_v3_from_v2_and_v3->GetHash().ToString(), tx_v3_from_v2_and_v3->GetWitnessHash().ToString(),
164  mempool_tx_v2->GetHash().ToString(), mempool_tx_v2->GetWitnessHash().ToString())};
165  BOOST_CHECK(*SingleV3Checks(tx_v3_from_v2_and_v3, *ancestors_v3_from_both, empty_conflicts_set, GetVirtualTransactionSize(*tx_v3_from_v2_and_v3))
166  == expected_error_str_2);
167 
168  // tx_v3_from_v2_and_v3 also violates V3_ANCESTOR_LIMIT.
169  const auto expected_error_str_3{strprintf("tx %s (wtxid=%s) would have too many ancestors",
170  tx_v3_from_v2_and_v3->GetHash().ToString(), tx_v3_from_v2_and_v3->GetWitnessHash().ToString())};
171  Package package_v3_v2_v3{mempool_tx_v3, mempool_tx_v2, tx_v3_from_v2_and_v3};
172  BOOST_CHECK_EQUAL(*PackageV3Checks(tx_v3_from_v2_and_v3, GetVirtualTransactionSize(*tx_v3_from_v2_and_v3), package_v3_v2_v3, empty_ancestors), expected_error_str_3);
173  }
174  // V3 from V3 is ok, and non-V3 from non-V3 is ok.
175  {
176  // mempool_tx_v3
177  // ^
178  // tx_v3_from_v3
179  auto tx_v3_from_v3 = make_tx({COutPoint{mempool_tx_v3->GetHash(), 0}}, /*version=*/3);
180  auto ancestors_v3{pool.CalculateMemPoolAncestors(entry.FromTx(tx_v3_from_v3), m_limits)};
181  BOOST_CHECK(SingleV3Checks(tx_v3_from_v3, *ancestors_v3, empty_conflicts_set, GetVirtualTransactionSize(*tx_v3_from_v3))
182  == std::nullopt);
183 
184  Package package_v3_v3{mempool_tx_v3, tx_v3_from_v3};
185  BOOST_CHECK(PackageV3Checks(tx_v3_from_v3, GetVirtualTransactionSize(*tx_v3_from_v3), package_v3_v3, empty_ancestors) == std::nullopt);
186 
187  // mempool_tx_v2
188  // ^
189  // tx_v2_from_v2
190  auto tx_v2_from_v2 = make_tx({COutPoint{mempool_tx_v2->GetHash(), 0}}, /*version=*/2);
191  auto ancestors_v2{pool.CalculateMemPoolAncestors(entry.FromTx(tx_v2_from_v2), m_limits)};
192  BOOST_CHECK(SingleV3Checks(tx_v2_from_v2, *ancestors_v2, empty_conflicts_set, GetVirtualTransactionSize(*tx_v2_from_v2))
193  == std::nullopt);
194 
195  Package package_v2_v2{mempool_tx_v2, tx_v2_from_v2};
196  BOOST_CHECK(PackageV3Checks(tx_v2_from_v2, GetVirtualTransactionSize(*tx_v2_from_v2), package_v2_v2, empty_ancestors) == std::nullopt);
197  }
198 
199  // Tx spending v3 cannot have too many mempool ancestors
200  // Configuration where the tx has multiple direct parents.
201  {
202  Package package_multi_parents;
203  std::vector<COutPoint> mempool_outpoints;
204  mempool_outpoints.emplace_back(mempool_tx_v3->GetHash(), 0);
205  package_multi_parents.emplace_back(mempool_tx_v3);
206  for (size_t i{0}; i < 2; ++i) {
207  auto mempool_tx = make_tx(random_outpoints(i + 1), /*version=*/3);
208  pool.addUnchecked(entry.FromTx(mempool_tx));
209  mempool_outpoints.emplace_back(mempool_tx->GetHash(), 0);
210  package_multi_parents.emplace_back(mempool_tx);
211  }
212  auto tx_v3_multi_parent = make_tx(mempool_outpoints, /*version=*/3);
213  package_multi_parents.emplace_back(tx_v3_multi_parent);
214  auto ancestors{pool.CalculateMemPoolAncestors(entry.FromTx(tx_v3_multi_parent), m_limits)};
215  BOOST_CHECK_EQUAL(ancestors->size(), 3);
216  const auto expected_error_str{strprintf("tx %s (wtxid=%s) would have too many ancestors",
217  tx_v3_multi_parent->GetHash().ToString(), tx_v3_multi_parent->GetWitnessHash().ToString())};
218  BOOST_CHECK_EQUAL(*SingleV3Checks(tx_v3_multi_parent, *ancestors, empty_conflicts_set, GetVirtualTransactionSize(*tx_v3_multi_parent)),
219  expected_error_str);
220 
221  BOOST_CHECK_EQUAL(*PackageV3Checks(tx_v3_multi_parent, GetVirtualTransactionSize(*tx_v3_multi_parent), package_multi_parents, empty_ancestors),
222  expected_error_str);
223  }
224 
225  // Configuration where the tx is in a multi-generation chain.
226  {
227  Package package_multi_gen;
228  CTransactionRef middle_tx;
229  auto last_outpoint{random_outpoints(1)[0]};
230  for (size_t i{0}; i < 2; ++i) {
231  auto mempool_tx = make_tx({last_outpoint}, /*version=*/3);
232  pool.addUnchecked(entry.FromTx(mempool_tx));
233  last_outpoint = COutPoint{mempool_tx->GetHash(), 0};
234  package_multi_gen.emplace_back(mempool_tx);
235  if (i == 1) middle_tx = mempool_tx;
236  }
237  auto tx_v3_multi_gen = make_tx({last_outpoint}, /*version=*/3);
238  package_multi_gen.emplace_back(tx_v3_multi_gen);
239  auto ancestors{pool.CalculateMemPoolAncestors(entry.FromTx(tx_v3_multi_gen), m_limits)};
240  const auto expected_error_str{strprintf("tx %s (wtxid=%s) would have too many ancestors",
241  tx_v3_multi_gen->GetHash().ToString(), tx_v3_multi_gen->GetWitnessHash().ToString())};
242  BOOST_CHECK_EQUAL(*SingleV3Checks(tx_v3_multi_gen, *ancestors, empty_conflicts_set, GetVirtualTransactionSize(*tx_v3_multi_gen)),
243  expected_error_str);
244 
245  // Middle tx is what triggers a failure for the grandchild:
246  BOOST_CHECK_EQUAL(*PackageV3Checks(middle_tx, GetVirtualTransactionSize(*middle_tx), package_multi_gen, empty_ancestors), expected_error_str);
247  BOOST_CHECK(PackageV3Checks(tx_v3_multi_gen, GetVirtualTransactionSize(*tx_v3_multi_gen), package_multi_gen, empty_ancestors) == std::nullopt);
248  }
249 
250  // Tx spending v3 cannot be too large in virtual size.
251  auto many_inputs{random_outpoints(100)};
252  many_inputs.emplace_back(mempool_tx_v3->GetHash(), 0);
253  {
254  auto tx_v3_child_big = make_tx(many_inputs, /*version=*/3);
255  const auto vsize{GetVirtualTransactionSize(*tx_v3_child_big)};
256  auto ancestors{pool.CalculateMemPoolAncestors(entry.FromTx(tx_v3_child_big), m_limits)};
257  const auto expected_error_str{strprintf("v3 child tx %s (wtxid=%s) is too big: %u > %u virtual bytes",
258  tx_v3_child_big->GetHash().ToString(), tx_v3_child_big->GetWitnessHash().ToString(), vsize, V3_CHILD_MAX_VSIZE)};
259  BOOST_CHECK_EQUAL(*SingleV3Checks(tx_v3_child_big, *ancestors, empty_conflicts_set, GetVirtualTransactionSize(*tx_v3_child_big)),
260  expected_error_str);
261 
262  Package package_child_big{mempool_tx_v3, tx_v3_child_big};
263  BOOST_CHECK_EQUAL(*PackageV3Checks(tx_v3_child_big, GetVirtualTransactionSize(*tx_v3_child_big), package_child_big, empty_ancestors),
264  expected_error_str);
265  }
266 
267  // Tx spending v3 cannot have too many sigops.
268  // This child has 10 P2WSH multisig inputs.
269  auto multisig_outpoints{random_outpoints(10)};
270  multisig_outpoints.emplace_back(mempool_tx_v3->GetHash(), 0);
271  auto keys{random_keys(2)};
272  CScript script_multisig;
273  script_multisig << OP_1;
274  for (const auto& key : keys) {
275  script_multisig << ToByteVector(key);
276  }
277  script_multisig << OP_2 << OP_CHECKMULTISIG;
278  {
279  CMutableTransaction mtx_many_sigops = CMutableTransaction{};
280  mtx_many_sigops.nVersion = 3;
281  for (const auto& outpoint : multisig_outpoints) {
282  mtx_many_sigops.vin.emplace_back(outpoint);
283  mtx_many_sigops.vin.back().scriptWitness.stack.emplace_back(script_multisig.begin(), script_multisig.end());
284  }
285  mtx_many_sigops.vout.resize(1);
286  mtx_many_sigops.vout.back().scriptPubKey = CScript() << OP_TRUE;
287  mtx_many_sigops.vout.back().nValue = 10000;
288  auto tx_many_sigops{MakeTransactionRef(mtx_many_sigops)};
289 
290  auto ancestors{pool.CalculateMemPoolAncestors(entry.FromTx(tx_many_sigops), m_limits)};
291  // legacy uses fAccurate = false, and the maximum number of multisig keys is used
292  const int64_t total_sigops{static_cast<int64_t>(tx_many_sigops->vin.size()) * static_cast<int64_t>(script_multisig.GetSigOpCount(/*fAccurate=*/false))};
293  BOOST_CHECK_EQUAL(total_sigops, tx_many_sigops->vin.size() * MAX_PUBKEYS_PER_MULTISIG);
294  const int64_t bip141_vsize{GetVirtualTransactionSize(*tx_many_sigops)};
295  // Weight limit is not reached...
296  BOOST_CHECK(SingleV3Checks(tx_many_sigops, *ancestors, empty_conflicts_set, bip141_vsize) == std::nullopt);
297  // ...but sigop limit is.
298  const auto expected_error_str{strprintf("v3 child tx %s (wtxid=%s) is too big: %u > %u virtual bytes",
299  tx_many_sigops->GetHash().ToString(), tx_many_sigops->GetWitnessHash().ToString(),
301  BOOST_CHECK_EQUAL(*SingleV3Checks(tx_many_sigops, *ancestors, empty_conflicts_set,
302  GetVirtualTransactionSize(*tx_many_sigops, /*nSigOpCost=*/total_sigops, /*bytes_per_sigop=*/ DEFAULT_BYTES_PER_SIGOP)),
303  expected_error_str);
304 
305  Package package_child_sigops{mempool_tx_v3, tx_many_sigops};
306  BOOST_CHECK_EQUAL(*PackageV3Checks(tx_many_sigops, total_sigops * DEFAULT_BYTES_PER_SIGOP / WITNESS_SCALE_FACTOR, package_child_sigops, empty_ancestors),
307  expected_error_str);
308  }
309 
310  // Parent + child with v3 in the mempool. Child is allowed as long as it is under V3_CHILD_MAX_VSIZE.
311  auto tx_mempool_v3_child = make_tx({COutPoint{mempool_tx_v3->GetHash(), 0}}, /*version=*/3);
312  {
314  auto ancestors{pool.CalculateMemPoolAncestors(entry.FromTx(tx_mempool_v3_child), m_limits)};
315  BOOST_CHECK(SingleV3Checks(tx_mempool_v3_child, *ancestors, empty_conflicts_set, GetVirtualTransactionSize(*tx_mempool_v3_child)) == std::nullopt);
316  pool.addUnchecked(entry.FromTx(tx_mempool_v3_child));
317 
318  Package package_v3_1p1c{mempool_tx_v3, tx_mempool_v3_child};
319  BOOST_CHECK(PackageV3Checks(tx_mempool_v3_child, GetVirtualTransactionSize(*tx_mempool_v3_child), package_v3_1p1c, empty_ancestors) == std::nullopt);
320  }
321 
322  // A v3 transaction cannot have more than 1 descendant.
323  // Configuration where tx has multiple direct children.
324  {
325  auto tx_v3_child2 = make_tx({COutPoint{mempool_tx_v3->GetHash(), 1}}, /*version=*/3);
326  auto ancestors{pool.CalculateMemPoolAncestors(entry.FromTx(tx_v3_child2), m_limits)};
327  const auto expected_error_str{strprintf("tx %s (wtxid=%s) would exceed descendant count limit",
328  mempool_tx_v3->GetHash().ToString(), mempool_tx_v3->GetWitnessHash().ToString())};
329  BOOST_CHECK_EQUAL(*SingleV3Checks(tx_v3_child2, *ancestors, empty_conflicts_set, GetVirtualTransactionSize(*tx_v3_child2)),
330  expected_error_str);
331  // If replacing the child, make sure there is no double-counting.
332  BOOST_CHECK(SingleV3Checks(tx_v3_child2, *ancestors, {tx_mempool_v3_child->GetHash()}, GetVirtualTransactionSize(*tx_v3_child2))
333  == std::nullopt);
334 
335  Package package_v3_1p2c{mempool_tx_v3, tx_mempool_v3_child, tx_v3_child2};
336  BOOST_CHECK_EQUAL(*PackageV3Checks(tx_v3_child2, GetVirtualTransactionSize(*tx_v3_child2), package_v3_1p2c, empty_ancestors),
337  expected_error_str);
338  }
339 
340  // Configuration where tx has multiple generations of descendants is not tested because that is
341  // equivalent to the tx with multiple generations of ancestors.
342 }
343 
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:423
unsigned int GetSigOpCount(bool fAccurate) const
Pre-version-0.6, Bitcoin always counted CHECKMULTISIGs as 20 sigops.
Definition: script.cpp:159
invalid by consensus rules
static const int WITNESS_SCALE_FACTOR
Definition: consensus.h:21
Definition: txmempool.h:19
node::NodeContext m_node
Definition: bitcoin-gui.cpp:37
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1162
Options struct containing limit options for a CTxMemPool.
CPubKey GetPubKey() const
Compute the public key from a private key.
Definition: key.cpp:188
uint256 GetRandHash() noexcept
Definition: random.cpp:650
std::vector< CTxIn > vin
Definition: transaction.h:379
std::vector< CTransactionRef > Package
A package is an ordered list of transactions.
Definition: packages.h:50
std::optional< std::string > SingleV3Checks(const CTransactionRef &ptx, const CTxMemPool::setEntries &mempool_ancestors, const std::set< Txid > &direct_conflicts, int64_t vsize)
Must be called for every transaction, even if not v3.
Definition: v3_policy.cpp:161
std::set< txiter, CompareIteratorByHash > setEntries
Definition: txmempool.h:394
const TxValidationState m_state
Contains information about why the transaction failed.
Definition: validation.h:139
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost, unsigned int bytes_per_sigop)
Compute the virtual transaction size (weight reinterpreted as bytes).
Definition: policy.cpp:295
CTxMemPoolEntry FromTx(const CMutableTransaction &tx) const
Definition: txmempool.cpp:31
const ResultType m_result_type
Result type.
Definition: validation.h:136
static constexpr unsigned int DEFAULT_BYTES_PER_SIGOP
Default for -bytespersigop.
Definition: policy.h:37
static const int MAX_PUBKEYS_PER_MULTISIG
Definition: script.h:33
static int32_t GetTransactionWeight(const CTransaction &tx)
Definition: validation.h:149
util::Result< setEntries > CalculateMemPoolAncestors(const CTxMemPoolEntry &entry, const Limits &limits, bool fSearchForParents=true) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Try to calculate all in-mempool ancestors of entry.
Definition: txmempool.cpp:237
std::unique_ptr< CTxMemPool > mempool
Definition: context.h:57
Definition: script.h:82
iterator end()
Definition: prevector.h:306
Definition: script.h:93
#define LOCK2(cs1, cs2)
Definition: sync.h:258
static std::vector< CPubKey > random_keys(size_t num_keys)
Definition: script.h:83
#define LOCK(cs)
Definition: sync.h:257
static CTransactionRef make_tx(const std::vector< COutPoint > &inputs, int32_t version)
BOOST_AUTO_TEST_SUITE_END()
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
Definition: key.cpp:161
Result GetResult() const
Definition: validation.h:125
Testing fixture that pre-creates a 100-block REGTEST-mode block chain.
Definition: setup_common.h:99
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:380
Validation result for a transaction evaluated by MemPoolAccept (single or package).
Definition: validation.h:127
std::optional< std::string > PackageV3Checks(const CTransactionRef &ptx, int64_t vsize, const Package &package, const CTxMemPool::setEntries &mempool_ancestors)
Must be called for every transaction that is submitted within a package, even if not v3...
Definition: v3_policy.cpp:58
static CTransactionRef MakeTransactionRef(Tx &&txIn)
Definition: transaction.h:424
static constexpr int64_t V3_CHILD_MAX_VSIZE
Maximum sigop-adjusted virtual size of a tx which spends from an unconfirmed v3 transaction.
Definition: v3_policy.h:28
void check(const CCoinsViewCache &active_coins_tip, int64_t spendheight) const EXCLUSIVE_LOCKS_REQUIRED(void addUnchecked(const CTxMemPoolEntry &entry) EXCLUSIVE_LOCKS_REQUIRED(cs
If sanity-checking is turned on, check makes sure the pool is consistent (does not contain two transa...
Definition: txmempool.h:472
BOOST_FIXTURE_TEST_CASE(tx_mempool_reject_coinbase, TestChain100Setup)
Ensure that the mempool won&#39;t accept coinbase transactions.
std::optional< txiter > GetIter(const uint256 &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Returns an iterator to the given hash, if found.
Definition: txmempool.cpp:946
std::vector< unsigned char > ToByteVector(const T &in)
Definition: script.h:66
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:299
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:18
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:413
static transaction_identifier FromUint256(const uint256 &id)
bool IsInvalid() const
Definition: validation.h:123
iterator begin()
Definition: prevector.h:304
BOOST_AUTO_TEST_SUITE(cuckoocache_tests)
Test Suite for CuckooCache.
A mutable version of CTransaction.
Definition: transaction.h:377
Definition: script.h:84
static std::vector< COutPoint > random_outpoints(size_t num_outpoints)
static constexpr CAmount CENT
Definition: setup_common.h:44
An encapsulated private key.
Definition: key.h:32
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:295
std::string GetRejectReason() const
Definition: validation.h:126
Identical to TestingSetup, but chain set to regtest.
Definition: setup_common.h:87
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
Definition: cs_main.cpp:8
std::unique_ptr< ChainstateManager > chainman
Definition: context.h:61
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it...
Definition: txmempool.h:388
#define Assert(val)
Identity function.
Definition: check.h:77
#define BOOST_CHECK(expr)
Definition: object.cpp:17