10#include <validation.h>
19struct FeeEstimatorTestingSetup :
public TestingSetup {
20 FeeEstimatorTestingSetup(
const ChainType chain_type, TestOpts opts) : TestingSetup{chain_type, opts}
24 ~FeeEstimatorTestingSetup() {
25 m_node.fee_estimator.reset();
28 void SetFeeEstimator(std::unique_ptr<CBlockPolicyEstimator> fee_estimator)
30 m_node.fee_estimator = std::move(fee_estimator);
34FeeEstimatorTestingSetup*
g_setup;
36class FuzzedBlockPolicyEstimator :
public CBlockPolicyEstimator
38 FuzzedDataProvider& fuzzed_data_provider;
41 FuzzedBlockPolicyEstimator(FuzzedDataProvider& provider)
42 : CBlockPolicyEstimator(fs::path{}, false), fuzzed_data_provider(provider) {}
44 CFeeRate estimateSmartFee(
int confTarget, FeeCalculation* feeCalc,
bool conservative)
const override
46 return CFeeRate{
ConsumeMoney(fuzzed_data_provider, 1'000'000)};
51 return fuzzed_data_provider.ConsumeIntegralInRange<
unsigned int>(1, 1000);
55void initialize_setup()
64 FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
67 Chainstate* chainstate = &node.chainman->ActiveChainstate();
71 .incremental_relay_feerate = CFeeRate{
ConsumeMoney(fuzzed_data_provider, 1'000'000)},
72 .min_relay_feerate = CFeeRate{
ConsumeMoney(fuzzed_data_provider, 1'000'000)},
73 .dust_relay_feerate = CFeeRate{
ConsumeMoney(fuzzed_data_provider, 1'000'000)}
75 node.mempool = std::make_unique<CTxMemPool>(mempool_opts, error);
76 std::unique_ptr<CBlockPolicyEstimator> fee_estimator = std::make_unique<FuzzedBlockPolicyEstimator>(fuzzed_data_provider);
77 g_setup->SetFeeEstimator(std::move(fee_estimator));
78 auto target_feerate{CFeeRate{
ConsumeMoney(fuzzed_data_provider, 1'000'000)}};
79 if (target_feerate > node.mempool->m_opts.incremental_relay_feerate &&
80 target_feerate > node.mempool->m_opts.min_relay_feerate) {
118 FeeCalculation fee_calculation;
119 FeeCalculation* maybe_fee_calculation{fuzzed_data_provider.
ConsumeBool() ? nullptr : &fee_calculation};
121 (void)
GetMinimumFee(wallet, tx_bytes, coin_control, maybe_fee_calculation);
static 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 to control arguments to estimateSmartFee.
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)
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
void SetLastBlockProcessed(int block_height, uint256 block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Set last block processed height, and write to database.
CFeeRate GetRequiredFeeRate(const CWallet &wallet)
Return the minimum required feerate taking into account the minimum relay feerate and user set minimu...
CAmount GetMinimumFee(const CWallet &wallet, unsigned int nTxBytes, const CCoinControl &coin_control, FeeCalculation *feeCalc)
Estimate the minimum fee considering user set parameters and the required fee.
CFeeRate GetMinimumFeeRate(const CWallet &wallet, const CCoinControl &coin_control, FeeCalculation *feeCalc)
Estimate the minimum fee rate considering user set parameters and the required fee.
std::unique_ptr< WalletDatabase > CreateMockableWalletDatabase(MockableData records)
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.
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
void SeedRandomStateForTest(SeedRand seedtype)
Seed the global RNG state for testing and log the seed value.
@ 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),...
@ CONSERVATIVE
Force estimateSmartFee to use conservative estimates.
@ ECONOMICAL
Force estimateSmartFee to use non-conservative estimates.
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.