18const std::vector<std::shared_ptr<CBlock>>* g_chain;
20void initialize_chain()
30 std::unique_ptr<const TestingSetup> setup{MakeNoLogFileContext<const TestingSetup>()};
31 const auto&
node = setup->m_node;
32 auto& chainman{*
node.chainman};
36 Assert(!chainman.SnapshotBlockhash());
41 outfile << Span<const uint8_t>{file_data};
44 const auto ActivateFuzzedSnapshot{[&] {
49 }
catch (
const std::ios_base::failure&) {
52 return chainman.ActivateSnapshot(infile, metadata,
true);
55 if (fuzzed_data_provider.ConsumeBool()) {
56 for (
const auto& block : *g_chain) {
58 bool processed{chainman.ProcessNewBlockHeaders({*block}, dummy,
::Params())};
60 const auto* index{
WITH_LOCK(::
cs_main,
return chainman.m_blockman.LookupBlockIndex(block->GetHash()))};
65 if (ActivateFuzzedSnapshot()) {
67 Assert(!chainman.ActiveChainstate().m_from_snapshot_blockhash->IsNull());
68 Assert(*chainman.ActiveChainstate().m_from_snapshot_blockhash ==
69 *chainman.SnapshotBlockhash());
70 const auto& coinscache{chainman.ActiveChainstate().CoinsTip()};
72 for (
const auto& block : *g_chain) {
74 const auto* index{chainman.m_blockman.LookupBlockIndex(block->GetHash())};
75 const auto num_tx{
Assert(index)->nTx};
79 Assert(g_chain->size() == coinscache.GetCacheSize());
80 Assert(chain_tx == chainman.ActiveTip()->nChainTx);
82 Assert(!chainman.SnapshotBlockhash());
83 Assert(!chainman.ActiveChainstate().m_from_snapshot_blockhash);
86 Assert(!ActivateFuzzedSnapshot());
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
std::unique_ptr< const CChainParams > CreateChainParams(const ArgsManager &args, const std::string &chain)
Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
const CChainParams & Params()
Return the currently selected parameters.
#define Assert(val)
Identity function.
const fs::path & GetDataDirNet() const
Get data directory path with appended network identifier.
Non-refcounted RAII wrapper for FILE*.
static const std::string REGTEST
An outpoint - a combination of a transaction hash and an index n into its vout.
static const int CLIENT_VERSION
bitcoind-res.rc includes this file, but it cannot cope with real c++ code.
static const int COINBASE_MATURITY
Coinbase transaction outputs can only be spent after this number of new blocks (network rule)
#define FUZZ_TARGET_INIT(name, init_fun)
FILE * fopen(const fs::path &p, const char *mode)
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
std::vector< uint8_t > ConsumeRandomLengthByteVector(FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt) noexcept
std::vector< std::shared_ptr< CBlock > > CreateBlockChain(size_t total_height, const CChainParams ¶ms)
Create a blockchain, starting from genesis.