14#include <validation.h>
25struct FeeEstimatorManTestingSetup :
public TestingSetup {
26 FeeEstimatorManTestingSetup(
const ChainType chain_type, TestOpts opts) : TestingSetup{chain_type, opts}
30 ~FeeEstimatorManTestingSetup()
32 m_node.fee_estimator_man.reset();
35 void SetFeeEstimatorMan(std::unique_ptr<FeeRateEstimatorManager> fee_estimator_man)
37 m_node.fee_estimator_man = std::move(fee_estimator_man);
41FeeEstimatorManTestingSetup*
g_setup;
43class FuzzedFeeEstimatorMan :
public FeeRateEstimatorManager
45 FuzzedDataProvider& fuzzed_data_provider;
48 FuzzedFeeEstimatorMan(FuzzedDataProvider&
provider,
const CTxMemPool& mempool, ChainstateManager& chainman)
49 : FeeRateEstimatorManager(fs::path{}, false, fs::path{}, mempool, chainman), fuzzed_data_provider(
provider) {}
51 util::Expected<FeeRateEstimation, FeeRateEstimationError> GetFeeRateEstimate(
int confTarget,
bool conservative)
const override
53 FeePerVSize feerate(
ConsumeMoney(fuzzed_data_provider, 1'000'000), fuzzed_data_provider.ConsumeIntegralInRange<
unsigned int>(1000, 1000000));
56 util::Expected<FeeRateEstimation, FeeRateEstimationError> GetFeeRateEstimate(
FeeRateEstimatorType type,
int confTarget,
bool conservative)
const override
58 auto res = GetFeeRateEstimate(confTarget, conservative);
59 if (res) res->feerate_estimator = type;
62 unsigned int MaximumTarget()
const override
64 return fuzzed_data_provider.ConsumeIntegralInRange<
unsigned int>(1, 1004);
68void initialize_setup()
77 FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
78 FakeNodeClock clock{
ConsumeTime(fuzzed_data_provider)};
80 Chainstate* chainstate = &node.chainman->ActiveChainstate();
84 .incremental_relay_feerate = CFeeRate{
ConsumeMoney(fuzzed_data_provider, 1'000'000)},
85 .min_relay_feerate = CFeeRate{
ConsumeMoney(fuzzed_data_provider, 1'000'000)},
86 .dust_relay_feerate = CFeeRate{
ConsumeMoney(fuzzed_data_provider, 1'000'000)}
88 node.mempool = std::make_unique<CTxMemPool>(mempool_opts, error);
89 std::unique_ptr<FeeRateEstimatorManager> fee_estimator_man = std::make_unique<FuzzedFeeEstimatorMan>(fuzzed_data_provider, *node.mempool, *node.chainman);
90 g_setup->SetFeeEstimatorMan(std::move(fee_estimator_man));
91 auto target_feerate{CFeeRate{
ConsumeMoney(fuzzed_data_provider, 1'000'000)}};
92 if (target_feerate > node.mempool->m_opts.incremental_relay_feerate &&
93 target_feerate > node.mempool->m_opts.min_relay_feerate) {
134 std::optional<int> returned_target;
constexpr CAmount COIN
The amount of satoshis in one BTC.
const TestingSetup * g_setup
uint256 GetBlockHash() const
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
int Height() const
Return the maximal height in the chain.
FeeEstimateMode m_fee_mode
Fee estimation mode.
std::optional< unsigned int > m_confirm_target
Override the default confirmation target if set.
std::optional< CFeeRate > m_feerate
Override the wallet's fee rate if set.
kernel::MemPoolOptions Options
CFeeRate m_discard_rate
If the cost to spend a change output at this feerate is greater than the value of the output itself,...
CFeeRate m_fallback_fee
If fee estimation does not have enough data to provide estimates, use this fee instead.
RecursiveMutex cs_wallet
Main wallet lock.
T ConsumeIntegralInRange(T min, T max)
T PickValueInArray(const T(&array)[size])
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
FeePerUnit< VSizeTag > FeePerVSize
void SetLastBlockProcessed(int block_height, uint256 block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Set last block processed height, and write to database.
std::unique_ptr< WalletDatabase > CreateMockableWalletDatabase()
CFeeRate GetRequiredFeeRate(const CWallet &wallet)
Return the minimum required feerate taking into account the minimum relay feerate and user set minimu...
MinimumFeeRateResult GetMinimumFeeRate(const CWallet &wallet, const CCoinControl &coin_control)
Estimate the minimum fee rate considering user set parameters and the required fee.
CAmount GetMinimumFee(const MinimumFeeRateResult &min_fee_rate, unsigned int nTxBytes)
Return the minimum fee for this size given a fee rate result.
FUZZ_TARGET(coin_grinder)
CFeeRate GetDiscardRate(const CWallet &wallet)
Return the maximum feerate for discarding change.
CAmount GetRequiredFee(const CWallet &wallet, unsigned int nTxBytes)
Return the minimum required absolute fee for this size based on the required fee rate.
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.
SeedRandomStateForTest(SeedRand::ZEROS)
FuzzedDataProvider provider
NodeSeconds ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
CAmount ConsumeMoney(FuzzedDataProvider &fuzzed_data_provider, const std::optional< CAmount > &max) noexcept
@ ZEROS
Seed with a compile time constant of zeros.
void MockMempoolMinFee(const CFeeRate &target_feerate, CTxMemPool &mempool)
Mock the mempool minimum feerate by adding a transaction and calling TrimToSize(0),...
FeeRateEstimatorType
Identifier for fee rate estimator.
@ CONSERVATIVE
Force Fee rate estimator to return conservative estimates.
@ ECONOMICAL
Force Fee rate estimator to return non-conservative estimates.