24std::deque<COutPoint> g_available_coins;
25void initialize_miner()
27 static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
28 g_setup = testing_setup.get();
29 for (uint32_t i = 0; i < uint32_t{100}; ++i) {
42 std::vector<COutPoint> outpoints;
43 std::deque<COutPoint> available_coins = g_available_coins;
49 const size_t num_inputs = fuzzed_data_provider.ConsumeIntegralInRange<
size_t>(1, available_coins.size());
50 const size_t num_outputs = fuzzed_data_provider.ConsumeIntegralInRange<
size_t>(1, 50);
51 for (
size_t n{0}; n < num_inputs; ++n) {
52 auto prevout = available_coins.front();
54 available_coins.pop_front();
56 for (uint32_t n{0}; n < num_outputs; ++n) {
66 for (uint32_t n{0}; n < num_outputs; ++n) {
67 if (fuzzed_data_provider.ConsumeBool()) {
68 available_coins.emplace_back(tx->GetHash(), n);
72 if (fuzzed_data_provider.ConsumeBool() && !tx->vout.empty()) {
74 outpoints.emplace_back(tx->GetHash(),
75 (uint32_t)fuzzed_data_provider.ConsumeIntegralInRange<
size_t>(0, tx->vout.size()));
79 auto outpoint = ConsumeDeserializable<COutPoint>(fuzzed_data_provider);
80 if (outpoint.has_value() && std::find(outpoints.begin(), outpoints.end(), *outpoint) == outpoints.end()) {
81 outpoints.push_back(*outpoint);
88 std::optional<CAmount> total_bumpfee;
92 assert(mini_miner.IsReadyToCalculate());
93 const auto bump_fees = mini_miner.CalculateBumpFees(target_feerate);
94 for (
const auto& outpoint : outpoints) {
95 auto it = bump_fees.find(outpoint);
96 assert(it != bump_fees.end());
98 sum_fees += it->second;
100 assert(!mini_miner.IsReadyToCalculate());
104 assert(mini_miner.IsReadyToCalculate());
105 total_bumpfee = mini_miner.CalculateTotalBumpFees(target_feerate);
106 assert(total_bumpfee.has_value());
107 assert(!mini_miner.IsReadyToCalculate());
110 assert (sum_fees >= *total_bumpfee);
122 std::deque<COutPoint> available_coins = g_available_coins;
123 std::vector<CTransactionRef> transactions;
129 assert(!available_coins.empty());
130 const size_t num_inputs = std::min(
size_t{2}, available_coins.size());
131 const size_t num_outputs = fuzzed_data_provider.ConsumeIntegralInRange<
size_t>(2, 5);
132 for (
size_t n{0}; n < num_inputs; ++n) {
133 auto prevout = available_coins.at(0);
135 available_coins.pop_front();
137 for (uint32_t n{0}; n < num_outputs; ++n) {
145 for (uint32_t n{0}; n < num_outputs - 1; ++n) {
146 if (fuzzed_data_provider.ConsumeBool()) {
147 available_coins.emplace_front(tx->GetHash(), n);
149 available_coins.emplace_back(tx->GetHash(), n);
160 transactions.push_back(tx);
162 std::vector<COutPoint> outpoints;
163 for (
const auto& coin : g_available_coins) {
164 if (!pool.GetConflictTx(coin)) outpoints.push_back(coin);
166 for (
const auto& tx : transactions) {
168 for (uint32_t n{0}; n < tx->vout.size(); ++n) {
170 if (!pool.GetConflictTx(coin)) outpoints.push_back(coin);
183 assert(mini_miner.IsReadyToCalculate());
187 const auto blocktemplate{miner.CreateNewBlock()};
188 mini_miner.BuildMockTemplate(target_feerate);
189 assert(!mini_miner.IsReadyToCalculate());
190 auto mock_template_txids = mini_miner.GetMockTemplateTxids();
192 assert(mock_template_txids.count(blocktemplate->block.vtx[0]->GetHash()) == 0);
193 auto [iter, new_entry] = mock_template_txids.emplace(blocktemplate->block.vtx[0]->GetHash());
196 assert(mock_template_txids.size() == blocktemplate->block.vtx.size());
197 for (
const auto& tx : blocktemplate->block.vtx) {
198 assert(mock_template_txids.count(tx->GetHash()));
static constexpr CAmount MAX_MONEY
No amount larger than this (in satoshi) is valid.
bool MoneyRange(const CAmount &nValue)
int64_t CAmount
Amount in satoshis (Can be negative)
#define Assert(val)
Identity function.
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
An outpoint - a combination of a transaction hash and an index n into its vout.
Serialized script, used inside transaction inputs and outputs.
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
static GenTxid Txid(const uint256 &hash)
Generate a new block, without valid proof-of-work.
A minimal version of BlockAssembler, using the same ancestor set scoring algorithm.
static transaction_identifier FromUint256(const uint256 &id)
static const uint256 ZERO
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
AddToMempool(pool, CTxMemPoolEntry(tx, fee, nTime, nHeight, sequence, spendsCoinbase, sigOpCost, lp))
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost, unsigned int bytes_per_sigop)
Compute the virtual transaction size (weight reinterpreted as bytes).
static constexpr unsigned int DEFAULT_BLOCK_MAX_WEIGHT
Default for -blockmaxweight, which controls the range of block weights the mining code will create.
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
A mutable version of CTransaction.
std::vector< CTxOut > vout
CTxMemPoolEntry FromTx(const CMutableTransaction &tx) const
TestMemPoolEntryHelper & Fee(CAmount _fee)
Testing setup that configures a complete environment.
Options struct containing options for constructing a CTxMemPool.
CScript coinbase_output_script
Script to put in the coinbase transaction.
std::unique_ptr< ChainstateManager > chainman
CAmount ConsumeMoney(FuzzedDataProvider &fuzzed_data_provider, const std::optional< CAmount > &max) noexcept
void SeedRandomStateForTest(SeedRand seedtype)
Seed the global RNG state for testing and log the seed value.
@ ZEROS
Seed with a compile time constant of zeros.
static const CScript P2WSH_OP_TRUE