Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
test
fuzz
policy_estimator_io.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 <
policy/fees/block_policy_estimator.h
>
6
#include <
policy/fees/estimator_args.h
>
7
#include <
policy/fees/mempool_estimator.h
>
8
#include <
streams.h
>
9
#include <
test/fuzz/FuzzedDataProvider.h
>
10
#include <
test/fuzz/fuzz.h
>
11
#include <
test/fuzz/util.h
>
12
#include <
test/util/setup_common.h
>
13
14
#include <memory>
15
16
namespace
{
17
const
TestingSetup
*
g_setup
;
18
}
// namespace
19
20
void
initialize_policy_estimator_io
()
21
{
22
static
const
auto
testing_setup{
23
MakeNoLogFileContext<const TestingSetup>
(
ChainType::REGTEST
,
TestOpts
{.setup_net =
false
})};
24
g_setup
= testing_setup.get();
25
}
26
27
FUZZ_TARGET
(policy_estimator_io, .
init
=
initialize_policy_estimator_io
)
28
{
29
FuzzedDataProvider
fuzzed_data_provider(buffer.data(), buffer.size());
30
FuzzedFileProvider
fuzzed_file_provider{fuzzed_data_provider};
31
// Reuse estimators across runs to avoid costly object creation.
32
static
CBlockPolicyEstimator
block_policy_estimator{
33
BlockPolicyFeeEstPath
(*
g_setup
->
m_node
.
args
),
DEFAULT_ACCEPT_STALE_FEE_ESTIMATES
};
34
{
35
AutoFile
fuzzed_auto_file_block_policy{fuzzed_file_provider.
open
()};
36
if
(block_policy_estimator.
Read
(fuzzed_auto_file_block_policy)) {
37
block_policy_estimator.
Write
(fuzzed_auto_file_block_policy);
38
}
39
(void)fuzzed_auto_file_block_policy.
fclose
();
40
}
41
static
MemPoolFeeRateEstimator
mempool_feerate_estimator{
42
MempoolPolicyEstimatorPath
(*
g_setup
->
m_node
.
args
),
43
*
g_setup
->
m_node
.
mempool
,
44
*
g_setup
->
m_node
.
chainman
};
45
{
46
AutoFile
fuzzed_auto_file_mempool_policy{fuzzed_file_provider.
open
()};
47
if
(mempool_feerate_estimator.
Read
(fuzzed_auto_file_mempool_policy)) {
48
mempool_feerate_estimator.
Write
(fuzzed_auto_file_mempool_policy);
49
}
50
// Write() does not take ownership; close explicitly because it may
51
// have written to the fuzzed file.
52
(void)fuzzed_auto_file_mempool_policy.
fclose
();
53
}
54
}
FuzzedDataProvider.h
g_setup
const TestingSetup * g_setup
Definition
block_index_tree.cpp:22
block_policy_estimator.h
DEFAULT_ACCEPT_STALE_FEE_ESTIMATES
constexpr bool DEFAULT_ACCEPT_STALE_FEE_ESTIMATES
Definition
block_policy_estimator.h:34
ChainType::REGTEST
@ REGTEST
Definition
chaintype.h:16
AutoFile
Non-refcounted RAII wrapper for FILE*.
Definition
streams.h:395
AutoFile::fclose
int fclose()
Definition
streams.h:429
CBlockPolicyEstimator
The BlockPolicyEstimator is used for estimating the feerate needed for a transaction to be included i...
Definition
block_policy_estimator.h:146
CBlockPolicyEstimator::Write
bool Write(AutoFile &fileout) const EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator)
Write estimation data to a file.
Definition
block_policy_estimator.cpp:1007
CBlockPolicyEstimator::Read
bool Read(AutoFile &filein) EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator)
Read estimation data from a file.
Definition
block_policy_estimator.cpp:1031
FuzzedDataProvider
Definition
FuzzedDataProvider.h:32
FuzzedFileProvider
Definition
util.h:289
FuzzedFileProvider::open
FILE * open()
Definition
util.cpp:251
MemPoolFeeRateEstimator
Estimate the fee rate required for a transaction to be included in the next block.
Definition
mempool_estimator.h:88
MemPoolFeeRateEstimator::Write
bool Write(AutoFile &file) const EXCLUSIVE_LOCKS_REQUIRED(!cs)
Definition
mempool_estimator.cpp:248
MemPoolFeeRateEstimator::Read
bool Read(AutoFile &file) EXCLUSIVE_LOCKS_REQUIRED(!cs)
Deserialize mined-block stats without taking ownership of file.
Definition
mempool_estimator.cpp:189
MempoolPolicyEstimatorPath
fs::path MempoolPolicyEstimatorPath(const ArgsManager &argsman)
Definition
estimator_args.cpp:57
BlockPolicyFeeEstPath
fs::path BlockPolicyFeeEstPath(const ArgsManager &argsman)
Definition
estimator_args.cpp:52
estimator_args.h
fuzz.h
FUZZ_TARGET
#define FUZZ_TARGET(...)
Definition
fuzz.h:35
mempool_estimator.h
init
Definition
basic.cpp:11
initialize_policy_estimator_io
void initialize_policy_estimator_io()
Definition
policy_estimator_io.cpp:20
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
streams.h
BasicTestingSetup::m_node
node::NodeContext m_node
Definition
setup_common.h:60
TestOpts
Definition
setup_common.h:46
TestingSetup
Testing setup that configures a complete environment.
Definition
setup_common.h:115
node::NodeContext::mempool
std::unique_ptr< CTxMemPool > mempool
Definition
context.h:71
node::NodeContext::chainman
std::unique_ptr< ChainstateManager > chainman
Definition
context.h:76
node::NodeContext::args
ArgsManager * args
Definition
context.h:78
util.h
Generated on
for Bitcoin Core by
1.18.0