Bitcoin Core 31.99.0
P2P Digital Currency
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
MemPoolFeeRateEstimator Class Reference

Estimate the fee rate required for a transaction to be included in the next block. More...

#include <mempool_estimator.h>

Collaboration diagram for MemPoolFeeRateEstimator:
[legend]

Classes

struct  Percentiles
 

Public Types

enum class  MempoolHealth { HEALTHY , INSUFFICIENT_DATA , LOW_COVERAGE }
 Health of the recent mined-block window for fee rate estimation. More...
 

Public Member Functions

 MemPoolFeeRateEstimator (fs::path mempool_estimator_file_path, const CTxMemPool &mempool, ChainstateManager &chainman)
 
 ~MemPoolFeeRateEstimator ()=default
 
util::Expected< FeeRateEstimation, FeeRateEstimationErrorEstimateFeeRate (bool conservative) const EXCLUSIVE_LOCKS_REQUIRED(!cs)
 
unsigned int MaximumTarget () const
 
std::vector< MinedBlockStatsGetPrevBlockData () const EXCLUSIVE_LOCKS_REQUIRED(!cs)
 
void MempoolTxsRemovedForBlock (const std::shared_ptr< const CBlock > &block, const std::vector< RemovedMempoolTransactionInfo > &txs_removed_for_block, unsigned int block_height) EXCLUSIVE_LOCKS_REQUIRED(!cs)
 
MempoolHealth GetMempoolHealth () const EXCLUSIVE_LOCKS_REQUIRED(!cs)
 
bool IsMempoolHealthy () const EXCLUSIVE_LOCKS_REQUIRED(!cs)
 Checks if recent mined blocks indicate a healthy mempool state. More...
 
void FlushMinedBlockStats () EXCLUSIVE_LOCKS_REQUIRED(!cs)
 
bool Read (AutoFile &file) EXCLUSIVE_LOCKS_REQUIRED(!cs)
 Deserialize mined-block stats without taking ownership of file. More...
 
bool Write (AutoFile &file) const EXCLUSIVE_LOCKS_REQUIRED(!cs)
 Serialize mined-block stats without taking ownership of file. More...
 

Static Public Member Functions

static Percentiles CalculateMaxWeightPercentiles (std::span< const FeePerVSize > chunk_feerates)
 Calculate the 50th and 75th percentile fee rates from block template chunks, sorted in descending mining-score order. More...
 

Private Member Functions

void ReadFromDisk () EXCLUSIVE_LOCKS_REQUIRED(!cs)
 
std::vector< MinedBlockStats > m_prev_mined_blocks GUARDED_BY (cs)
 Tracks weight statistics for the last MEMPOOL_HEALTH_WINDOW_BLOCKS mined blocks. More...
 
uint256 m_mined_blocks_tip_hash GUARDED_BY (cs)
 
MemPoolFeeRateEstimatorCache m_cache GUARDED_BY (cs)
 

Private Attributes

const CTxMemPoolm_mempool
 
ChainstateManagerm_chainman
 
Mutex cs
 
const fs::path m_mempool_estimator_file_path
 

Detailed Description

Estimate the fee rate required for a transaction to be included in the next block.

Uses Bitcoin Core's block-building algorithm to generate a block template from the mempool, then calculates percentile fee rates from the selected chunks: the 75th percentile is returned as the economical estimate and the 50th percentile as the conservative estimate.

Definition at line 87 of file mempool_estimator.h.

Member Enumeration Documentation

◆ MempoolHealth

Health of the recent mined-block window for fee rate estimation.

Enumerator
HEALTHY 

Recent blocks represent the mempool well enough to estimate a fee rate.

INSUFFICIENT_DATA 

Too few recent mined blocks to estimate a fee rate.

LOW_COVERAGE 

Recent blocks include too few mempool transactions to estimate a fee rate.

Definition at line 126 of file mempool_estimator.h.

Constructor & Destructor Documentation

◆ MemPoolFeeRateEstimator()

MemPoolFeeRateEstimator::MemPoolFeeRateEstimator ( fs::path  mempool_estimator_file_path,
const CTxMemPool mempool,
ChainstateManager chainman 
)

Definition at line 162 of file mempool_estimator.cpp.

Here is the call graph for this function:

◆ ~MemPoolFeeRateEstimator()

MemPoolFeeRateEstimator::~MemPoolFeeRateEstimator ( )
default

Member Function Documentation

◆ CalculateMaxWeightPercentiles()

MemPoolFeeRateEstimator::Percentiles MemPoolFeeRateEstimator::CalculateMaxWeightPercentiles ( std::span< const FeePerVSize chunk_feerates)
static

Calculate the 50th and 75th percentile fee rates from block template chunks, sorted in descending mining-score order.

A percentile is left empty when the chunks cannot cover the corresponding fraction of a block.

Parameters
[in]chunk_feeratesBlock template chunk fee rates sorted by descending mining score.

Definition at line 95 of file mempool_estimator.cpp.

Here is the caller graph for this function:

◆ EstimateFeeRate()

util::Expected< FeeRateEstimation, FeeRateEstimationError > MemPoolFeeRateEstimator::EstimateFeeRate ( bool  conservative) const

Definition at line 360 of file mempool_estimator.cpp.

Here is the call graph for this function:

◆ FlushMinedBlockStats()

void MemPoolFeeRateEstimator::FlushMinedBlockStats ( )

Definition at line 259 of file mempool_estimator.cpp.

Here is the call graph for this function:

◆ GetMempoolHealth()

MemPoolFeeRateEstimator::MempoolHealth MemPoolFeeRateEstimator::GetMempoolHealth ( ) const

Definition at line 323 of file mempool_estimator.cpp.

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

◆ GetPrevBlockData()

std::vector< MinedBlockStats > MemPoolFeeRateEstimator::GetPrevBlockData ( ) const
inline

Definition at line 115 of file mempool_estimator.h.

◆ GUARDED_BY() [1/3]

std::vector< MinedBlockStats > m_prev_mined_blocks MemPoolFeeRateEstimator::GUARDED_BY ( cs  )
private

Tracks weight statistics for the last MEMPOOL_HEALTH_WINDOW_BLOCKS mined blocks.

◆ GUARDED_BY() [2/3]

uint256 m_mined_blocks_tip_hash MemPoolFeeRateEstimator::GUARDED_BY ( cs  )
private

◆ GUARDED_BY() [3/3]

MemPoolFeeRateEstimatorCache m_cache MemPoolFeeRateEstimator::GUARDED_BY ( cs  )
mutableprivate

◆ IsMempoolHealthy()

bool MemPoolFeeRateEstimator::IsMempoolHealthy ( ) const
inline

Checks if recent mined blocks indicate a healthy mempool state.

Definition at line 136 of file mempool_estimator.h.

Here is the call graph for this function:

◆ MaximumTarget()

unsigned int MemPoolFeeRateEstimator::MaximumTarget ( ) const
inline

Definition at line 110 of file mempool_estimator.h.

◆ MempoolTxsRemovedForBlock()

void MemPoolFeeRateEstimator::MempoolTxsRemovedForBlock ( const std::shared_ptr< const CBlock > &  block,
const std::vector< RemovedMempoolTransactionInfo > &  txs_removed_for_block,
unsigned int  block_height 
)

Definition at line 294 of file mempool_estimator.cpp.

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

◆ Read()

bool MemPoolFeeRateEstimator::Read ( AutoFile file)

Deserialize mined-block stats without taking ownership of file.

Definition at line 188 of file mempool_estimator.cpp.

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

◆ ReadFromDisk()

void MemPoolFeeRateEstimator::ReadFromDisk ( )
private

Definition at line 172 of file mempool_estimator.cpp.

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

◆ Write()

bool MemPoolFeeRateEstimator::Write ( AutoFile file) const

Serialize mined-block stats without taking ownership of file.

Callers must explicitly close file and check for errors after writing.

Definition at line 246 of file mempool_estimator.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ cs

Mutex MemPoolFeeRateEstimator::cs
mutableprivate

Definition at line 152 of file mempool_estimator.h.

◆ m_chainman

ChainstateManager& MemPoolFeeRateEstimator::m_chainman
private

Definition at line 151 of file mempool_estimator.h.

◆ m_mempool

const CTxMemPool& MemPoolFeeRateEstimator::m_mempool
private

Definition at line 150 of file mempool_estimator.h.

◆ m_mempool_estimator_file_path

const fs::path MemPoolFeeRateEstimator::m_mempool_estimator_file_path
private

Definition at line 154 of file mempool_estimator.h.


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