Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#ifndef BITCOIN_UTIL_FEES_H6#define BITCOIN_UTIL_FEES_H8#include <attributes.h>9#include <util/expected.h>10#include <util/feefrac.h>12#include <optional>13#include <string>14#include <string_view>15#include <utility>17/* Used to determine type of fee estimation requested */18enum class FeeEstimateMode {19UNSET, //!< Use default settings based on other criteria20ECONOMICAL, //!< Force Fee rate estimator to return non-conservative estimates21CONSERVATIVE, //!< Force Fee rate estimator to return conservative estimates22};24/* Used to determine the reason a wallet selected a transaction fee rate */25enum class FeeReason {26FEE_RATE_ESTIMATOR,27MEMPOOL_MIN,28USER_SPECIFIED,29FALLBACK,30REQUIRED,31};33/**34* @enum FeeRateEstimatorType35* Identifier for fee rate estimator.36*/37enum class FeeRateEstimatorType {38AUTO,39BLOCK_POLICY,40MEMPOOL_POLICY,41};43/**44* @struct FeeRateEstimation45* A successful fee rate estimate returned by a fee rate estimator.46*/47struct FeeRateEstimation {48//! This identifies which fee rate estimator is providing this feerate estimate49FeeRateEstimatorType feerate_estimator;50//! Fee rate sufficient for confirmation within target.51FeePerVSize feerate;52//! The returned confirmation target for the estimate.53int returned_target;54/**55* Compare two FeeRateEstimation objects based on fee rate56* @param other The other FeeRateEstimation object to compare with57* @return strong ordering of either less, greater or equal; based on feerate ratio comparison.58*/59auto operator<=>(const FeeRateEstimation& other) const60{61return ByRatio{feerate} <=> ByRatio{other.feerate};62}63};65/**66* @struct FeeRateEstimationError67* A failed fee rate estimation, carrying the zero-value estimation that68* identifies the estimator and target alongside the error reason.69*/70struct FeeRateEstimationError {71FeeRateEstimation estimation;72std::string reason;73};75/**76* Build a fee rate estimation error result: a zero-value estimation77* identifying the estimator and target, alongside the error message.78*/79inline util::Unexpected<FeeRateEstimationError> EstimationError(FeeRateEstimatorType estimator, int returned_target, std::string error)80{81return util::Unexpected{FeeRateEstimationError{{estimator, FeePerVSize{0, 0}, returned_target}, std::move(error)}};82}84/**85* Return the estimation carried by a fee rate estimate result: the86* successful estimation, or the error's zero-value estimation.87*/88inline const FeeRateEstimation& FeeRateEstimationRef(const util::Expected<FeeRateEstimation, FeeRateEstimationError>& result LIFETIMEBOUND)89{90return result ? *result : result.error().estimation;91}93std::string_view FeeRateEstimatorTypeToString(FeeRateEstimatorType feerate_estimator_type);94std::optional<FeeRateEstimatorType> FeeRateEstimatorTypeFromString(std::string_view feerate_estimator_type);96#endif // BITCOIN_UTIL_FEES_H
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.