6 #include <chainparams.h> 13 #include <validation.h> 49 static const auto testing_setup = MakeNoLogFileContext<>(
ChainType::MAIN);
50 g_setup = testing_setup.get();
59 .cache_bytes = 1 << 20,
64 int files_count = fuzzed_data_provider.ConsumeIntegralInRange(1, 100);
65 std::vector<std::unique_ptr<CBlockFileInfo>> files;
66 files.reserve(files_count);
67 std::vector<std::pair<int, const CBlockFileInfo*>> files_info;
68 files_info.reserve(files_count);
69 for (
int i = 0; i < files_count; i++) {
70 if (
auto file_info = ConsumeDeserializable<CBlockFileInfo>(fuzzed_data_provider)) {
71 files.push_back(std::make_unique<CBlockFileInfo>(std::move(*file_info)));
72 files_info.emplace_back(i, files.back().get());
79 int blocks_count = fuzzed_data_provider.ConsumeIntegralInRange(files_count * 10, files_count * 100);
80 std::vector<std::unique_ptr<CBlockIndex>> blocks;
81 blocks.reserve(blocks_count);
82 std::vector<const CBlockIndex*> blocks_info;
83 blocks_info.reserve(blocks_count);
84 for (
int i = 0; i < blocks_count; i++) {
85 CBlockHeader header{ConsumeBlockHeader(fuzzed_data_provider)};
86 blocks.push_back(std::make_unique<CBlockIndex>(std::move(header)));
87 blocks.back()->phashBlock = &g_block_hash;
88 blocks_info.push_back(blocks.back().get());
92 assert(block_index.WriteBatchSync(files_info, files_count - 1, blocks_info));
97 for (
const auto& [n, file_info]: files_info) {
98 assert(block_index.ReadBlockFileInfo(n, info));
99 assert(info == *file_info);
104 assert(block_index.ReadLastBlockFile(last_block_file));
105 assert(last_block_file == files_count - 1);
109 block_index.WriteReindexing(
true);
110 block_index.ReadReindexing(reindexing);
112 block_index.WriteReindexing(
false);
113 block_index.ReadReindexing(reindexing);
117 const std::string flag_name = fuzzed_data_provider.ConsumeRandomLengthString(100);
119 block_index.WriteFlag(flag_name,
true);
120 block_index.ReadFlag(flag_name, flag_value);
122 block_index.WriteFlag(flag_name,
false);
123 block_index.ReadFlag(flag_name, flag_value);
129 const auto inserter = [&](
const uint256&) {
130 return blocks.back().get();
fs::path path
Location in the filesystem where leveldb data will be stored.
bool operator==(const CNetAddr &a, const CNetAddr &b)
Access to the block database (blocks/index/)
unsigned int nSize
number of used bytes of block file
const CBlock & GenesisBlock() const
util::SignalInterrupt m_interrupt
unsigned int nHeightLast
highest height of block in file
unsigned int nUndoSize
number of used bytes in the undo file
uint64_t nTimeFirst
earliest time of block in file
FUZZ_TARGET(block_index,.init=init_block_index)
unsigned int nHeightFirst
lowest height of block in file
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
const CChainParams & Params()
Return the currently selected parameters.
Application-specific storage settings.
unsigned int nBlocks
number of blocks stored in file
uint64_t nTimeLast
latest time of block in file
const Consensus::Params & GetConsensus() const
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...