Bitcoin Core 28.99.0
P2P Digital Currency
load_external_block_file.cpp
Go to the documentation of this file.
1// Copyright (c) 2020-2021 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <chainparams.h>
6#include <clientversion.h>
7#include <flatfile.h>
9#include <test/fuzz/fuzz.h>
10#include <test/fuzz/util.h>
12#include <validation.h>
13
14#include <cstdint>
15#include <vector>
16
17namespace {
18const TestingSetup* g_setup;
19} // namespace
20
22{
23 static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
24 g_setup = testing_setup.get();
25}
26
28{
29 FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
30 FuzzedFileProvider fuzzed_file_provider{fuzzed_data_provider};
31 AutoFile fuzzed_block_file{fuzzed_file_provider.open()};
32 if (fuzzed_block_file.IsNull()) {
33 return;
34 }
35 if (fuzzed_data_provider.ConsumeBool()) {
36 // Corresponds to the -reindex case (track orphan blocks across files).
37 FlatFilePos flat_file_pos;
38 std::multimap<uint256, FlatFilePos> blocks_with_unknown_parent;
39 g_setup->m_node.chainman->LoadExternalBlockFile(fuzzed_block_file, &flat_file_pos, &blocks_with_unknown_parent);
40 } else {
41 // Corresponds to the -loadblock= case (orphan blocks aren't tracked across files).
42 g_setup->m_node.chainman->LoadExternalBlockFile(fuzzed_block_file);
43 }
44}
Non-refcounted RAII wrapper for FILE*.
Definition: streams.h:392
void initialize_load_external_block_file()
FUZZ_TARGET(load_external_block_file,.init=initialize_load_external_block_file)
Testing setup that configures a complete environment.
Definition: setup_common.h:120