Bitcoin Core 31.99.0
P2P Digital Currency
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
8#include <streams.h>
10#include <test/fuzz/fuzz.h>
11#include <test/fuzz/util.h>
13
14#include <memory>
15
16namespace {
18} // namespace
19
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
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{
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{
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}
const TestingSetup * g_setup
constexpr bool DEFAULT_ACCEPT_STALE_FEE_ESTIMATES
Non-refcounted RAII wrapper for FILE*.
Definition: streams.h:395
int fclose()
Definition: streams.h:429
The BlockPolicyEstimator is used for estimating the feerate needed for a transaction to be included i...
Estimate the fee rate required for a transaction to be included in the next block.
fs::path MempoolPolicyEstimatorPath(const ArgsManager &argsman)
fs::path BlockPolicyFeeEstPath(const ArgsManager &argsman)
Definition: basic.cpp:11
FUZZ_TARGET(policy_estimator_io,.init=initialize_policy_estimator_io)
void initialize_policy_estimator_io()
node::NodeContext m_node
Definition: setup_common.h:60
bool setup_net
Definition: setup_common.h:50
Testing setup that configures a complete environment.
Definition: setup_common.h:115
std::unique_ptr< CTxMemPool > mempool
Definition: context.h:71
std::unique_ptr< ChainstateManager > chainman
Definition: context.h:76
ArgsManager * args
Definition: context.h:78
FuzzedDataProvider & fuzzed_data_provider
Definition: fees.cpp:45