Bitcoin Core 31.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
54 virtual util::Expected<FeeRateEstimation, FeeRateEstimationError> GetFeeRateEstimate(int target, bool conservative) const;
55
64
66 void IntervalFlush();
67
69 void ShutdownFlush();
70
74 virtual unsigned int MaximumTarget() const;
75
79 CFeeRate BlockPolicyEstimateRawFee(unsigned int target, double threshold, FeeEstimateHorizon horizon, EstimationResult* buckets) const;
80
84 unsigned int BlockPolicyHighestTargetTracked(FeeEstimateHorizon horizon) const;
85
89 std::vector<MinedBlockStats> MempoolPolicyEstimatorBlocksStats() const;
90
91protected:
93 void TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t /*unused*/) override;
94 void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason /*unused*/, uint64_t /*unused*/) override;
95 void MempoolTransactionsRemovedForBlock(const std::shared_ptr<const CBlock>& block, const std::vector<RemovedMempoolTransactionInfo>& txs_removed_for_block, unsigned int block_height) override;
96
97private:
98 std::unique_ptr<CBlockPolicyEstimator> m_block_policy_estimator;
99 std::unique_ptr<MemPoolFeeRateEstimator> m_mempool_estimator;
100};
101
102#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:945
Manages fee rate estimators.
Definition: estimator_man.h:31
std::unique_ptr< MemPoolFeeRateEstimator > m_mempool_estimator
Definition: estimator_man.h:99
unsigned int BlockPolicyHighestTargetTracked(FeeEstimateHorizon horizon) const
Returns the maximum supported confirmation target of block policy estimator.
virtual util::Expected< FeeRateEstimation, FeeRateEstimationError > GetFeeRateEstimate(int target, bool conservative) const
Get a 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
Definition: estimator_man.h:98
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:403
FeeRateEstimatorType
Identifier for fee rate estimator.
Definition: fees.h:36