Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

We will instantiate an instance of this class to track transactions that were included in a block. More...

Public Member Functions

 TxConfirmStats (const std::vector< double > &defaultBuckets, const std::map< double, unsigned int > &defaultBucketMap, unsigned int maxPeriods, double decay, unsigned int scale)
 Create new TxConfirmStats. More...
 
void ClearCurrent (unsigned int nBlockHeight)
 Roll the circular buffer for unconfirmed txs. More...
 
void Record (int blocksToConfirm, double val)
 Record a new transaction data point in the current block stats. More...
 
unsigned int NewTx (unsigned int nBlockHeight, double val)
 Record a new transaction entering the mempool. More...
 
void removeTx (unsigned int entryHeight, unsigned int nBestSeenHeight, unsigned int bucketIndex, bool inBlock)
 Remove a transaction from mempool tracking stats. More...
 
void UpdateMovingAverages ()
 Update our estimates by decaying our historical moving average and updating with the data gathered from the current block. More...
 
double EstimateMedianVal (int confTarget, double sufficientTxVal, double minSuccess, bool requireGreater, unsigned int nBlockHeight, EstimationResult *result=nullptr) const
 Calculate a feerate estimate. More...
 
unsigned int GetMaxConfirms () const
 Return the max number of confirms we're tracking. More...
 
void Write (CAutoFile &fileout) const
 Write state of estimation data to a file. More...
 
void Read (CAutoFile &filein, int nFileVersion, size_t numBuckets)
 Read saved state of estimation data from a file and replace all internal data structures and variables with this state. More...
 

Private Member Functions

void resizeInMemoryCounters (size_t newbuckets)
 

Private Attributes

const std::vector< double > & buckets
 
const std::map< double, unsigned int > & bucketMap
 
std::vector< double > txCtAvg
 
std::vector< std::vector< double > > confAvg
 
std::vector< std::vector< double > > failAvg
 
std::vector< double > avg
 
double decay
 
unsigned int scale
 
std::vector< std::vector< int > > unconfTxs
 
std::vector< int > oldUnconfTxs
 

Detailed Description

We will instantiate an instance of this class to track transactions that were included in a block.

We will lump transactions into a bucket according to their approximate feerate and then track how long it took for those txs to be included in a block

The tracking of unconfirmed (mempool) transactions is completely independent of the historical tracking of transactions that have been confirmed in a block.

Definition at line 72 of file fees.cpp.

Constructor & Destructor Documentation

◆ TxConfirmStats()

TxConfirmStats::TxConfirmStats ( const std::vector< double > &  defaultBuckets,
const std::map< double, unsigned int > &  defaultBucketMap,
unsigned int  maxPeriods,
double  decay,
unsigned int  scale 
)

Create new TxConfirmStats.

This is called by BlockPolicyEstimator's constructor with default values.

Parameters
defaultBucketscontains the upper limits for the bucket boundaries
maxPeriodsmax number of periods to track
decayhow much to decay the historical moving average per block

Definition at line 175 of file fees.cpp.

References avg, buckets, confAvg, decay, failAvg, resizeInMemoryCounters(), scale, and txCtAvg.

Member Function Documentation

◆ ClearCurrent()

void TxConfirmStats::ClearCurrent ( unsigned int  nBlockHeight)

Roll the circular buffer for unconfirmed txs.

Definition at line 208 of file fees.cpp.

References buckets, oldUnconfTxs, and unconfTxs.

◆ EstimateMedianVal()

double TxConfirmStats::EstimateMedianVal ( int  confTarget,
double  sufficientTxVal,
double  minSuccess,
bool  requireGreater,
unsigned int  nBlockHeight,
EstimationResult result = nullptr 
) const

Calculate a feerate estimate.

Find the lowest value bucket (or range of buckets to make sure we have enough data points) whose transactions still have sufficient likelihood of being confirmed within the target number of confirmations

Parameters
confTargettarget number of confirmations
sufficientTxValrequired average number of transactions per block in a bucket range
minSuccessthe success probability we require
requireGreaterreturn the lowest feerate such that all higher values pass minSuccess OR return the highest feerate such that all lower values fail minSuccess
nBlockHeightthe current block height

Definition at line 244 of file fees.cpp.

References avg, buckets, confAvg, decay, EstimationResult::decay, EstimatorBucket::end, BCLog::ESTIMATEFEE, EstimationResult::fail, failAvg, GetMaxConfirms(), EstimatorBucket::inMempool, EstimatorBucket::leftMempool, LogPrint, oldUnconfTxs, EstimationResult::pass, scale, EstimationResult::scale, EstimatorBucket::start, EstimatorBucket::totalConfirmed, txCtAvg, unconfTxs, and EstimatorBucket::withinTarget.

Referenced by CBlockPolicyEstimator::estimateRawFee().

◆ GetMaxConfirms()

unsigned int TxConfirmStats::GetMaxConfirms ( ) const
inline

Return the max number of confirms we're tracking.

Definition at line 162 of file fees.cpp.

References confAvg, and scale.

Referenced by EstimateMedianVal(), CBlockPolicyEstimator::estimateRawFee(), and resizeInMemoryCounters().

◆ NewTx()

unsigned int TxConfirmStats::NewTx ( unsigned int  nBlockHeight,
double  val 
)

Record a new transaction entering the mempool.

Definition at line 462 of file fees.cpp.

References bucketMap, and unconfTxs.

◆ Read()

void TxConfirmStats::Read ( CAutoFile filein,
int  nFileVersion,
size_t  numBuckets 
)

Read saved state of estimation data from a file and replace all internal data structures and variables with this state.

Definition at line 406 of file fees.cpp.

References avg, confAvg, decay, BCLog::ESTIMATEFEE, failAvg, LogPrint, resizeInMemoryCounters(), scale, and txCtAvg.

◆ Record()

void TxConfirmStats::Record ( int  blocksToConfirm,
double  val 
)

Record a new transaction data point in the current block stats.

Parameters
blocksToConfirmthe number of blocks it took this transaction to confirm
valthe feerate of the transaction
Warning
blocksToConfirm is 1-based and has to be >= 1

Definition at line 217 of file fees.cpp.

References avg, bucketMap, confAvg, scale, and txCtAvg.

◆ removeTx()

void TxConfirmStats::removeTx ( unsigned int  entryHeight,
unsigned int  nBestSeenHeight,
unsigned int  bucketIndex,
bool  inBlock 
)

Remove a transaction from mempool tracking stats.

Definition at line 470 of file fees.cpp.

References BCLog::ESTIMATEFEE, failAvg, LogPrint, oldUnconfTxs, scale, and unconfTxs.

◆ resizeInMemoryCounters()

void TxConfirmStats::resizeInMemoryCounters ( size_t  newbuckets)
private

Definition at line 198 of file fees.cpp.

References GetMaxConfirms(), oldUnconfTxs, and unconfTxs.

Referenced by Read(), and TxConfirmStats().

◆ UpdateMovingAverages()

void TxConfirmStats::UpdateMovingAverages ( )

Update our estimates by decaying our historical moving average and updating with the data gathered from the current block.

Definition at line 231 of file fees.cpp.

References avg, buckets, confAvg, decay, failAvg, and txCtAvg.

◆ Write()

void TxConfirmStats::Write ( CAutoFile fileout) const

Write state of estimation data to a file.

Definition at line 396 of file fees.cpp.

References avg, confAvg, decay, failAvg, fileout, scale, and txCtAvg.

Member Data Documentation

◆ avg

std::vector<double> TxConfirmStats::avg
private

Definition at line 94 of file fees.cpp.

Referenced by EstimateMedianVal(), Read(), Record(), TxConfirmStats(), UpdateMovingAverages(), and Write().

◆ bucketMap

const std::map<double, unsigned int>& TxConfirmStats::bucketMap
private

Definition at line 77 of file fees.cpp.

Referenced by NewTx(), and Record().

◆ buckets

const std::vector<double>& TxConfirmStats::buckets
private

Definition at line 76 of file fees.cpp.

Referenced by ClearCurrent(), EstimateMedianVal(), TxConfirmStats(), and UpdateMovingAverages().

◆ confAvg

std::vector<std::vector<double> > TxConfirmStats::confAvg
private

◆ decay

double TxConfirmStats::decay
private

Definition at line 99 of file fees.cpp.

Referenced by EstimateMedianVal(), Read(), TxConfirmStats(), UpdateMovingAverages(), and Write().

◆ failAvg

std::vector<std::vector<double> > TxConfirmStats::failAvg
private

Definition at line 90 of file fees.cpp.

Referenced by EstimateMedianVal(), Read(), removeTx(), TxConfirmStats(), UpdateMovingAverages(), and Write().

◆ oldUnconfTxs

std::vector<int> TxConfirmStats::oldUnconfTxs
private

Definition at line 109 of file fees.cpp.

Referenced by ClearCurrent(), EstimateMedianVal(), removeTx(), and resizeInMemoryCounters().

◆ scale

unsigned int TxConfirmStats::scale
private

Definition at line 102 of file fees.cpp.

Referenced by EstimateMedianVal(), GetMaxConfirms(), Read(), Record(), removeTx(), TxConfirmStats(), and Write().

◆ txCtAvg

std::vector<double> TxConfirmStats::txCtAvg
private

Definition at line 82 of file fees.cpp.

Referenced by EstimateMedianVal(), Read(), Record(), TxConfirmStats(), UpdateMovingAverages(), and Write().

◆ unconfTxs

std::vector<std::vector<int> > TxConfirmStats::unconfTxs
private

Definition at line 107 of file fees.cpp.

Referenced by ClearCurrent(), EstimateMedianVal(), NewTx(), removeTx(), and resizeInMemoryCounters().


The documentation for this class was generated from the following file:
Released under the MIT license