5 #include <chainparams.h> 18 #include <validation.h> 26 .extra_args = {
"-testactivationheight=bip34@2"},
30 test_setup.LoadVerifyActivateChainstate();
31 auto&
node{test_setup.m_node};
32 auto& chainman{*
Assert(test_setup.m_node.chainman)};
35 const auto ActiveHeight = [&]() {
36 LOCK(chainman.GetMutex());
37 return chainman.ActiveHeight();
39 const auto PrepareNextBlock = [&]() {
52 auto current_block = PrepareNextBlock();
54 std::vector<std::pair<COutPoint, CTxOut>> txos;
62 const auto StoreLastTxo = [&]() {
66 const uint32_t i = tx.
vout.size() - 1;
69 if (current_block->vtx.size() == 1 && tx.
vout.at(i).scriptPubKey[0] ==
OP_RETURN) {
71 const uint32_t i = tx.
vout.size() - 2;
76 const auto& txo = txos.at(fuzzed_data_provider.ConsumeIntegralInRange<
size_t>(0, txos.size() - 1));
77 tx.vin.emplace_back(txo.first);
78 tx.vout.emplace_back(txo.second.nValue, txo.second.scriptPubKey);
80 const auto UpdateUtxoStats = [&]() {
81 LOCK(chainman.GetMutex());
82 chainman.ActiveChainstate().ForceFlushStateToDisk();
83 utxo_stats = std::move(
93 assert(ActiveHeight() == 0);
97 int64_t duplicate_coinbase_height = fuzzed_data_provider.ConsumeIntegralInRange(0, 300);
99 const CScript duplicate_coinbase_script =
CScript() << duplicate_coinbase_height <<
OP_0;
101 current_block = PrepareNextBlock();
107 tx.
vin.at(0).scriptSig = duplicate_coinbase_script;
116 assert(ActiveHeight() == 1);
118 current_block = PrepareNextBlock();
126 fuzzed_data_provider, 128 // Append an input-output pair to the last tx in the current block 129 CMutableTransaction tx{*current_block->vtx.back()}; 131 current_block->vtx.back() = MakeTransactionRef(tx); 135 // Append a tx to the list of txs in the current block 136 CMutableTransaction tx{}; 138 current_block->vtx.push_back(MakeTransactionRef(tx)); 142 // Append the current block to the active chain 143 node::RegenerateCommitments(*current_block, chainman); 144 const bool was_valid = !MineBlock(node, current_block).IsNull(); 146 const auto prev_utxo_stats = utxo_stats; 148 if (duplicate_coinbase_height == ActiveHeight()) { 149 // we mined the duplicate coinbase 150 assert(current_block->vtx.at(0)->vin.at(0).scriptSig == duplicate_coinbase_script); 153 circulation += GetBlockSubsidy(ActiveHeight(), Params().GetConsensus()); 159 // utxo stats must not change 160 assert(prev_utxo_stats.hashSerialized == utxo_stats.hashSerialized); 163 current_block = PrepareNextBlock(); Testing setup that performs all steps up until right before ChainstateManager gets initialized...
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams)
std::optional< CAmount > total_amount
The total amount, or nullopt if an overflow occurred calculating it.
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
int64_t CAmount
Amount in satoshis (Can be negative)
const std::vector< CTxOut > vout
uint256 BlockMerkleRoot(const CBlock &block, bool *mutated)
An outpoint - a combination of a transaction hash and an index n into its vout.
std::vector< CTxOut > vout
static CTransactionRef MakeTransactionRef(Tx &&txIn)
COutPoint MineBlock(const NodeContext &node, const CScript &coinbase_scriptPubKey)
Returns the generated coin.
static bool ComputeUTXOStats(CCoinsView *view, CCoinsStats &stats, T hash_obj, const std::function< void()> &interruption_point)
Calculate statistics about the unspent transaction output set.
const CChainParams & Params()
Return the currently selected parameters.
Serialized script, used inside transaction inputs and outputs.
A mutable version of CTransaction.
The basic transaction that is broadcasted on the network and contained in blocks. ...
FUZZ_TARGET(utxo_total_supply)
std::shared_ptr< CBlock > PrepareBlock(const NodeContext &node, const CScript &coinbase_scriptPubKey, const BlockAssembler::Options &assembler_options)
#define Assert(val)
Identity function.
const Txid & GetHash() const LIFETIMEBOUND