Files
bitcoin/src/util/fees.cpp
ismaelsadeeq c9bb3df29f fees: add MemPoolFeeRateEstimator class
Add MemPoolFeeRateEstimator, which calls Bitcoin Core's block
assembler with the mempool and chainstate to build a block template and
use its chunk fee rates for fee rate estimation.

Add CalculateMaxWeightPercentiles to return the 50th and 75th
percentile chunk feerates by cumulative block weight. If sparse,
EstimateFeeRate uses the higher of the minimum relay fee rate and the
current mempool minimum fee rate.

The 50th percentile is returned as the conservative estimate, and the
75th percentile as the economical estimate.

Wire MemPoolFeeRateEstimator into FeeRateEstimatorManager and add
FeeRateEstimatorType::MEMPOOL_POLICY for result attribution.

Add unit tests for the mempool fee rate estimator and fee estimator
string conversions, plus fuzz coverage for the string conversions.

Co-authored-by: willcl-ark <will@256k1.dev>
2026-08-20 15:15:03 +01:00

33 lines
1.1 KiB
C++

// Copyright (c) The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <util/fees.h>
#include <util/strencodings.h>
#include <cassert>
#include <string_view>
std::string_view FeeRateEstimatorTypeToString(FeeRateEstimatorType feerate_estimator_type)
{
switch (feerate_estimator_type) {
case FeeRateEstimatorType::NONE:
return "none";
case FeeRateEstimatorType::BLOCK_POLICY:
return "block_policy";
case FeeRateEstimatorType::MEMPOOL_POLICY:
return "mempool_policy";
}
// no default case, so the compiler can warn about missing cases
assert(false);
}
FeeRateEstimatorType FeeRateEstimatorTypeFromString(std::string_view feerate_estimator_type)
{
const auto normalized{ToLower(feerate_estimator_type)};
if (normalized == "block_policy") return FeeRateEstimatorType::BLOCK_POLICY;
if (normalized == "mempool_policy") return FeeRateEstimatorType::MEMPOOL_POLICY;
return FeeRateEstimatorType::NONE;
}