39#include <validation.h>
40#include <versionbits.h>
42#include <boost/test/unit_test.hpp>
84 opts.limits.cluster_size_vbytes = 1'200'000;
104}
BLOCKINFO[]{{0, 3552706918}, {500, 37506755}, {1000, 948987788}, {400, 524762339}, {800, 258510074}, {300, 102309278},
105 {1300, 54365202}, {600, 1107740426}, {1000, 203094491}, {900, 391178848}, {800, 381177271}, {600, 87188412},
106 {0, 66522866}, {800, 874942736}, {1000, 89200838}, {400, 312638088}, {400, 66263693}, {500, 924648304},
107 {400, 369913599}, {500, 47630099}, {500, 115045364}, {100, 277026602}, {1100, 809621409}, {700, 155345322},
108 {800, 943579953}, {400, 28200730}, {900, 77200495}, {0, 105935488}, {400, 698721821}, {500, 111098863},
109 {1300, 445389594}, {500, 621849894}, {1400, 56010046}, {1100, 370669776}, {1200, 380301940}, {1200, 110654905},
110 {400, 213771024}, {1500, 120014726}, {1200, 835019014}, {1500, 624817237}, {900, 1404297}, {400, 189414558},
111 {400, 293178348}, {1100, 15393789}, {600, 396764180}, {800, 1387046371}, {800, 199368303}, {700, 111496662},
112 {100, 129759616}, {200, 536577982}, {500, 125881300}, {500, 101053391}, {1200, 471590548}, {900, 86957729},
113 {1200, 179604104}, {600, 68658642}, {1000, 203295701}, {500, 139615361}, {900, 233693412}, {300, 153225163},
114 {0, 27616254}, {1200, 9856191}, {100, 220392722}, {200, 66257599}, {1100, 145489641}, {1300, 37859442},
115 {400, 5816075}, {1200, 215752117}, {1400, 32361482}, {1400, 6529223}, {500, 143332977}, {800, 878392},
116 {700, 159290408}, {400, 123197595}, {700, 43988693}, {300, 304224916}, {700, 214771621}, {1100, 274148273},
117 {400, 285632418}, {1100, 923451065}, {600, 12818092}, {1200, 736282054}, {1000, 246683167}, {600, 92950402},
118 {1400, 29223405}, {1000, 841327192}, {700, 174301283}, {1400, 214009854}, {1000, 6989517}, {1200, 278226956},
119 {700, 540219613}, {400, 93663104}, {1100, 152345635}, {1500, 464194499}, {1300, 333850111}, {600, 258311263},
120 {600, 90173162}, {1000, 33590797}, {1500, 332866027}, {100, 204704427}, {1000, 463153545}, {800, 303244785},
121 {600, 88096214}, {0, 137477892}, {1200, 195514506}, {300, 704114595}, {900, 292087369}, {1400, 758684870},
122 {1300, 163493028}, {1200, 53151293}};
126 auto index{std::make_unique<CBlockIndex>()};
147void MinerTestingSetup::TestPackageSelection(
const CScript& scriptPubKey,
const std::vector<CTransactionRef>&
txFirst)
260 for (
size_t i=0; i<block.vtx.size(); ++i) {
314 for (
size_t i=0; i<block.vtx.size(); ++i) {
344 std::vector<CTransactionRef>
ret;
360 for (
unsigned int i = 0; i < 50; ++i) {
366void MinerTestingSetup::TestSigOpsAdjustedWeightChunkLimit(
const CScript& scriptPubKey,
const std::vector<CTransactionRef>&
txFirst)
384 .coinbase_output_script = scriptPubKey,
386 const CBlock block{
mining->createNewBlock(options,
false)->getBlock()};
388 BOOST_CHECK(block.vtx[1]->GetHash() == tx.GetHash());
391void MinerTestingSetup::TestBasicMining(
const CScript& scriptPubKey,
const std::vector<CTransactionRef>&
txFirst,
int baseheight)
425 for (
auto&
t :
txs) {
452 for (
auto&
t :
txs) {
472 std::vector<unsigned char> vchData(520);
473 for (
unsigned int i = 0; i < 18; ++i) {
479 tx.
vin[0].prevout.hash =
txFirst[0]->GetHash();
480 tx.
vin[0].prevout.n = 0;
482 for (
unsigned int i = 0; i < 63; ++i) {
488 tx.
vin[0].prevout.hash = hash;
509 tx.
vin[0].prevout.hash =
txFirst[1]->GetHash();
513 tx.
vin[0].prevout.hash = hash;
516 tx.
vin[1].prevout.hash =
txFirst[0]->GetHash();
517 tx.
vin[1].prevout.n = 0;
530 tx.
vin[0].prevout.SetNull();
532 tx.
vout[0].nValue = 0;
545 tx.
vin[0].prevout.hash =
txFirst[0]->GetHash();
546 tx.
vin[0].prevout.n = 0;
590 tx.
vin[0].prevout.hash =
txFirst[0]->GetHash();
591 tx.
vin[0].prevout.n = 0;
598 tx.
vin[0].prevout.hash = hash;
609 m_node.
chainman->ActiveChainstate().CoinsTip().SetBestBlock(
del->pprev->GetBlockHash());
610 delete del->phashBlock;
628 tx.
vin[0].prevout.hash =
txFirst[0]->GetHash();
629 tx.
vin[0].prevout.n = 0;
648 tx.
vin[0].prevout.hash =
txFirst[1]->GetHash();
670 tx.
vin[0].prevout.hash =
txFirst[2]->GetHash();
685 tx.
vin[0].prevout.hash =
txFirst[3]->GetHash();
696 tx.
vin[0].prevout.hash = hash;
699 tx.
vin[0].nSequence = 0;
702 tx.
vin[0].nSequence = 1;
732void MinerTestingSetup::TestPrioritisedMining(
const CScript& scriptPubKey,
const std::vector<CTransactionRef>&
txFirst)
798 for (
size_t i=0; i<block.vtx.size(); ++i) {
809 auto mining{MakeMining()};
813 CScript scriptPubKey =
CScript() <<
"04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"_hex <<
OP_CHECKSIG;
826 HasReason(
"block_reserved_weight (8000) exceeds block_max_weight (7999)"));
865 static_assert(std::size(
BLOCKINFO) == 110,
"Should have 110 blocks to import");
867 std::vector<CTransactionRef>
txFirst;
895 txFirst.push_back(block.vtx[0]);
897 block.nNonce =
bi.nonce;
901 std::string reason{
"stale reason"};
902 std::string
debug{
"stale debug"};
908 reason =
"stale reason";
909 debug =
"stale debug";
914 reason =
"stale reason";
915 debug =
"stale debug";
935 mining->waitTipChanged(block.hashPrevBlock);
959 auto block_template = block_template_manager.CreateNewTemplate(options);
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
int64_t CAmount
Amount in satoshis (Can be negative)
constexpr CAmount COIN
The amount of satoshis in one BTC.
TryAddToMempool(pool, CTxMemPoolEntry(tx, fee, 0, 1, 0, false, 4, lp))
#define Assert(val)
Identity function.
The block chain is a tree shaped structure starting with the genesis block at the root,...
CBlockIndex * pprev
pointer to the index of the predecessor of this block
void BuildSkip()
Build the skiplist pointer for this entry.
uint256 GetBlockHash() const
int nHeight
height of the entry in the chain. The genesis block has height 0
static constexpr int nMedianTimeSpan
const uint256 * phashBlock
pointer to the hash of the block, if any. Memory is owned by this CBlockIndex
CCoinsView that brings transactions from a mempool into view.
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
CAmount GetFee(int32_t virtual_bytes) const
Return the fee in satoshis for the given vsize in vbytes. (Rounds up)
An outpoint - a combination of a transaction hash and an index n into its vout.
Serialized script, used inside transaction inputs and outputs.
The basic transaction that is broadcasted on the network and contained in blocks.
An input of a transaction.
static constexpr int SEQUENCE_LOCKTIME_GRANULARITY
In order to use the same number of bits to encode roughly the same wall-clock duration,...
static constexpr 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...
static constexpr uint32_t MAX_SEQUENCE_NONFINAL
This is the maximum sequence number that enables both nLockTime and OP_CHECKLOCKTIMEVERIFY (BIP 65).
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
An output of a transaction.
Helper to initialize the global NodeClock, let a duration elapse, and reset it after use in a test.
void set(NodeSeconds t)
Set mocktime.
BOOST_CHECK_EXCEPTION predicates to check the specific validation error.
Block template interface.
Interface giving clients (RPC, Stratum v2 Template Provider in the future) ability to create block te...
static transaction_identifier FromUint256(const uint256 &id)
static const uint256 ZERO
uint32_t current_height
Current height in the simulation.
uint256 BlockMerkleRoot(const CBlock &block, bool *mutated)
constexpr unsigned int LOCKTIME_VERIFY_SEQUENCE
Flags for nSequence and nLockTime locks.
constexpr int64_t MAX_BLOCK_SIGOPS_COST
The maximum allowed number of signature check operations in a block (network rule)
constexpr int WITNESS_SCALE_FACTOR
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EXCEPTION(HTTPHeaders{}.Read(reader), std::runtime_error, HasReason{"Empty HTTP header name"})
@ REPLACED
Removed for replacement.
std::vector< CTransactionRef > CreateBigSigOpsCluster(const CTransactionRef &first_tx)
BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
static CMutableTransaction CreateBigSigOpsTx(const COutPoint &input, unsigned int num_outputs)
static std::unique_ptr< CBlockIndex > CreateBlockIndex(int nHeight, CBlockIndex *active_chain_tip) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
static CMutableTransaction MakeTx(const COutPoint &prevout, CAmount value, const CScript &script_pub_key={})
static constexpr struct @14 BLOCKINFO[]
static CFeeRate blockMinFeeRate
Simple data definitions used by mining IPC clients.
std::unique_ptr< Mining > MakeMining(const node::NodeContext &node, bool wait_loaded=true)
Return implementation of Mining interface.
""_hex is a compile-time user-defined literal returning a std::array<std::byte>, equivalent to ParseH...
#define BOOST_CHECK_THROW(stmt, excMatch)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
constexpr unsigned int DEFAULT_BLOCK_MIN_TX_FEE
Default for -blockmintxfee, which sets the minimum feerate for a transaction in blocks created by min...
constexpr unsigned int DEFAULT_BLOCK_RESERVED_WEIGHT
Default for -blockreservedweight.
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params ¶ms)
Check whether a block hash satisfies the proof-of-work requirement specified by nBits.
constexpr TransactionSerParams TX_WITH_WITNESS
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
uint64_t GetSerializeSize(const T &t)
Utilities for converting data from/to strings.
A mutable version of CTransaction.
std::vector< CTxOut > vout
Txid GetHash() const
Compute the hash of this CMutableTransaction.
void CreateBlockTemplateManager()
Create the block template manager.
Data structure storing a fee and size.
TestMemPoolEntryHelper & SigOpsCost(unsigned int _sigopsCost)
TestMemPoolEntryHelper & Time(NodeSeconds tp)
CTxMemPoolEntry FromTx(const CMutableTransaction &tx) const
TestMemPoolEntryHelper & SpendsCoinbase(bool _flag)
TestMemPoolEntryHelper & Fee(CAmount _fee)
Testing setup that configures a complete environment.
std::unique_ptr< Mining > MakeMining()
CTxMemPool & MakeMempool()
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(void TestSigOpsAdjustedWeightChunkLimit(const CScript &scriptPubKey, const std::vector< CTransactionRef > &txFirst) EXCLUSIVE_LOCKS_REQUIRED(bool TestSequenceLocks(const CTransaction &tx, CTxMemPool &tx_mempool) EXCLUSIVE_LOCKS_REQUIRED(
Block template creation options.
CScript coinbase_output_script
Script to put in the coinbase transaction.
bool use_mempool
Set false to omit mempool transactions.
std::optional< uint64_t > block_max_weight
Maximum block weight, defaults to -maxblockweight.
std::unique_ptr< CTxMemPool > mempool
std::unique_ptr< BlockTemplateManager > block_template_manager
Must be destroyed before its dependencies (holds references to them).
std::unique_ptr< ChainstateManager > chainman
CTxMemPool::Options MemPoolOptionsForTest(const NodeContext &node)
#define EXCLUSIVE_LOCKS_REQUIRED(...)
void BulkTransaction(CMutableTransaction &tx, int32_t target_weight)
unsigned int GetLegacySigOpCount(const CTransaction &tx)
Auxiliary functions for transaction validation (ideally should not be exposed)
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.
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.
std::chrono::duration< double, std::chrono::milliseconds::period > MillisecondsDouble
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
bool CheckFinalTxAtTip(const CBlockIndex &active_chain_tip, const CTransaction &tx)
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.
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.
constexpr int32_t VERSIONBITS_TOP_BITS
What bits to set in version for versionbits blocks.