Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
test
fuzz
validation_load_mempool.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 <
node/mempool_persist.h
>
6
#include <
test/util/time.h
>
7
8
#include <
node/mempool_args.h
>
9
#include <
node/mempool_persist_args.h
>
10
#include <
test/fuzz/FuzzedDataProvider.h
>
11
#include <
test/fuzz/fuzz.h
>
12
#include <
test/fuzz/util.h
>
13
#include <
test/fuzz/util/mempool.h
>
14
#include <
test/util/setup_common.h
>
15
#include <
test/util/txmempool.h
>
16
#include <
txmempool.h
>
17
#include <
util/check.h
>
18
#include <util/time.h>
19
#include <
util/translation.h
>
20
#include <validation.h>
21
22
#include <cstdint>
23
#include <vector>
24
25
using
node::DumpMempool
;
26
using
node::LoadMempool
;
27
28
using
node::MempoolPath
;
29
30
namespace
{
31
const
TestingSetup
*
g_setup
;
32
}
// namespace
33
34
void
initialize_validation_load_mempool
()
35
{
36
static
const
auto
testing_setup =
MakeNoLogFileContext<const TestingSetup>
();
37
g_setup
= testing_setup.get();
38
}
39
40
FUZZ_TARGET
(validation_load_mempool, .
init
=
initialize_validation_load_mempool
)
41
{
42
SeedRandomStateForTest
(
SeedRand::ZEROS
);
43
FuzzedDataProvider
fuzzed_data_provider{buffer.data(), buffer.size()};
44
FakeNodeClock
clock{
ConsumeTime
(fuzzed_data_provider)};
45
FuzzedFileProvider
fuzzed_file_provider{fuzzed_data_provider};
46
47
bilingual_str
error;
48
CTxMemPool
pool{
MemPoolOptionsForTest
(
g_setup
->
m_node
), error};
49
Assert
(error.
empty
());
50
51
auto
& chainstate{
static_cast<
DummyChainState
&
>
(
g_setup
->
m_node
.
chainman
->ActiveChainstate())};
52
chainstate.SetMempool(&pool);
53
54
auto
fuzzed_fopen = [&](
const
fs::path&,
const
char
*) {
55
return
fuzzed_file_provider.
open
();
56
};
57
(void)
LoadMempool
(pool,
MempoolPath
(
g_setup
->
m_args
), chainstate,
58
{
59
.mockable_fopen_function = fuzzed_fopen,
60
});
61
pool.
SetLoadTried
(
true
);
62
(void)
DumpMempool
(pool,
MempoolPath
(
g_setup
->
m_args
), fuzzed_fopen,
true
);
63
}
FuzzedDataProvider.h
g_setup
const TestingSetup * g_setup
Definition
block_index_tree.cpp:22
check.h
Assert
#define Assert(val)
Identity function.
Definition
check.h:116
CTxMemPool
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition
txmempool.h:187
CTxMemPool::SetLoadTried
void SetLoadTried(bool load_tried)
Set whether or not an initial attempt to load the persisted mempool was made (regardless of whether t...
Definition
txmempool.cpp:1010
DummyChainState
Definition
mempool.h:16
FakeNodeClock
Helper to initialize the global NodeClock, let a duration elapse, and reset it after use in a test.
Definition
time.h:54
FuzzedDataProvider
Definition
FuzzedDataProvider.h:32
FuzzedFileProvider
Definition
util.h:289
FuzzedFileProvider::open
FILE * open()
Definition
util.cpp:251
fuzz.h
FUZZ_TARGET
#define FUZZ_TARGET(...)
Definition
fuzz.h:35
MempoolPath
fs::path MempoolPath(const ArgsManager &argsman)
Definition
mempool_persist_args.cpp:18
DumpMempool
bool DumpMempool(const CTxMemPool &pool, const fs::path &dump_path, fsbridge::FopenFn mockable_fopen_function=fsbridge::fopen, bool skip_file_commit=false)
Dump the mempool to a file.
Definition
mempool_persist.cpp:153
LoadMempool
bool LoadMempool(CTxMemPool &pool, const fs::path &load_path, Chainstate &active_chainstate, ImportMempoolOptions &&opts)
Import the file and attempt to add its contents to the mempool.
Definition
mempool_persist.cpp:43
mempool_args.h
mempool_persist.h
mempool_persist_args.h
init
Definition
basic.cpp:11
node::MempoolPath
fs::path MempoolPath(const ArgsManager &argsman)
Definition
mempool_persist_args.cpp:18
node::DumpMempool
bool DumpMempool(const CTxMemPool &pool, const fs::path &dump_path, FopenFn mockable_fopen_function, bool skip_file_commit)
Dump the mempool to a file.
Definition
mempool_persist.cpp:153
node::LoadMempool
bool LoadMempool(CTxMemPool &pool, const fs::path &load_path, Chainstate &active_chainstate, ImportMempoolOptions &&opts)
Import the file and attempt to add its contents to the mempool.
Definition
mempool_persist.cpp:43
setup_common.h
MakeNoLogFileContext
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.
Definition
setup_common.h:241
BasicTestingSetup::m_args
ArgsManager m_args
Test-specific arguments and settings.
Definition
setup_common.h:93
BasicTestingSetup::m_node
node::NodeContext m_node
Definition
setup_common.h:60
TestingSetup
Testing setup that configures a complete environment.
Definition
setup_common.h:115
bilingual_str
Bilingual messages:
Definition
translation.h:24
bilingual_str::empty
bool empty() const
Definition
translation.h:35
node::NodeContext::chainman
std::unique_ptr< ChainstateManager > chainman
Definition
context.h:76
SeedRandomStateForTest
SeedRandomStateForTest(SeedRand::ZEROS)
mempool.h
ConsumeTime
NodeSeconds ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
Definition
util.cpp:34
util.h
SeedRand::ZEROS
@ ZEROS
Seed with a compile time constant of zeros.
Definition
random.h:19
time.h
MemPoolOptionsForTest
CTxMemPool::Options MemPoolOptionsForTest(const NodeContext &node)
Definition
txmempool.cpp:21
txmempool.h
translation.h
txmempool.h
initialize_validation_load_mempool
void initialize_validation_load_mempool()
Definition
validation_load_mempool.cpp:34
Generated on
for Bitcoin Core by
1.18.0