Bitcoin Core  25.99.0
P2P Digital Currency
validation_load_mempool.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020-2022 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 
6 
7 #include <node/mempool_args.h>
10 #include <test/fuzz/fuzz.h>
11 #include <test/fuzz/util.h>
12 #include <test/fuzz/util/mempool.h>
13 #include <test/util/setup_common.h>
14 #include <test/util/txmempool.h>
15 #include <txmempool.h>
16 #include <util/time.h>
17 #include <validation.h>
18 
19 #include <cstdint>
20 #include <vector>
21 
23 
24 using node::MempoolPath;
25 
26 namespace {
27 const TestingSetup* g_setup;
28 } // namespace
29 
31 {
32  static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
33  g_setup = testing_setup.get();
34 }
35 
37 {
38  FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
39  SetMockTime(ConsumeTime(fuzzed_data_provider));
40  FuzzedFileProvider fuzzed_file_provider = ConsumeFile(fuzzed_data_provider);
41 
42  CTxMemPool pool{MemPoolOptionsForTest(g_setup->m_node)};
43 
44  auto& chainstate{static_cast<DummyChainState&>(g_setup->m_node.chainman->ActiveChainstate())};
45  chainstate.SetMempool(&pool);
46 
47  auto fuzzed_fopen = [&](const fs::path&, const char*) {
48  return fuzzed_file_provider.open();
49  };
50  (void)chainstate.LoadMempool(MempoolPath(g_setup->m_args), fuzzed_fopen);
51  (void)DumpMempool(pool, MempoolPath(g_setup->m_args), fuzzed_fopen, true);
52 }
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:316
void SetMempool(CTxMemPool *mempool)
Definition: mempool.h:18
FILE * open()
Definition: util.cpp:207
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:31
bool DumpMempool(const CTxMemPool &pool, const fs::path &dump_path, FopenFn mockable_fopen_function, bool skip_file_commit)
fs::path MempoolPath(const ArgsManager &argsman)
Testing setup that configures a complete environment.
Definition: setup_common.h:108
int64_t ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
Definition: util.cpp:22
FuzzedFileProvider ConsumeFile(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.h:243
CTxMemPool::Options MemPoolOptionsForTest(const NodeContext &node)
Definition: txmempool.cpp:17
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
Definition: time.cpp:81
FUZZ_TARGET_INIT(validation_load_mempool, initialize_validation_load_mempool)
void initialize_validation_load_mempool()