Bitcoin Core 31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
load_external_block_file.cpp
Go to the documentation of this file.
1// Copyright (c) 2020-present 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 <util/time.h>
13#include <validation.h>
14
15#include <cstdint>
16#include <vector>
17
18namespace {
20} // namespace
21
23{
24 static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
25 g_setup = testing_setup.get();
26}
27
29{
30 FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
31 SetMockTime(ConsumeTime(fuzzed_data_provider));
32 FuzzedFileProvider fuzzed_file_provider{fuzzed_data_provider};
33 AutoFile fuzzed_block_file{fuzzed_file_provider.open()};
34 if (fuzzed_block_file.IsNull()) {
35 return;
36 }
37 if (fuzzed_data_provider.ConsumeBool()) {
38 // Corresponds to the -reindex case (track orphan blocks across files).
39 FlatFilePos flat_file_pos;
40 std::multimap<uint256, FlatFilePos> blocks_with_unknown_parent;
41 g_setup->m_node.chainman->LoadExternalBlockFile(fuzzed_block_file, &flat_file_pos, &blocks_with_unknown_parent);
42 } else {
43 // Corresponds to the -loadblock= case (orphan blocks aren't tracked across files).
44 g_setup->m_node.chainman->LoadExternalBlockFile(fuzzed_block_file);
45 }
46}
const TestingSetup * g_setup
Non-refcounted RAII wrapper for FILE*.
Definition streams.h:373
bool IsNull() const
Return true if the wrapped FILE* is nullptr, false otherwise.
Definition streams.h:426
FILE * open()
Definition util.cpp:256
#define FUZZ_TARGET(...)
Definition fuzz.h:35
void initialize_load_external_block_file()
std::unique_ptr< T > MakeNoLogFileContext(const ChainType chain_type=ChainType::REGTEST, TestOpts opts={})
Make a test setup that has disk access to the debug.log file disabled.
Testing setup that configures a complete environment.
NodeSeconds ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
Definition util.cpp:34
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
Definition time.cpp:44