5 #include <chainparams.h>
22 const std::vector<std::shared_ptr<CBlock>>* g_chain;
24 void initialize_chain()
34 std::unique_ptr<const TestingSetup> setup{MakeNoLogFileContext<const TestingSetup>()};
35 const auto&
node = setup->m_node;
36 auto& chainman{*
node.chainman};
40 Assert(!chainman.SnapshotBlockhash());
45 outfile <<
Span{file_data};
48 const auto ActivateFuzzedSnapshot{[&] {
53 }
catch (
const std::ios_base::failure&) {
56 return chainman.ActivateSnapshot(infile, metadata,
true);
59 if (fuzzed_data_provider.ConsumeBool()) {
60 for (
const auto& block : *g_chain) {
62 bool processed{chainman.ProcessNewBlockHeaders({*block},
true, dummy)};
64 const auto* index{
WITH_LOCK(::
cs_main,
return chainman.m_blockman.LookupBlockIndex(block->GetHash()))};
69 if (ActivateFuzzedSnapshot()) {
71 Assert(!chainman.ActiveChainstate().m_from_snapshot_blockhash->IsNull());
72 Assert(*chainman.ActiveChainstate().m_from_snapshot_blockhash ==
73 *chainman.SnapshotBlockhash());
74 const auto& coinscache{chainman.ActiveChainstate().CoinsTip()};
76 for (
const auto& block : *g_chain) {
78 const auto* index{chainman.m_blockman.LookupBlockIndex(block->GetHash())};
79 const auto num_tx{
Assert(index)->nTx};
83 Assert(g_chain->size() == coinscache.GetCacheSize());
84 Assert(chain_tx == chainman.ActiveTip()->nChainTx);
86 Assert(!chainman.SnapshotBlockhash());
87 Assert(!chainman.ActiveChainstate().m_from_snapshot_blockhash);
90 Assert(!ActivateFuzzedSnapshot());
std::unique_ptr< const CChainParams > CreateChainParams(const ArgsManager &args, const ChainType chain)
Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
#define Assert(val)
Identity function.
const fs::path & GetDataDirNet() const
Get data directory path with appended network identifier.
Non-refcounted RAII wrapper for FILE*.
An outpoint - a combination of a transaction hash and an index n into its vout.
A Span is an object that can refer to a contiguous sequence of objects.
static const int COINBASE_MATURITY
Coinbase transaction outputs can only be spent after this number of new blocks (network rule)
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
#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.