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