Bitcoin Core  29.1.0
P2P Digital Currency
miner_tests.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-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 <addresstype.h>
6 #include <coins.h>
7 #include <common/system.h>
8 #include <consensus/consensus.h>
9 #include <consensus/merkle.h>
10 #include <consensus/tx_verify.h>
11 #include <interfaces/mining.h>
12 #include <node/miner.h>
13 #include <policy/policy.h>
14 #include <test/util/random.h>
16 #include <test/util/txmempool.h>
17 #include <txmempool.h>
18 #include <uint256.h>
19 #include <util/check.h>
20 #include <util/feefrac.h>
21 #include <util/strencodings.h>
22 #include <util/time.h>
23 #include <util/translation.h>
24 #include <validation.h>
25 #include <versionbits.h>
26 
27 #include <test/util/setup_common.h>
28 
29 #include <memory>
30 #include <vector>
31 
32 #include <boost/test/unit_test.hpp>
33 
34 using namespace util::hex_literals;
36 using interfaces::Mining;
38 
39 namespace miner_tests {
41  void TestPackageSelection(const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
42  void TestBasicMining(const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst, int baseheight) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
43  void TestPrioritisedMining(const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
45  {
46  CCoinsViewMemPool view_mempool{&m_node.chainman->ActiveChainstate().CoinsTip(), tx_mempool};
47  CBlockIndex* tip{m_node.chainman->ActiveChain().Tip()};
48  const std::optional<LockPoints> lock_points{CalculateLockPointsAtTip(tip, view_mempool, tx)};
49  return lock_points.has_value() && CheckSequenceLocksAtTip(tip, *lock_points);
50  }
52  {
53  // Delete the previous mempool to ensure with valgrind that the old
54  // pointer is not accessed, when the new one should be accessed
55  // instead.
56  m_node.mempool.reset();
57  bilingual_str error;
58  m_node.mempool = std::make_unique<CTxMemPool>(MemPoolOptionsForTest(m_node), error);
59  Assert(error.empty());
60  return *m_node.mempool;
61  }
62  std::unique_ptr<Mining> MakeMining()
63  {
65  }
66 };
67 } // namespace miner_tests
68 
69 BOOST_FIXTURE_TEST_SUITE(miner_tests, MinerTestingSetup)
70 
72 
73 constexpr static struct {
74  unsigned char extranonce;
75  unsigned int nonce;
76 } BLOCKINFO[]{{8, 582909131}, {0, 971462344}, {2, 1169481553}, {6, 66147495}, {7, 427785981}, {8, 80538907},
77  {8, 207348013}, {2, 1951240923}, {4, 215054351}, {1, 491520534}, {8, 1282281282}, {4, 639565734},
78  {3, 248274685}, {8, 1160085976}, {6, 396349768}, {5, 393780549}, {5, 1096899528}, {4, 965381630},
79  {0, 728758712}, {5, 318638310}, {3, 164591898}, {2, 274234550}, {2, 254411237}, {7, 561761812},
80  {2, 268342573}, {0, 402816691}, {1, 221006382}, {6, 538872455}, {7, 393315655}, {4, 814555937},
81  {7, 504879194}, {6, 467769648}, {3, 925972193}, {2, 200581872}, {3, 168915404}, {8, 430446262},
82  {5, 773507406}, {3, 1195366164}, {0, 433361157}, {3, 297051771}, {0, 558856551}, {2, 501614039},
83  {3, 528488272}, {2, 473587734}, {8, 230125274}, {2, 494084400}, {4, 357314010}, {8, 60361686},
84  {7, 640624687}, {3, 480441695}, {8, 1424447925}, {4, 752745419}, {1, 288532283}, {6, 669170574},
85  {5, 1900907591}, {3, 555326037}, {3, 1121014051}, {0, 545835650}, {8, 189196651}, {5, 252371575},
86  {0, 199163095}, {6, 558895874}, {6, 1656839784}, {6, 815175452}, {6, 718677851}, {5, 544000334},
87  {0, 340113484}, {6, 850744437}, {4, 496721063}, {8, 524715182}, {6, 574361898}, {6, 1642305743},
88  {6, 355110149}, {5, 1647379658}, {8, 1103005356}, {7, 556460625}, {3, 1139533992}, {5, 304736030},
89  {2, 361539446}, {2, 143720360}, {6, 201939025}, {7, 423141476}, {4, 574633709}, {3, 1412254823},
90  {4, 873254135}, {0, 341817335}, {6, 53501687}, {3, 179755410}, {5, 172209688}, {8, 516810279},
91  {4, 1228391489}, {8, 325372589}, {6, 550367589}, {0, 876291812}, {7, 412454120}, {7, 717202854},
92  {2, 222677843}, {6, 251778867}, {7, 842004420}, {7, 194762829}, {4, 96668841}, {1, 925485796},
93  {0, 792342903}, {6, 678455063}, {6, 773251385}, {5, 186617471}, {6, 883189502}, {7, 396077336},
94  {8, 254702874}, {0, 455592851}};
95 
96 static std::unique_ptr<CBlockIndex> CreateBlockIndex(int nHeight, CBlockIndex* active_chain_tip) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
97 {
98  auto index{std::make_unique<CBlockIndex>()};
99  index->nHeight = nHeight;
100  index->pprev = active_chain_tip;
101  return index;
102 }
103 
104 // Test suite for ancestor feerate transaction selection.
105 // Implemented as an additional function, rather than a separate test case,
106 // to allow reusing the blockchain created in CreateNewBlock_validity.
107 void MinerTestingSetup::TestPackageSelection(const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst)
108 {
109  CTxMemPool& tx_mempool{MakeMempool()};
110  auto mining{MakeMining()};
111  BlockAssembler::Options options;
112  options.coinbase_output_script = scriptPubKey;
113 
114  LOCK(tx_mempool.cs);
115  // Test the ancestor feerate transaction selection.
117 
118  // Test that a medium fee transaction will be selected after a higher fee
119  // rate package with a low fee rate parent.
121  tx.vin.resize(1);
122  tx.vin[0].scriptSig = CScript() << OP_1;
123  tx.vin[0].prevout.hash = txFirst[0]->GetHash();
124  tx.vin[0].prevout.n = 0;
125  tx.vout.resize(1);
126  tx.vout[0].nValue = 5000000000LL - 1000;
127  // This tx has a low fee: 1000 satoshis
128  Txid hashParentTx = tx.GetHash(); // save this txid for later use
129  const auto parent_tx{entry.Fee(1000).Time(Now<NodeSeconds>()).SpendsCoinbase(true).FromTx(tx)};
130  AddToMempool(tx_mempool, parent_tx);
131 
132  // This tx has a medium fee: 10000 satoshis
133  tx.vin[0].prevout.hash = txFirst[1]->GetHash();
134  tx.vout[0].nValue = 5000000000LL - 10000;
135  Txid hashMediumFeeTx = tx.GetHash();
136  const auto medium_fee_tx{entry.Fee(10000).Time(Now<NodeSeconds>()).SpendsCoinbase(true).FromTx(tx)};
137  AddToMempool(tx_mempool, medium_fee_tx);
138 
139  // This tx has a high fee, but depends on the first transaction
140  tx.vin[0].prevout.hash = hashParentTx;
141  tx.vout[0].nValue = 5000000000LL - 1000 - 50000; // 50k satoshi fee
142  Txid hashHighFeeTx = tx.GetHash();
143  const auto high_fee_tx{entry.Fee(50000).Time(Now<NodeSeconds>()).SpendsCoinbase(false).FromTx(tx)};
144  AddToMempool(tx_mempool, high_fee_tx);
145 
146  std::unique_ptr<BlockTemplate> block_template = mining->createNewBlock(options);
147  BOOST_REQUIRE(block_template);
148  CBlock block{block_template->getBlock()};
149  BOOST_REQUIRE_EQUAL(block.vtx.size(), 4U);
150  BOOST_CHECK(block.vtx[1]->GetHash() == hashParentTx);
151  BOOST_CHECK(block.vtx[2]->GetHash() == hashHighFeeTx);
152  BOOST_CHECK(block.vtx[3]->GetHash() == hashMediumFeeTx);
153 
154  // Test the inclusion of package feerates in the block template and ensure they are sequential.
155  const auto block_package_feerates = BlockAssembler{m_node.chainman->ActiveChainstate(), &tx_mempool, options}.CreateNewBlock()->m_package_feerates;
156  BOOST_CHECK(block_package_feerates.size() == 2);
157 
158  // parent_tx and high_fee_tx are added to the block as a package.
159  const auto combined_txs_fee = parent_tx.GetFee() + high_fee_tx.GetFee();
160  const auto combined_txs_size = parent_tx.GetTxSize() + high_fee_tx.GetTxSize();
161  FeeFrac package_feefrac{combined_txs_fee, combined_txs_size};
162  // The package should be added first.
163  BOOST_CHECK(block_package_feerates[0] == package_feefrac);
164 
165  // The medium_fee_tx should be added next.
166  FeeFrac medium_tx_feefrac{medium_fee_tx.GetFee(), medium_fee_tx.GetTxSize()};
167  BOOST_CHECK(block_package_feerates[1] == medium_tx_feefrac);
168 
169  // Test that a package below the block min tx fee doesn't get included
170  tx.vin[0].prevout.hash = hashHighFeeTx;
171  tx.vout[0].nValue = 5000000000LL - 1000 - 50000; // 0 fee
172  Txid hashFreeTx = tx.GetHash();
173  AddToMempool(tx_mempool, entry.Fee(0).FromTx(tx));
174  size_t freeTxSize = ::GetSerializeSize(TX_WITH_WITNESS(tx));
175 
176  // Calculate a fee on child transaction that will put the package just
177  // below the block min tx fee (assuming 1 child tx of the same size).
178  CAmount feeToUse = blockMinFeeRate.GetFee(2*freeTxSize) - 1;
179 
180  tx.vin[0].prevout.hash = hashFreeTx;
181  tx.vout[0].nValue = 5000000000LL - 1000 - 50000 - feeToUse;
182  Txid hashLowFeeTx = tx.GetHash();
183  AddToMempool(tx_mempool, entry.Fee(feeToUse).FromTx(tx));
184  block_template = mining->createNewBlock(options);
185  BOOST_REQUIRE(block_template);
186  block = block_template->getBlock();
187  // Verify that the free tx and the low fee tx didn't get selected
188  for (size_t i=0; i<block.vtx.size(); ++i) {
189  BOOST_CHECK(block.vtx[i]->GetHash() != hashFreeTx);
190  BOOST_CHECK(block.vtx[i]->GetHash() != hashLowFeeTx);
191  }
192 
193  // Test that packages above the min relay fee do get included, even if one
194  // of the transactions is below the min relay fee
195  // Remove the low fee transaction and replace with a higher fee transaction
196  tx_mempool.removeRecursive(CTransaction(tx), MemPoolRemovalReason::REPLACED);
197  tx.vout[0].nValue -= 2; // Now we should be just over the min relay fee
198  hashLowFeeTx = tx.GetHash();
199  AddToMempool(tx_mempool, entry.Fee(feeToUse + 2).FromTx(tx));
200  block_template = mining->createNewBlock(options);
201  BOOST_REQUIRE(block_template);
202  block = block_template->getBlock();
203  BOOST_REQUIRE_EQUAL(block.vtx.size(), 6U);
204  BOOST_CHECK(block.vtx[4]->GetHash() == hashFreeTx);
205  BOOST_CHECK(block.vtx[5]->GetHash() == hashLowFeeTx);
206 
207  // Test that transaction selection properly updates ancestor fee
208  // calculations as ancestor transactions get included in a block.
209  // Add a 0-fee transaction that has 2 outputs.
210  tx.vin[0].prevout.hash = txFirst[2]->GetHash();
211  tx.vout.resize(2);
212  tx.vout[0].nValue = 5000000000LL - 100000000;
213  tx.vout[1].nValue = 100000000; // 1BTC output
214  // Increase size to avoid rounding errors: when the feerate is extremely small (i.e. 1sat/kvB), evaluating the fee
215  // at a smaller transaction size gives us a rounded value of 0.
216  BulkTransaction(tx, 4000);
217  Txid hashFreeTx2 = tx.GetHash();
218  AddToMempool(tx_mempool, entry.Fee(0).SpendsCoinbase(true).FromTx(tx));
219 
220  // This tx can't be mined by itself
221  tx.vin[0].prevout.hash = hashFreeTx2;
222  tx.vout.resize(1);
223  feeToUse = blockMinFeeRate.GetFee(freeTxSize);
224  tx.vout[0].nValue = 5000000000LL - 100000000 - feeToUse;
225  Txid hashLowFeeTx2 = tx.GetHash();
226  AddToMempool(tx_mempool, entry.Fee(feeToUse).SpendsCoinbase(false).FromTx(tx));
227  block_template = mining->createNewBlock(options);
228  BOOST_REQUIRE(block_template);
229  block = block_template->getBlock();
230 
231  // Verify that this tx isn't selected.
232  for (size_t i=0; i<block.vtx.size(); ++i) {
233  BOOST_CHECK(block.vtx[i]->GetHash() != hashFreeTx2);
234  BOOST_CHECK(block.vtx[i]->GetHash() != hashLowFeeTx2);
235  }
236 
237  // This tx will be mineable, and should cause hashLowFeeTx2 to be selected
238  // as well.
239  tx.vin[0].prevout.n = 1;
240  tx.vout[0].nValue = 100000000 - 10000; // 10k satoshi fee
241  AddToMempool(tx_mempool, entry.Fee(10000).FromTx(tx));
242  block_template = mining->createNewBlock(options);
243  BOOST_REQUIRE(block_template);
244  block = block_template->getBlock();
245  BOOST_REQUIRE_EQUAL(block.vtx.size(), 9U);
246  BOOST_CHECK(block.vtx[8]->GetHash() == hashLowFeeTx2);
247 }
248 
249 void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst, int baseheight)
250 {
251  Txid hash;
254  entry.nFee = 11;
255  entry.nHeight = 11;
256 
257  const CAmount BLOCKSUBSIDY = 50 * COIN;
258  const CAmount LOWFEE = CENT;
259  const CAmount HIGHFEE = COIN;
260  const CAmount HIGHERFEE = 4 * COIN;
261 
262  auto mining{MakeMining()};
263  BOOST_REQUIRE(mining);
264 
265  BlockAssembler::Options options;
266  options.coinbase_output_script = scriptPubKey;
267 
268  {
269  CTxMemPool& tx_mempool{MakeMempool()};
270  LOCK(tx_mempool.cs);
271 
272  // Just to make sure we can still make simple blocks
273  auto block_template{mining->createNewBlock(options)};
274  BOOST_REQUIRE(block_template);
275  CBlock block{block_template->getBlock()};
276 
277  // block sigops > limit: 1000 CHECKMULTISIG + 1
278  tx.vin.resize(1);
279  // NOTE: OP_NOP is used to force 20 SigOps for the CHECKMULTISIG
280  tx.vin[0].scriptSig = CScript() << OP_0 << OP_0 << OP_0 << OP_NOP << OP_CHECKMULTISIG << OP_1;
281  tx.vin[0].prevout.hash = txFirst[0]->GetHash();
282  tx.vin[0].prevout.n = 0;
283  tx.vout.resize(1);
284  tx.vout[0].nValue = BLOCKSUBSIDY;
285  for (unsigned int i = 0; i < 1001; ++i) {
286  tx.vout[0].nValue -= LOWFEE;
287  hash = tx.GetHash();
288  bool spendsCoinbase = i == 0; // only first tx spends coinbase
289  // If we don't set the # of sig ops in the CTxMemPoolEntry, template creation fails
290  AddToMempool(tx_mempool, entry.Fee(LOWFEE).Time(Now<NodeSeconds>()).SpendsCoinbase(spendsCoinbase).FromTx(tx));
291  tx.vin[0].prevout.hash = hash;
292  }
293 
294  BOOST_CHECK_EXCEPTION(mining->createNewBlock(options), std::runtime_error, HasReason("bad-blk-sigops"));
295  }
296 
297  {
298  CTxMemPool& tx_mempool{MakeMempool()};
299  LOCK(tx_mempool.cs);
300 
301  tx.vin[0].prevout.hash = txFirst[0]->GetHash();
302  tx.vout[0].nValue = BLOCKSUBSIDY;
303  for (unsigned int i = 0; i < 1001; ++i) {
304  tx.vout[0].nValue -= LOWFEE;
305  hash = tx.GetHash();
306  bool spendsCoinbase = i == 0; // only first tx spends coinbase
307  // If we do set the # of sig ops in the CTxMemPoolEntry, template creation passes
308  AddToMempool(tx_mempool, entry.Fee(LOWFEE).Time(Now<NodeSeconds>()).SpendsCoinbase(spendsCoinbase).SigOpsCost(80).FromTx(tx));
309  tx.vin[0].prevout.hash = hash;
310  }
311  BOOST_REQUIRE(mining->createNewBlock(options));
312  }
313 
314  {
315  CTxMemPool& tx_mempool{MakeMempool()};
316  LOCK(tx_mempool.cs);
317 
318  // block size > limit
319  tx.vin[0].scriptSig = CScript();
320  // 18 * (520char + DROP) + OP_1 = 9433 bytes
321  std::vector<unsigned char> vchData(520);
322  for (unsigned int i = 0; i < 18; ++i) {
323  tx.vin[0].scriptSig << vchData << OP_DROP;
324  }
325  tx.vin[0].scriptSig << OP_1;
326  tx.vin[0].prevout.hash = txFirst[0]->GetHash();
327  tx.vout[0].nValue = BLOCKSUBSIDY;
328  for (unsigned int i = 0; i < 128; ++i) {
329  tx.vout[0].nValue -= LOWFEE;
330  hash = tx.GetHash();
331  bool spendsCoinbase = i == 0; // only first tx spends coinbase
332  AddToMempool(tx_mempool, entry.Fee(LOWFEE).Time(Now<NodeSeconds>()).SpendsCoinbase(spendsCoinbase).FromTx(tx));
333  tx.vin[0].prevout.hash = hash;
334  }
335  BOOST_REQUIRE(mining->createNewBlock(options));
336  }
337 
338  {
339  CTxMemPool& tx_mempool{MakeMempool()};
340  LOCK(tx_mempool.cs);
341 
342  // orphan in tx_mempool, template creation fails
343  hash = tx.GetHash();
344  AddToMempool(tx_mempool, entry.Fee(LOWFEE).Time(Now<NodeSeconds>()).FromTx(tx));
345  BOOST_CHECK_EXCEPTION(mining->createNewBlock(options), std::runtime_error, HasReason("bad-txns-inputs-missingorspent"));
346  }
347 
348  {
349  CTxMemPool& tx_mempool{MakeMempool()};
350  LOCK(tx_mempool.cs);
351 
352  // child with higher feerate than parent
353  tx.vin[0].scriptSig = CScript() << OP_1;
354  tx.vin[0].prevout.hash = txFirst[1]->GetHash();
355  tx.vout[0].nValue = BLOCKSUBSIDY - HIGHFEE;
356  hash = tx.GetHash();
357  AddToMempool(tx_mempool, entry.Fee(HIGHFEE).Time(Now<NodeSeconds>()).SpendsCoinbase(true).FromTx(tx));
358  tx.vin[0].prevout.hash = hash;
359  tx.vin.resize(2);
360  tx.vin[1].scriptSig = CScript() << OP_1;
361  tx.vin[1].prevout.hash = txFirst[0]->GetHash();
362  tx.vin[1].prevout.n = 0;
363  tx.vout[0].nValue = tx.vout[0].nValue + BLOCKSUBSIDY - HIGHERFEE; // First txn output + fresh coinbase - new txn fee
364  hash = tx.GetHash();
365  AddToMempool(tx_mempool, entry.Fee(HIGHERFEE).Time(Now<NodeSeconds>()).SpendsCoinbase(true).FromTx(tx));
366  BOOST_REQUIRE(mining->createNewBlock(options));
367  }
368 
369  {
370  CTxMemPool& tx_mempool{MakeMempool()};
371  LOCK(tx_mempool.cs);
372 
373  // coinbase in tx_mempool, template creation fails
374  tx.vin.resize(1);
375  tx.vin[0].prevout.SetNull();
376  tx.vin[0].scriptSig = CScript() << OP_0 << OP_1;
377  tx.vout[0].nValue = 0;
378  hash = tx.GetHash();
379  // give it a fee so it'll get mined
380  AddToMempool(tx_mempool, entry.Fee(LOWFEE).Time(Now<NodeSeconds>()).SpendsCoinbase(false).FromTx(tx));
381  // Should throw bad-cb-multiple
382  BOOST_CHECK_EXCEPTION(mining->createNewBlock(options), std::runtime_error, HasReason("bad-cb-multiple"));
383  }
384 
385  {
386  CTxMemPool& tx_mempool{MakeMempool()};
387  LOCK(tx_mempool.cs);
388 
389  // double spend txn pair in tx_mempool, template creation fails
390  tx.vin[0].prevout.hash = txFirst[0]->GetHash();
391  tx.vin[0].scriptSig = CScript() << OP_1;
392  tx.vout[0].nValue = BLOCKSUBSIDY - HIGHFEE;
393  tx.vout[0].scriptPubKey = CScript() << OP_1;
394  hash = tx.GetHash();
395  AddToMempool(tx_mempool, entry.Fee(HIGHFEE).Time(Now<NodeSeconds>()).SpendsCoinbase(true).FromTx(tx));
396  tx.vout[0].scriptPubKey = CScript() << OP_2;
397  hash = tx.GetHash();
398  AddToMempool(tx_mempool, entry.Fee(HIGHFEE).Time(Now<NodeSeconds>()).SpendsCoinbase(true).FromTx(tx));
399  BOOST_CHECK_EXCEPTION(mining->createNewBlock(options), std::runtime_error, HasReason("bad-txns-inputs-missingorspent"));
400  }
401 
402  {
403  CTxMemPool& tx_mempool{MakeMempool()};
404  LOCK(tx_mempool.cs);
405 
406  // subsidy changing
407  int nHeight = m_node.chainman->ActiveChain().Height();
408  // Create an actual 209999-long block chain (without valid blocks).
409  while (m_node.chainman->ActiveChain().Tip()->nHeight < 209999) {
410  CBlockIndex* prev = m_node.chainman->ActiveChain().Tip();
411  CBlockIndex* next = new CBlockIndex();
412  next->phashBlock = new uint256(m_rng.rand256());
413  m_node.chainman->ActiveChainstate().CoinsTip().SetBestBlock(next->GetBlockHash());
414  next->pprev = prev;
415  next->nHeight = prev->nHeight + 1;
416  next->BuildSkip();
417  m_node.chainman->ActiveChain().SetTip(*next);
418  }
419  BOOST_REQUIRE(mining->createNewBlock(options));
420  // Extend to a 210000-long block chain.
421  while (m_node.chainman->ActiveChain().Tip()->nHeight < 210000) {
422  CBlockIndex* prev = m_node.chainman->ActiveChain().Tip();
423  CBlockIndex* next = new CBlockIndex();
424  next->phashBlock = new uint256(m_rng.rand256());
425  m_node.chainman->ActiveChainstate().CoinsTip().SetBestBlock(next->GetBlockHash());
426  next->pprev = prev;
427  next->nHeight = prev->nHeight + 1;
428  next->BuildSkip();
429  m_node.chainman->ActiveChain().SetTip(*next);
430  }
431  BOOST_REQUIRE(mining->createNewBlock(options));
432 
433  // invalid p2sh txn in tx_mempool, template creation fails
434  tx.vin[0].prevout.hash = txFirst[0]->GetHash();
435  tx.vin[0].prevout.n = 0;
436  tx.vin[0].scriptSig = CScript() << OP_1;
437  tx.vout[0].nValue = BLOCKSUBSIDY - LOWFEE;
438  CScript script = CScript() << OP_0;
439  tx.vout[0].scriptPubKey = GetScriptForDestination(ScriptHash(script));
440  hash = tx.GetHash();
441  AddToMempool(tx_mempool, entry.Fee(LOWFEE).Time(Now<NodeSeconds>()).SpendsCoinbase(true).FromTx(tx));
442  tx.vin[0].prevout.hash = hash;
443  tx.vin[0].scriptSig = CScript() << std::vector<unsigned char>(script.begin(), script.end());
444  tx.vout[0].nValue -= LOWFEE;
445  hash = tx.GetHash();
446  AddToMempool(tx_mempool, entry.Fee(LOWFEE).Time(Now<NodeSeconds>()).SpendsCoinbase(false).FromTx(tx));
447  BOOST_CHECK_EXCEPTION(mining->createNewBlock(options), std::runtime_error, HasReason("mandatory-script-verify-flag-failed"));
448 
449  // Delete the dummy blocks again.
450  while (m_node.chainman->ActiveChain().Tip()->nHeight > nHeight) {
451  CBlockIndex* del = m_node.chainman->ActiveChain().Tip();
452  m_node.chainman->ActiveChain().SetTip(*Assert(del->pprev));
453  m_node.chainman->ActiveChainstate().CoinsTip().SetBestBlock(del->pprev->GetBlockHash());
454  delete del->phashBlock;
455  delete del;
456  }
457  }
458 
459  CTxMemPool& tx_mempool{MakeMempool()};
460  LOCK(tx_mempool.cs);
461 
462  // non-final txs in mempool
463  SetMockTime(m_node.chainman->ActiveChain().Tip()->GetMedianTimePast() + 1);
464  const int flags{LOCKTIME_VERIFY_SEQUENCE};
465  // height map
466  std::vector<int> prevheights;
467 
468  // relative height locked
469  tx.version = 2;
470  tx.vin.resize(1);
471  prevheights.resize(1);
472  tx.vin[0].prevout.hash = txFirst[0]->GetHash(); // only 1 transaction
473  tx.vin[0].prevout.n = 0;
474  tx.vin[0].scriptSig = CScript() << OP_1;
475  tx.vin[0].nSequence = m_node.chainman->ActiveChain().Tip()->nHeight + 1; // txFirst[0] is the 2nd block
476  prevheights[0] = baseheight + 1;
477  tx.vout.resize(1);
478  tx.vout[0].nValue = BLOCKSUBSIDY-HIGHFEE;
479  tx.vout[0].scriptPubKey = CScript() << OP_1;
480  tx.nLockTime = 0;
481  hash = tx.GetHash();
482  AddToMempool(tx_mempool, entry.Fee(HIGHFEE).Time(Now<NodeSeconds>()).SpendsCoinbase(true).FromTx(tx));
483  BOOST_CHECK(CheckFinalTxAtTip(*Assert(m_node.chainman->ActiveChain().Tip()), CTransaction{tx})); // Locktime passes
484  BOOST_CHECK(!TestSequenceLocks(CTransaction{tx}, tx_mempool)); // Sequence locks fail
485 
486  {
487  CBlockIndex* active_chain_tip = m_node.chainman->ActiveChain().Tip();
488  BOOST_CHECK(SequenceLocks(CTransaction(tx), flags, prevheights, *CreateBlockIndex(active_chain_tip->nHeight + 2, active_chain_tip))); // Sequence locks pass on 2nd block
489  }
490 
491  // relative time locked
492  tx.vin[0].prevout.hash = txFirst[1]->GetHash();
493  tx.vin[0].nSequence = CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG | (((m_node.chainman->ActiveChain().Tip()->GetMedianTimePast()+1-m_node.chainman->ActiveChain()[1]->GetMedianTimePast()) >> CTxIn::SEQUENCE_LOCKTIME_GRANULARITY) + 1); // txFirst[1] is the 3rd block
494  prevheights[0] = baseheight + 2;
495  hash = tx.GetHash();
496  AddToMempool(tx_mempool, entry.Time(Now<NodeSeconds>()).FromTx(tx));
497  BOOST_CHECK(CheckFinalTxAtTip(*Assert(m_node.chainman->ActiveChain().Tip()), CTransaction{tx})); // Locktime passes
498  BOOST_CHECK(!TestSequenceLocks(CTransaction{tx}, tx_mempool)); // Sequence locks fail
499 
500  const int SEQUENCE_LOCK_TIME = 512; // Sequence locks pass 512 seconds later
501  for (int i = 0; i < CBlockIndex::nMedianTimeSpan; ++i)
502  m_node.chainman->ActiveChain().Tip()->GetAncestor(m_node.chainman->ActiveChain().Tip()->nHeight - i)->nTime += SEQUENCE_LOCK_TIME; // Trick the MedianTimePast
503  {
504  CBlockIndex* active_chain_tip = m_node.chainman->ActiveChain().Tip();
505  BOOST_CHECK(SequenceLocks(CTransaction(tx), flags, prevheights, *CreateBlockIndex(active_chain_tip->nHeight + 1, active_chain_tip)));
506  }
507 
508  for (int i = 0; i < CBlockIndex::nMedianTimeSpan; ++i) {
509  CBlockIndex* ancestor{Assert(m_node.chainman->ActiveChain().Tip()->GetAncestor(m_node.chainman->ActiveChain().Tip()->nHeight - i))};
510  ancestor->nTime -= SEQUENCE_LOCK_TIME; // undo tricked MTP
511  }
512 
513  // absolute height locked
514  tx.vin[0].prevout.hash = txFirst[2]->GetHash();
515  tx.vin[0].nSequence = CTxIn::MAX_SEQUENCE_NONFINAL;
516  prevheights[0] = baseheight + 3;
517  tx.nLockTime = m_node.chainman->ActiveChain().Tip()->nHeight + 1;
518  hash = tx.GetHash();
519  AddToMempool(tx_mempool, entry.Time(Now<NodeSeconds>()).FromTx(tx));
520  BOOST_CHECK(!CheckFinalTxAtTip(*Assert(m_node.chainman->ActiveChain().Tip()), CTransaction{tx})); // Locktime fails
521  BOOST_CHECK(TestSequenceLocks(CTransaction{tx}, tx_mempool)); // Sequence locks pass
522  BOOST_CHECK(IsFinalTx(CTransaction(tx), m_node.chainman->ActiveChain().Tip()->nHeight + 2, m_node.chainman->ActiveChain().Tip()->GetMedianTimePast())); // Locktime passes on 2nd block
523 
524  // absolute time locked
525  tx.vin[0].prevout.hash = txFirst[3]->GetHash();
526  tx.nLockTime = m_node.chainman->ActiveChain().Tip()->GetMedianTimePast();
527  prevheights.resize(1);
528  prevheights[0] = baseheight + 4;
529  hash = tx.GetHash();
530  AddToMempool(tx_mempool, entry.Time(Now<NodeSeconds>()).FromTx(tx));
531  BOOST_CHECK(!CheckFinalTxAtTip(*Assert(m_node.chainman->ActiveChain().Tip()), CTransaction{tx})); // Locktime fails
532  BOOST_CHECK(TestSequenceLocks(CTransaction{tx}, tx_mempool)); // Sequence locks pass
533  BOOST_CHECK(IsFinalTx(CTransaction(tx), m_node.chainman->ActiveChain().Tip()->nHeight + 2, m_node.chainman->ActiveChain().Tip()->GetMedianTimePast() + 1)); // Locktime passes 1 second later
534 
535  // mempool-dependent transactions (not added)
536  tx.vin[0].prevout.hash = hash;
537  prevheights[0] = m_node.chainman->ActiveChain().Tip()->nHeight + 1;
538  tx.nLockTime = 0;
539  tx.vin[0].nSequence = 0;
540  BOOST_CHECK(CheckFinalTxAtTip(*Assert(m_node.chainman->ActiveChain().Tip()), CTransaction{tx})); // Locktime passes
541  BOOST_CHECK(TestSequenceLocks(CTransaction{tx}, tx_mempool)); // Sequence locks pass
542  tx.vin[0].nSequence = 1;
543  BOOST_CHECK(!TestSequenceLocks(CTransaction{tx}, tx_mempool)); // Sequence locks fail
544  tx.vin[0].nSequence = CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG;
545  BOOST_CHECK(TestSequenceLocks(CTransaction{tx}, tx_mempool)); // Sequence locks pass
546  tx.vin[0].nSequence = CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG | 1;
547  BOOST_CHECK(!TestSequenceLocks(CTransaction{tx}, tx_mempool)); // Sequence locks fail
548 
549  auto block_template = mining->createNewBlock(options);
550  BOOST_REQUIRE(block_template);
551 
552  // None of the of the absolute height/time locked tx should have made
553  // it into the template because we still check IsFinalTx in CreateNewBlock,
554  // but relative locked txs will if inconsistently added to mempool.
555  // For now these will still generate a valid template until BIP68 soft fork
556  CBlock block{block_template->getBlock()};
557  BOOST_CHECK_EQUAL(block.vtx.size(), 3U);
558  // However if we advance height by 1 and time by SEQUENCE_LOCK_TIME, all of them should be mined
559  for (int i = 0; i < CBlockIndex::nMedianTimeSpan; ++i) {
560  CBlockIndex* ancestor{Assert(m_node.chainman->ActiveChain().Tip()->GetAncestor(m_node.chainman->ActiveChain().Tip()->nHeight - i))};
561  ancestor->nTime += SEQUENCE_LOCK_TIME; // Trick the MedianTimePast
562  }
563  m_node.chainman->ActiveChain().Tip()->nHeight++;
564  SetMockTime(m_node.chainman->ActiveChain().Tip()->GetMedianTimePast() + 1);
565 
566  block_template = mining->createNewBlock(options);
567  BOOST_REQUIRE(block_template);
568  block = block_template->getBlock();
569  BOOST_CHECK_EQUAL(block.vtx.size(), 5U);
570 }
571 
572 void MinerTestingSetup::TestPrioritisedMining(const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst)
573 {
574  auto mining{MakeMining()};
575  BOOST_REQUIRE(mining);
576 
577  BlockAssembler::Options options;
578  options.coinbase_output_script = scriptPubKey;
579 
580  CTxMemPool& tx_mempool{MakeMempool()};
581  LOCK(tx_mempool.cs);
582 
584 
585  // Test that a tx below min fee but prioritised is included
587  tx.vin.resize(1);
588  tx.vin[0].prevout.hash = txFirst[0]->GetHash();
589  tx.vin[0].prevout.n = 0;
590  tx.vin[0].scriptSig = CScript() << OP_1;
591  tx.vout.resize(1);
592  tx.vout[0].nValue = 5000000000LL; // 0 fee
593  uint256 hashFreePrioritisedTx = tx.GetHash();
594  AddToMempool(tx_mempool, entry.Fee(0).Time(Now<NodeSeconds>()).SpendsCoinbase(true).FromTx(tx));
595  tx_mempool.PrioritiseTransaction(hashFreePrioritisedTx, 5 * COIN);
596 
597  tx.vin[0].prevout.hash = txFirst[1]->GetHash();
598  tx.vin[0].prevout.n = 0;
599  tx.vout[0].nValue = 5000000000LL - 1000;
600  // This tx has a low fee: 1000 satoshis
601  Txid hashParentTx = tx.GetHash(); // save this txid for later use
602  AddToMempool(tx_mempool, entry.Fee(1000).Time(Now<NodeSeconds>()).SpendsCoinbase(true).FromTx(tx));
603 
604  // This tx has a medium fee: 10000 satoshis
605  tx.vin[0].prevout.hash = txFirst[2]->GetHash();
606  tx.vout[0].nValue = 5000000000LL - 10000;
607  Txid hashMediumFeeTx = tx.GetHash();
608  AddToMempool(tx_mempool, entry.Fee(10000).Time(Now<NodeSeconds>()).SpendsCoinbase(true).FromTx(tx));
609  tx_mempool.PrioritiseTransaction(hashMediumFeeTx, -5 * COIN);
610 
611  // This tx also has a low fee, but is prioritised
612  tx.vin[0].prevout.hash = hashParentTx;
613  tx.vout[0].nValue = 5000000000LL - 1000 - 1000; // 1000 satoshi fee
614  Txid hashPrioritsedChild = tx.GetHash();
615  AddToMempool(tx_mempool, entry.Fee(1000).Time(Now<NodeSeconds>()).SpendsCoinbase(false).FromTx(tx));
616  tx_mempool.PrioritiseTransaction(hashPrioritsedChild, 2 * COIN);
617 
618  // Test that transaction selection properly updates ancestor fee calculations as prioritised
619  // parents get included in a block. Create a transaction with two prioritised ancestors, each
620  // included by itself: FreeParent <- FreeChild <- FreeGrandchild.
621  // When FreeParent is added, a modified entry will be created for FreeChild + FreeGrandchild
622  // FreeParent's prioritisation should not be included in that entry.
623  // When FreeChild is included, FreeChild's prioritisation should also not be included.
624  tx.vin[0].prevout.hash = txFirst[3]->GetHash();
625  tx.vout[0].nValue = 5000000000LL; // 0 fee
626  Txid hashFreeParent = tx.GetHash();
627  AddToMempool(tx_mempool, entry.Fee(0).SpendsCoinbase(true).FromTx(tx));
628  tx_mempool.PrioritiseTransaction(hashFreeParent, 10 * COIN);
629 
630  tx.vin[0].prevout.hash = hashFreeParent;
631  tx.vout[0].nValue = 5000000000LL; // 0 fee
632  Txid hashFreeChild = tx.GetHash();
633  AddToMempool(tx_mempool, entry.Fee(0).SpendsCoinbase(false).FromTx(tx));
634  tx_mempool.PrioritiseTransaction(hashFreeChild, 1 * COIN);
635 
636  tx.vin[0].prevout.hash = hashFreeChild;
637  tx.vout[0].nValue = 5000000000LL; // 0 fee
638  Txid hashFreeGrandchild = tx.GetHash();
639  AddToMempool(tx_mempool, entry.Fee(0).SpendsCoinbase(false).FromTx(tx));
640 
641  auto block_template = mining->createNewBlock(options);
642  BOOST_REQUIRE(block_template);
643  CBlock block{block_template->getBlock()};
644  BOOST_REQUIRE_EQUAL(block.vtx.size(), 6U);
645  BOOST_CHECK(block.vtx[1]->GetHash() == hashFreeParent);
646  BOOST_CHECK(block.vtx[2]->GetHash() == hashFreePrioritisedTx);
647  BOOST_CHECK(block.vtx[3]->GetHash() == hashParentTx);
648  BOOST_CHECK(block.vtx[4]->GetHash() == hashPrioritsedChild);
649  BOOST_CHECK(block.vtx[5]->GetHash() == hashFreeChild);
650  for (size_t i=0; i<block.vtx.size(); ++i) {
651  // The FreeParent and FreeChild's prioritisations should not impact the child.
652  BOOST_CHECK(block.vtx[i]->GetHash() != hashFreeGrandchild);
653  // De-prioritised transaction should not be included.
654  BOOST_CHECK(block.vtx[i]->GetHash() != hashMediumFeeTx);
655  }
656 }
657 
658 // NOTE: These tests rely on CreateNewBlock doing its own self-validation!
659 BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
660 {
661  auto mining{MakeMining()};
662  BOOST_REQUIRE(mining);
663 
664  // Note that by default, these tests run with size accounting enabled.
665  CScript scriptPubKey = CScript() << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"_hex << OP_CHECKSIG;
666  BlockAssembler::Options options;
667  options.coinbase_output_script = scriptPubKey;
668  std::unique_ptr<BlockTemplate> block_template;
669 
670  // We can't make transactions until we have inputs
671  // Therefore, load 110 blocks :)
672  static_assert(std::size(BLOCKINFO) == 110, "Should have 110 blocks to import");
673  int baseheight = 0;
674  std::vector<CTransactionRef> txFirst;
675  for (const auto& bi : BLOCKINFO) {
676  const int current_height{mining->getTip()->height};
677 
678  // Simple block creation, nothing special yet:
679  block_template = mining->createNewBlock(options);
680  BOOST_REQUIRE(block_template);
681 
682  CBlock block{block_template->getBlock()};
683  CMutableTransaction txCoinbase(*block.vtx[0]);
684  {
685  LOCK(cs_main);
686  block.nVersion = VERSIONBITS_TOP_BITS;
687  block.nTime = Assert(m_node.chainman)->ActiveChain().Tip()->GetMedianTimePast()+1;
688  txCoinbase.version = 1;
689  txCoinbase.vin[0].scriptSig = CScript{} << (current_height + 1) << bi.extranonce;
690  txCoinbase.vout.resize(1); // Ignore the (optional) segwit commitment added by CreateNewBlock (as the hardcoded nonces don't account for this)
691  txCoinbase.vout[0].scriptPubKey = CScript();
692  block.vtx[0] = MakeTransactionRef(txCoinbase);
693  if (txFirst.size() == 0)
694  baseheight = current_height;
695  if (txFirst.size() < 4)
696  txFirst.push_back(block.vtx[0]);
697  block.hashMerkleRoot = BlockMerkleRoot(block);
698  block.nNonce = bi.nonce;
699  }
700  std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(block);
701  // Alternate calls between Chainman's ProcessNewBlock and submitSolution
702  // via the Mining interface. The former is used by net_processing as well
703  // as the submitblock RPC.
704  if (current_height % 2 == 0) {
705  BOOST_REQUIRE(Assert(m_node.chainman)->ProcessNewBlock(shared_pblock, /*force_processing=*/true, /*min_pow_checked=*/true, nullptr));
706  } else {
707  BOOST_REQUIRE(block_template->submitSolution(block.nVersion, block.nTime, block.nNonce, MakeTransactionRef(txCoinbase)));
708  }
709  {
710  LOCK(cs_main);
711  // The above calls don't guarantee the tip is actually updated, so
712  // we explicitly check this.
713  auto maybe_new_tip{Assert(m_node.chainman)->ActiveChain().Tip()};
714  BOOST_REQUIRE_EQUAL(maybe_new_tip->GetBlockHash(), block.GetHash());
715  }
716  // This just adds coverage
717  mining->waitTipChanged(block.hashPrevBlock);
718  }
719 
720  LOCK(cs_main);
721 
722  TestBasicMining(scriptPubKey, txFirst, baseheight);
723 
724  m_node.chainman->ActiveChain().Tip()->nHeight--;
725  SetMockTime(0);
726 
727  TestPackageSelection(scriptPubKey, txFirst);
728 
729  m_node.chainman->ActiveChain().Tip()->nHeight--;
730  SetMockTime(0);
731 
732  TestPrioritisedMining(scriptPubKey, txFirst);
733 }
734 
static constexpr unsigned int LOCKTIME_VERIFY_SEQUENCE
Flags for nSequence and nLockTime locks.
Definition: consensus.h:28
Block template interface.
Definition: mining.h:31
Generate a new block, without valid proof-of-work.
Definition: miner.h:143
CBlockIndex * pprev
pointer to the index of the predecessor of this block
Definition: chain.h:147
Definition: txmempool.h:19
unsigned int nonce
Definition: miner_tests.cpp:75
Bilingual messages:
Definition: translation.h:24
TestMemPoolEntryHelper & Fee(CAmount _fee)
Definition: txmempool.h:33
Definition: block.h:68
node::NodeContext m_node
Definition: bitcoin-gui.cpp:42
bool empty() const
Definition: translation.h:35
std::vector< CTxIn > vin
Definition: transaction.h:379
bool SequenceLocks(const CTransaction &tx, int flags, std::vector< int > &prevHeights, const CBlockIndex &block)
Check if transaction is final per BIP 68 sequence numbers and can be included in a block...
Definition: tx_verify.cpp:107
size_t GetSerializeSize(const T &t)
Definition: serialize.h:1103
bool CheckFinalTxAtTip(const CBlockIndex &active_chain_tip, const CTransaction &tx)
Definition: validation.cpp:146
void TestPackageSelection(const CScript &scriptPubKey, const std::vector< CTransactionRef > &txFirst) EXCLUSIVE_LOCKS_REQUIRED(void TestBasicMining(const CScript &scriptPubKey, const std::vector< CTransactionRef > &txFirst, int baseheight) EXCLUSIVE_LOCKS_REQUIRED(void TestPrioritisedMining(const CScript &scriptPubKey, const std::vector< CTransactionRef > &txFirst) EXCLUSIVE_LOCKS_REQUIRED(bool TestSequenceLocks(const CTransaction &tx, CTxMemPool &tx_mempool) EXCLUSIVE_LOCKS_REQUIRED(
Definition: miner_tests.cpp:44
static CFeeRate blockMinFeeRate
Definition: miner_tests.cpp:71
static const int SEQUENCE_LOCKTIME_GRANULARITY
In order to use the same number of bits to encode roughly the same wall-clock duration, and because blocks are naturally limited to occur every 600s on average, the minimum granularity for time-based relative lock-time is fixed at 512 seconds.
Definition: transaction.h:119
CTxMemPoolEntry FromTx(const CMutableTransaction &tx) const
Definition: txmempool.cpp:33
BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
Definition: script.h:76
void BulkTransaction(CMutableTransaction &tx, int32_t target_weight)
Definition: script.h:102
std::unique_ptr< CTxMemPool > mempool
Definition: context.h:68
Definition: script.h:83
static std::unique_ptr< CBlockIndex > CreateBlockIndex(int nHeight, CBlockIndex *active_chain_tip) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: miner_tests.cpp:96
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
TestMemPoolEntryHelper & SpendsCoinbase(bool _flag)
Definition: txmempool.h:37
static constexpr int nMedianTimeSpan
Definition: chain.h:276
uint256 GetBlockHash() const
Definition: chain.h:243
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
Definition: time.cpp:40
static constexpr struct @14 BLOCKINFO[]
Interface giving clients (RPC, Stratum v2 Template Provider in the future) ability to create block te...
Definition: mining.h:63
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
#define LOCK(cs)
Definition: sync.h:257
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EXCEPTION predicates to check the specific validation error.
Definition: setup_common.h:295
uint256 BlockMerkleRoot(const CBlock &block, bool *mutated)
Definition: merkle.cpp:66
void BuildSkip()
Build the skiplist pointer for this entry.
Definition: chain.cpp:125
""_hex is a compile-time user-defined literal returning a std::array<std::byte>, equivalent to ParseH...
Definition: strencodings.h:427
Txid GetHash() const
Compute the hash of this CMutableTransaction.
Definition: transaction.cpp:69
AddToMempool(pool, CTxMemPoolEntry(tx, fee, nTime, nHeight, sequence, spendsCoinbase, sigOpCost, lp))
static const uint32_t SEQUENCE_LOCKTIME_TYPE_FLAG
If CTxIn::nSequence encodes a relative lock-time and this flag is set, the relative lock-time has uni...
Definition: transaction.h:104
std::vector< CTxOut > vout
Definition: transaction.h:380
bool CheckFinalTxAtTip(const CBlockIndex &active_chain_tip, const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(std::optional< LockPoints > CalculateLockPointsAtTip(CBlockIndex *tip, const CCoinsView &coins_view, const CTransaction &tx)
Check if transaction will be final in the next block to be created.
Definition: validation.h:309
unsigned int nHeight
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
static CTransactionRef MakeTransactionRef(Tx &&txIn)
Definition: transaction.h:424
int flags
Definition: bitcoin-tx.cpp:536
unsigned int nHeight
Definition: txmempool.h:23
std::unique_ptr< Mining > MakeMining()
Definition: miner_tests.cpp:62
256-bit opaque blob.
Definition: uint256.h:201
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
Data structure storing a fee and size, ordered by increasing fee/size.
Definition: feefrac.h:38
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:303
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:18
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:140
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:414
TestMemPoolEntryHelper & Time(NodeSeconds tp)
Definition: txmempool.h:34
static const int32_t VERSIONBITS_TOP_BITS
What bits to set in version for versionbits blocks.
Definition: versionbits.h:16
CAmount nFee
Definition: txmempool.h:21
TestMemPoolEntryHelper & SigOpsCost(unsigned int _sigopsCost)
Definition: txmempool.h:38
std::unique_ptr< Mining > MakeMining(node::NodeContext &node)
Return implementation of Mining interface.
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
Definition: feerate.h:32
bool spendsCoinbase
CAmount GetFee(uint32_t num_bytes) const
Return the fee in satoshis for the given vsize in vbytes.
Definition: feerate.cpp:23
static constexpr unsigned int DEFAULT_BLOCK_MIN_TX_FEE
Default for -blockmintxfee, which sets the minimum feerate for a transaction in blocks created by min...
Definition: policy.h:32
A mutable version of CTransaction.
Definition: transaction.h:377
Definition: script.h:85
unsigned char extranonce
Definition: miner_tests.cpp:74
bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
Check if transaction is final and can be included in a block with the specified height and time...
Definition: tx_verify.cpp:17
bool CheckSequenceLocksAtTip(CBlockIndex *tip, const LockPoints &lock_points)
Check if transaction will be BIP68 final in the next block to be created on top of tip...
Definition: validation.cpp:245
static constexpr CAmount CENT
Definition: setup_common.h:47
static const uint32_t MAX_SEQUENCE_NONFINAL
This is the maximum sequence number that enables both nLockTime and OP_CHECKLOCKTIMEVERIFY (BIP 65)...
Definition: transaction.h:87
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:295
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:153
Removed for replacement.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
Definition: cs_main.cpp:8
CCoinsView that brings transactions from a mempool into view.
Definition: txmempool.h:924
std::unique_ptr< ChainstateManager > chainman
Definition: context.h:72
Testing setup that configures a complete environment.
Definition: setup_common.h:121
#define Assert(val)
Identity function.
Definition: check.h:85
static constexpr TransactionSerParams TX_WITH_WITNESS
Definition: transaction.h:195
#define BOOST_CHECK(expr)
Definition: object.cpp:17
CTxMemPool::Options MemPoolOptionsForTest(const NodeContext &node)
Definition: txmempool.cpp:20
static constexpr CAmount COIN
The amount of satoshis in one BTC.
Definition: amount.h:15
const uint256 * phashBlock
pointer to the hash of the block, if any. Memory is owned by this CBlockIndex
Definition: chain.h:144