Bitcoin Core 32.99.0
P2P Digital Currency
estimator_man.h
Go to the documentation of this file.
1// Copyright (c) The Bitcoin Core developers
2// Distributed under the MIT software license. See the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef BITCOIN_POLICY_FEES_ESTIMATOR_MAN_H
6#define BITCOIN_POLICY_FEES_ESTIMATOR_MAN_H
7
11#include <util/expected.h>
12#include <util/fees.h>
13#include <util/fs.h>
14#include <validationinterface.h>
15
16#include <chrono>
17#include <memory>
18
19class CFeeRate;
21class CTxMemPool;
23
24// How often to flush data to disk
25inline constexpr std::chrono::hours FEE_FLUSH_INTERVAL{1};
26
31{
32public:
40 FeeRateEstimatorManager(const fs::path& block_policy_path,
41 bool read_stale_estimates,
42 const fs::path& mempool_estimator_path,
43 const CTxMemPool& mempool,
44 ChainstateManager& chainman);
45
47
58 virtual util::Expected<FeeRateEstimation, FeeRateEstimationError> GetFeeRateEstimate(int target, bool conservative) const;
59
68
70 void IntervalFlush();
71
73 void ShutdownFlush();
74
79 void MempoolLoadFailed();
80
84 virtual unsigned int MaximumTarget() const;
85
89 CFeeRate BlockPolicyEstimateRawFee(unsigned int target, double threshold, FeeEstimateHorizon horizon, EstimationResult* buckets) const;
90
94 unsigned int BlockPolicyHighestTargetTracked(FeeEstimateHorizon horizon) const;
95
99 std::vector<MinedBlockStats> MempoolPolicyEstimatorBlocksStats() const;
100
101protected:
103 void TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t /*unused*/) override;
104 void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason /*unused*/, uint64_t /*unused*/) override;
105 void MempoolTransactionsRemovedForBlock(const std::shared_ptr<const CBlock>& block, const std::vector<RemovedMempoolTransactionInfo>& txs_removed_for_block, unsigned int block_height) override;
106
107private:
108 std::unique_ptr<CBlockPolicyEstimator> m_block_policy_estimator;
109 std::unique_ptr<MemPoolFeeRateEstimator> m_mempool_estimator;
110};
111
112#endif // BITCOIN_POLICY_FEES_ESTIMATOR_MAN_H
FeeEstimateHorizon
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
Definition: feerate.h:32
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:187
Implement this to subscribe to events generated in validation and mempool.
Interface for managing multiple Chainstate objects, where each chainstate is associated with chainsta...
Definition: validation.h:950
Manages fee rate estimators.
Definition: estimator_man.h:31
std::unique_ptr< MemPoolFeeRateEstimator > m_mempool_estimator
unsigned int BlockPolicyHighestTargetTracked(FeeEstimateHorizon horizon) const
Returns the maximum supported confirmation target of block policy estimator.
void MempoolLoadFailed()
Called when the mempool was not loaded from disk (the load failed, there was no mempool file,...
virtual util::Expected< FeeRateEstimation, FeeRateEstimationError > GetFeeRateEstimate(int target, bool conservative) const
Get a combined fee rate estimate from the available fee rate estimators.
FeeRateEstimatorManager(const fs::path &block_policy_path, bool read_stale_estimates, const fs::path &mempool_estimator_path, const CTxMemPool &mempool, ChainstateManager &chainman)
std::vector< MinedBlockStats > MempoolPolicyEstimatorBlocksStats() const
Returns per-block weight statistics for the last MEMPOOL_HEALTH_WINDOW_BLOCKS mined blocks.
void IntervalFlush()
Flush recorded data to disk.
void MempoolTransactionsRemovedForBlock(const std::shared_ptr< const CBlock > &block, const std::vector< RemovedMempoolTransactionInfo > &txs_removed_for_block, unsigned int block_height) override
void TransactionRemovedFromMempool(const CTransactionRef &tx, MemPoolRemovalReason, uint64_t) override
Notifies listeners of a transaction leaving mempool.
virtual unsigned int MaximumTarget() const
Returns the maximum supported confirmation target from all fee rate estimators.
std::unique_ptr< CBlockPolicyEstimator > m_block_policy_estimator
CFeeRate BlockPolicyEstimateRawFee(unsigned int target, double threshold, FeeEstimateHorizon horizon, EstimationResult *buckets) const
Delegate to the block policy estimator's estimateRawFee (used by the estimaterawfee RPC).
void ShutdownFlush()
Flush recorded data to disk as part of shutdown sequence.
void TransactionAddedToMempool(const NewMempoolTransactionInfo &tx, uint64_t) override
Overridden from CValidationInterface.
virtual ~FeeRateEstimatorManager()
Estimate the fee rate required for a transaction to be included in the next block.
The util::Expected class provides a standard way for low-level functions to return either error value...
Definition: expected.h:44
constexpr std::chrono::hours FEE_FLUSH_INTERVAL
Definition: estimator_man.h:25
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal.
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:417
FeeRateEstimatorType
Identifier for fee rate estimator.
Definition: fees.h:37