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_POLICY_FEES_ESTIMATOR_MAN_H6#define BITCOIN_POLICY_FEES_ESTIMATOR_MAN_H8#include <policy/fees/block_policy_estimator.h>9#include <policy/fees/mempool_estimator.h>10#include <primitives/transaction.h>11#include <util/expected.h>12#include <util/fees.h>13#include <util/fs.h>14#include <validationinterface.h>16#include <chrono>17#include <memory>19class CFeeRate;20class ChainstateManager;21class CTxMemPool;22class MemPoolFeeRateEstimator;24// How often to flush data to disk25inline constexpr std::chrono::hours FEE_FLUSH_INTERVAL{1};27/** \class FeeRateEstimatorManager28* Manages fee rate estimators.29*/30class FeeRateEstimatorManager : public CValidationInterface31{32public:33/**34* @param[in] block_policy_path Path to the block policy fee estimates file.35* @param[in] read_stale_estimates Whether to load stale estimates from disk.36* @param[in] mempool_estimator_path Path to the mempool policy estimator data file.37* @param[in] mempool The mempool to use for the mempool fee rate estimator.38* @param[in] chainman The chainstate manager.39*/40FeeRateEstimatorManager(const fs::path& block_policy_path,41bool read_stale_estimates,42const fs::path& mempool_estimator_path,43const CTxMemPool& mempool,44ChainstateManager& chainman);46virtual ~FeeRateEstimatorManager();48/**49* @brief Get a combined fee rate estimate from the available fee rate estimators.50* Combines both estimators, returning the lower of the block policy and mempool fee rate51* estimates. If the mempool fee rate estimator cannot produce an estimate, the block policy fee52* rate estimate is returned instead. An error is returned only if the block policy fee rate53* estimate is unavailable.54* @param[in] target The target within which the transaction should be confirmed.55* @param[in] conservative Whether to select a more conservative, potentially higher, fee rate estimate.56* @return fee rate estimation, or an error on failure.57*/58virtual util::Expected<FeeRateEstimation, FeeRateEstimationError> GetFeeRateEstimate(int target, bool conservative) const;60/**61* Like GetFeeRateEstimate, but only consults the specified estimator type.62* @param[in] type The estimator to query. AUTO returns the manager-selected combined estimate.63* @param[in] target The target within which the transaction should be confirmed.64* @param[in] conservative Whether to select a more conservative, potentially higher, fee rate estimate.65* @return Fee rate estimation from the specified estimator, or an error on failure.66*/67virtual util::Expected<FeeRateEstimation, FeeRateEstimationError> GetFeeRateEstimate(FeeRateEstimatorType type, int target, bool conservative) const;69/** Flush recorded data to disk. */70void IntervalFlush();72/** Flush recorded data to disk as part of shutdown sequence. */73void ShutdownFlush();75/**76* Called when the mempool was not loaded from disk (the load failed, there was no77* mempool file, or -persistmempool=0), unless loading was interrupted by shutdown.78*/79void MempoolLoadFailed();81/**82* @brief Returns the maximum supported confirmation target from all fee rate estimators.83*/84virtual unsigned int MaximumTarget() const;86/**87* @brief Delegate to the block policy estimator's estimateRawFee (used by the estimaterawfee RPC).88*/89CFeeRate BlockPolicyEstimateRawFee(unsigned int target, double threshold, FeeEstimateHorizon horizon, EstimationResult* buckets) const;91/**92* @brief Returns the maximum supported confirmation target of block policy estimator.93*/94unsigned int BlockPolicyHighestTargetTracked(FeeEstimateHorizon horizon) const;96/**97* Returns per-block weight statistics for the last MEMPOOL_HEALTH_WINDOW_BLOCKS mined blocks.98*/99std::vector<MinedBlockStats> MempoolPolicyEstimatorBlocksStats() const;101protected:102/** Overridden from CValidationInterface. */103void TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t /*unused*/) override;104void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason /*unused*/, uint64_t /*unused*/) override;105void MempoolTransactionsRemovedForBlock(const std::shared_ptr<const CBlock>& block, const std::vector<RemovedMempoolTransactionInfo>& txs_removed_for_block, unsigned int block_height) override;107private:108std::unique_ptr<CBlockPolicyEstimator> m_block_policy_estimator;109std::unique_ptr<MemPoolFeeRateEstimator> m_mempool_estimator;110};112#endif // BITCOIN_POLICY_FEES_ESTIMATOR_MAN_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.