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