Bitcoin Core 32.1.0
P2P Digital Currency
Loading...
Searching...
No Matches
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{
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...
bool Write(AutoFile &fileout) const EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator)
Write estimation data to a file.
bool Read(AutoFile &filein) EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator)
Read estimation data from a file.
FILE * open()
Definition util.cpp:251
Estimate the fee rate required for a transaction to be included in the next block.
bool Write(AutoFile &file) const EXCLUSIVE_LOCKS_REQUIRED(!cs)
bool Read(AutoFile &file) EXCLUSIVE_LOCKS_REQUIRED(!cs)
Deserialize mined-block stats without taking ownership of file.
fs::path MempoolPolicyEstimatorPath(const ArgsManager &argsman)
fs::path BlockPolicyFeeEstPath(const ArgsManager &argsman)
#define FUZZ_TARGET(...)
Definition fuzz.h:35
Definition basic.cpp:11
void initialize_policy_estimator_io()
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.
node::NodeContext m_node
Testing setup that configures a complete environment.
std::unique_ptr< CTxMemPool > mempool
Definition context.h:71
std::unique_ptr< ChainstateManager > chainman
Definition context.h:76
ArgsManager * args
Definition context.h:78