29std::deque<COutPoint> g_available_coins;
30void initialize_miner()
32 static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
33 g_setup = testing_setup.get();
34 for (uint32_t i = 0; i < uint32_t{100}; ++i) {
48 std::vector<COutPoint> outpoints;
49 std::deque<COutPoint> available_coins = g_available_coins;
55 const size_t num_inputs = fuzzed_data_provider.ConsumeIntegralInRange<
size_t>(1, available_coins.size());
56 const size_t num_outputs = fuzzed_data_provider.ConsumeIntegralInRange<
size_t>(1, 50);
57 for (
size_t n{0}; n < num_inputs; ++n) {
58 auto prevout = available_coins.front();
60 available_coins.pop_front();
62 for (uint32_t n{0}; n < num_outputs; ++n) {
72 for (uint32_t n{0}; n < num_outputs; ++n) {
73 if (fuzzed_data_provider.ConsumeBool()) {
74 available_coins.emplace_back(tx->GetHash(), n);
78 if (fuzzed_data_provider.ConsumeBool() && !tx->vout.empty()) {
80 outpoints.emplace_back(tx->GetHash(),
81 (uint32_t)fuzzed_data_provider.ConsumeIntegralInRange<
size_t>(0, tx->vout.size()));
85 auto outpoint = ConsumeDeserializable<COutPoint>(fuzzed_data_provider);
86 if (outpoint.has_value() && std::find(outpoints.begin(), outpoints.end(), *outpoint) == outpoints.end()) {
87 outpoints.push_back(*outpoint);
94 std::optional<CAmount> total_bumpfee;
98 assert(mini_miner.IsReadyToCalculate());
99 const auto bump_fees = mini_miner.CalculateBumpFees(target_feerate);
100 for (
const auto& outpoint : outpoints) {
101 auto it = bump_fees.find(outpoint);
102 assert(it != bump_fees.end());
104 sum_fees += it->second;
106 assert(!mini_miner.IsReadyToCalculate());
110 assert(mini_miner.IsReadyToCalculate());
111 total_bumpfee = mini_miner.CalculateTotalBumpFees(target_feerate);
112 assert(total_bumpfee.has_value());
113 assert(!mini_miner.IsReadyToCalculate());
116 assert (sum_fees >= *total_bumpfee);
129 std::deque<COutPoint> available_coins = g_available_coins;
130 std::vector<CTransactionRef> transactions;
136 assert(!available_coins.empty());
137 const size_t num_inputs = std::min(
size_t{2}, available_coins.size());
138 const size_t num_outputs = fuzzed_data_provider.ConsumeIntegralInRange<
size_t>(2, 5);
139 for (
size_t n{0}; n < num_inputs; ++n) {
140 auto prevout = available_coins.at(0);
142 available_coins.pop_front();
144 for (uint32_t n{0}; n < num_outputs; ++n) {
152 for (uint32_t n{0}; n < num_outputs - 1; ++n) {
153 if (fuzzed_data_provider.ConsumeBool()) {
154 available_coins.emplace_front(tx->GetHash(), n);
156 available_coins.emplace_back(tx->GetHash(), n);
167 transactions.push_back(tx);
169 std::vector<COutPoint> outpoints;
170 for (
const auto& coin : g_available_coins) {
171 if (!pool.GetConflictTx(coin)) outpoints.push_back(coin);
173 for (
const auto& tx : transactions) {
175 for (uint32_t n{0}; n < tx->vout.size(); ++n) {
177 if (!pool.GetConflictTx(coin)) outpoints.push_back(coin);
190 assert(mini_miner.IsReadyToCalculate());
194 const auto blocktemplate{miner.CreateNewBlock()};
195 mini_miner.BuildMockTemplate(target_feerate);
196 assert(!mini_miner.IsReadyToCalculate());
197 auto mock_template_txids = mini_miner.GetMockTemplateTxids();
199 assert(mock_template_txids.count(blocktemplate->block.vtx[0]->GetHash()) == 0);
200 auto [iter, new_entry] = mock_template_txids.emplace(blocktemplate->block.vtx[0]->GetHash());
203 assert(mock_template_txids.size() == blocktemplate->block.vtx.size());
204 for (
const auto& tx : blocktemplate->block.vtx) {
205 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
int64_t ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
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
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.