Bitcoin Core 32.99.0
P2P Digital Currency
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
FeeRateEstimatorManager Class Reference

Manages fee rate estimators. More...

#include <estimator_man.h>

Inheritance diagram for FeeRateEstimatorManager:
[legend]
Collaboration diagram for FeeRateEstimatorManager:
[legend]

Public Member Functions

 FeeRateEstimatorManager (const fs::path &block_policy_path, bool read_stale_estimates, const fs::path &mempool_estimator_path, const CTxMemPool &mempool, ChainstateManager &chainman)
 
virtual ~FeeRateEstimatorManager ()
 
virtual util::Expected< FeeRateEstimation, FeeRateEstimationError > GetFeeRateEstimate (int target, bool conservative) const
 Get a combined fee rate estimate from the available fee rate estimators. More...
 
virtual util::Expected< FeeRateEstimation, FeeRateEstimationError > GetFeeRateEstimate (FeeRateEstimatorType type, int target, bool conservative) const
 Like GetFeeRateEstimate, but only consults the specified estimator type. More...
 
void IntervalFlush ()
 Flush recorded data to disk. More...
 
void ShutdownFlush ()
 Flush recorded data to disk as part of shutdown sequence. More...
 
void MempoolLoadFailed ()
 Called when the mempool was not loaded from disk (the load failed, there was no mempool file, or -persistmempool=0), unless loading was interrupted by shutdown. More...
 
virtual unsigned int MaximumTarget () const
 Returns the maximum supported confirmation target from all fee rate estimators. More...
 
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). More...
 
unsigned int BlockPolicyHighestTargetTracked (FeeEstimateHorizon horizon) const
 Returns the maximum supported confirmation target of block policy estimator. More...
 
std::vector< MinedBlockStats > MempoolPolicyEstimatorBlocksStats () const
 Returns per-block weight statistics for the last MEMPOOL_HEALTH_WINDOW_BLOCKS mined blocks. More...
 

Protected Member Functions

void TransactionAddedToMempool (const NewMempoolTransactionInfo &tx, uint64_t) override
 Overridden from CValidationInterface. More...
 
void TransactionRemovedFromMempool (const CTransactionRef &tx, MemPoolRemovalReason, uint64_t) override
 Notifies listeners of a transaction leaving mempool. More...
 
void MempoolTransactionsRemovedForBlock (const std::shared_ptr< const CBlock > &block, const std::vector< RemovedMempoolTransactionInfo > &txs_removed_for_block, unsigned int block_height) override
 
- Protected Member Functions inherited from CValidationInterface
 ~CValidationInterface ()=default
 Protected destructor so that instances can only be deleted by derived classes. More...
 
virtual void UpdatedBlockTip (const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload)
 Notifies listeners when the block chain tip advances. More...
 
virtual void ActiveTipChange (const CBlockIndex &new_tip, bool is_ibd)
 Notifies listeners any time the block chain tip changes, synchronously. More...
 
virtual void TransactionAddedToMempool (const NewMempoolTransactionInfo &tx, uint64_t mempool_sequence)
 Notifies listeners of a transaction having been added to mempool. More...
 
virtual void TransactionRemovedFromMempool (const CTransactionRef &tx, MemPoolRemovalReason reason, uint64_t mempool_sequence)
 Notifies listeners of a transaction leaving mempool. More...
 
virtual void MempoolTransactionsRemovedForBlock (const std::shared_ptr< const CBlock > &block, const std::vector< RemovedMempoolTransactionInfo > &txs_removed_for_block, unsigned int block_height)
 
virtual void BlockConnected (const kernel::ChainstateRole &role, const std::shared_ptr< const CBlock > &block, const CBlockIndex *pindex)
 Notifies listeners of a block being connected. More...
 
virtual void BlockDisconnected (const std::shared_ptr< const CBlock > &block, const CBlockIndex *pindex)
 Notifies listeners of a block being disconnected Provides the block that was disconnected. More...
 
virtual void ChainStateFlushed (const kernel::ChainstateRole &role, const CBlockLocator &locator)
 Notifies listeners of the new active block chain on-disk. More...
 
virtual void BlockChecked (const std::shared_ptr< const CBlock > &, const BlockValidationState &)
 Notifies listeners of a block validation result. More...
 
virtual void NewPoWValidBlock (const CBlockIndex *pindex, const std::shared_ptr< const CBlock > &block)
 Notifies listeners that a block which builds directly on our current tip has been received and connected to the headers tree, though not validated yet. More...
 

Private Attributes

std::unique_ptr< CBlockPolicyEstimator > m_block_policy_estimator
 
std::unique_ptr< MemPoolFeeRateEstimator > m_mempool_estimator
 

Detailed Description

Manages fee rate estimators.

Definition at line 30 of file estimator_man.h.

Constructor & Destructor Documentation

◆ FeeRateEstimatorManager()

FeeRateEstimatorManager::FeeRateEstimatorManager ( const fs::path &  block_policy_path,
bool  read_stale_estimates,
const fs::path &  mempool_estimator_path,
const CTxMemPool &  mempool,
ChainstateManager &  chainman 
)
Parameters
[in]block_policy_pathPath to the block policy fee estimates file.
[in]read_stale_estimatesWhether to load stale estimates from disk.
[in]mempool_estimator_pathPath to the mempool policy estimator data file.
[in]mempoolThe mempool to use for the mempool fee rate estimator.
[in]chainmanThe chainstate manager.

Definition at line 15 of file estimator_man.cpp.

◆ ~FeeRateEstimatorManager()

FeeRateEstimatorManager::~FeeRateEstimatorManager ( )
virtualdefault

Member Function Documentation

◆ BlockPolicyEstimateRawFee()

CFeeRate FeeRateEstimatorManager::BlockPolicyEstimateRawFee ( unsigned int  target,
double  threshold,
FeeEstimateHorizon  horizon,
EstimationResult *  buckets 
) const

Delegate to the block policy estimator's estimateRawFee (used by the estimaterawfee RPC).

Definition at line 95 of file estimator_man.cpp.

Here is the caller graph for this function:

◆ BlockPolicyHighestTargetTracked()

unsigned int FeeRateEstimatorManager::BlockPolicyHighestTargetTracked ( FeeEstimateHorizon  horizon) const

Returns the maximum supported confirmation target of block policy estimator.

Definition at line 100 of file estimator_man.cpp.

Here is the caller graph for this function:

◆ GetFeeRateEstimate() [1/2]

util::Expected< FeeRateEstimation, FeeRateEstimationError > FeeRateEstimatorManager::GetFeeRateEstimate ( FeeRateEstimatorType  type,
int  target,
bool  conservative 
) const
virtual

Like GetFeeRateEstimate, but only consults the specified estimator type.

Parameters
[in]typeThe estimator to query. AUTO returns the manager-selected combined estimate.
[in]targetThe target within which the transaction should be confirmed.
[in]conservativeWhether to select a more conservative, potentially higher, fee rate estimate.
Returns
Fee rate estimation from the specified estimator, or an error on failure.

Definition at line 44 of file estimator_man.cpp.

Here is the call graph for this function:

◆ GetFeeRateEstimate() [2/2]

util::Expected< FeeRateEstimation, FeeRateEstimationError > FeeRateEstimatorManager::GetFeeRateEstimate ( int  target,
bool  conservative 
) const
virtual

Get a combined fee rate estimate from the available fee rate estimators.

Combines both estimators, returning the lower of the block policy and mempool fee rate estimates. If the mempool fee rate estimator cannot produce an estimate, the block policy fee rate estimate is returned instead. An error is returned only if the block policy fee rate estimate is unavailable.

Parameters
[in]targetThe target within which the transaction should be confirmed.
[in]conservativeWhether to select a more conservative, potentially higher, fee rate estimate.
Returns
fee rate estimation, or an error on failure.

Definition at line 25 of file estimator_man.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IntervalFlush()

void FeeRateEstimatorManager::IntervalFlush ( )

Flush recorded data to disk.

Definition at line 57 of file estimator_man.cpp.

◆ MaximumTarget()

unsigned int FeeRateEstimatorManager::MaximumTarget ( ) const
virtual

Returns the maximum supported confirmation target from all fee rate estimators.

Definition at line 105 of file estimator_man.cpp.

Here is the caller graph for this function:

◆ MempoolLoadFailed()

void FeeRateEstimatorManager::MempoolLoadFailed ( )

Called when the mempool was not loaded from disk (the load failed, there was no mempool file, or -persistmempool=0), unless loading was interrupted by shutdown.

Definition at line 69 of file estimator_man.cpp.

◆ MempoolPolicyEstimatorBlocksStats()

std::vector< MinedBlockStats > FeeRateEstimatorManager::MempoolPolicyEstimatorBlocksStats ( ) const

Returns per-block weight statistics for the last MEMPOOL_HEALTH_WINDOW_BLOCKS mined blocks.

Definition at line 74 of file estimator_man.cpp.

Here is the caller graph for this function:

◆ MempoolTransactionsRemovedForBlock()

void FeeRateEstimatorManager::MempoolTransactionsRemovedForBlock ( const std::shared_ptr< const CBlock > &  block,
const std::vector< RemovedMempoolTransactionInfo > &  txs_removed_for_block,
unsigned int  block_height 
)
overrideprotectedvirtual

Reimplemented from CValidationInterface.

Definition at line 89 of file estimator_man.cpp.

◆ ShutdownFlush()

void FeeRateEstimatorManager::ShutdownFlush ( )

Flush recorded data to disk as part of shutdown sequence.

Definition at line 63 of file estimator_man.cpp.

◆ TransactionAddedToMempool()

void FeeRateEstimatorManager::TransactionAddedToMempool ( const NewMempoolTransactionInfo &  tx,
uint64_t   
)
overrideprotectedvirtual

Overridden from CValidationInterface.

Reimplemented from CValidationInterface.

Definition at line 79 of file estimator_man.cpp.

◆ TransactionRemovedFromMempool()

void FeeRateEstimatorManager::TransactionRemovedFromMempool ( const CTransactionRef &  tx,
MemPoolRemovalReason  reason,
uint64_t  mempool_sequence 
)
overrideprotectedvirtual

Notifies listeners of a transaction leaving mempool.

This notification fires for transactions that are removed from the mempool for the following reasons:

  • EXPIRY (expired from mempool after -mempoolexpiry hours)
  • SIZELIMIT (removed in size limiting if the mempool exceeds -maxmempool megabytes)
  • REORG (removed during a reorg)
  • CONFLICT (removed because it conflicts with in-block transaction)
  • REPLACED (removed due to RBF replacement)

This does not fire for transactions that are removed from the mempool because they have been included in a block. Any client that is interested in transactions removed from the mempool for inclusion in a block can learn about those transactions from the MempoolTransactionsRemovedForBlock notification.

Transactions that are removed from the mempool because they conflict with a transaction in the new block will have TransactionRemovedFromMempool events fired before the BlockConnected event is fired. If multiple blocks are connected in one step, then the ordering could be:

  • TransactionRemovedFromMempool(tx1 from block A)
  • TransactionRemovedFromMempool(tx2 from block A)
  • TransactionRemovedFromMempool(tx1 from block B)
  • TransactionRemovedFromMempool(tx2 from block B)
  • BlockConnected(A)
  • BlockConnected(B)

Called on a background thread.

Reimplemented from CValidationInterface.

Definition at line 84 of file estimator_man.cpp.

Member Data Documentation

◆ m_block_policy_estimator

std::unique_ptr<CBlockPolicyEstimator> FeeRateEstimatorManager::m_block_policy_estimator
private

Definition at line 108 of file estimator_man.h.

◆ m_mempool_estimator

std::unique_ptr<MemPoolFeeRateEstimator> FeeRateEstimatorManager::m_mempool_estimator
private

Definition at line 109 of file estimator_man.h.


The documentation for this class was generated from the following files: