![]() |
Dash Core
0.12.2.1
P2P Digital Currency
|
#include <fees.h>
Classes | |
struct | TxStatsInfo |
Public Member Functions | |
CBlockPolicyEstimator (const CFeeRate &minRelayFee) | |
void | processBlock (unsigned int nBlockHeight, std::vector< CTxMemPoolEntry > &entries, bool fCurrentEstimate) |
void | processBlockTx (unsigned int nBlockHeight, const CTxMemPoolEntry &entry) |
void | processTransaction (const CTxMemPoolEntry &entry, bool fCurrentEstimate) |
void | removeTx (uint256 hash) |
bool | isFeeDataPoint (const CFeeRate &fee, double pri) |
bool | isPriDataPoint (const CFeeRate &fee, double pri) |
CFeeRate | estimateFee (int confTarget) |
CFeeRate | estimateSmartFee (int confTarget, int *answerFoundAtTarget, const CTxMemPool &pool) |
double | estimatePriority (int confTarget) |
double | estimateSmartPriority (int confTarget, int *answerFoundAtTarget, const CTxMemPool &pool) |
void | Write (CAutoFile &fileout) |
void | Read (CAutoFile &filein) |
Private Attributes | |
CFeeRate | minTrackedFee |
double | minTrackedPriority |
Passed to constructor to avoid dependency on main. More... | |
unsigned int | nBestSeenHeight |
Set to AllowFreeThreshold. More... | |
std::map< uint256, TxStatsInfo > | mapMemPoolTxs |
TxConfirmStats | feeStats |
TxConfirmStats | priStats |
CFeeRate | feeLikely |
CFeeRate | feeUnlikely |
double | priLikely |
double | priUnlikely |
We want to be able to estimate fees or priorities that are needed on tx's to be included in a certain number of blocks. Every time a block is added to the best chain, this class records stats on the transactions included in that block
The BlockPolicyEstimator is used for estimating the fee or priority needed for a transaction to be included in a block within a certain number of blocks.
At a high level the algorithm works by grouping transactions into buckets based on having similar priorities or fees and then tracking how long it takes transactions in the various buckets to be mined. It operates under the assumption that in general transactions of higher fee/priority will be included in blocks before transactions of lower fee/priority. So for example if you wanted to know what fee you should put on a transaction to be included in a block within the next 5 blocks, you would start by looking at the bucket with the highest fee transactions and verifying that a sufficiently high percentage of them were confirmed within 5 blocks and then you would look at the next highest fee bucket, and so on, stopping at the last bucket to pass the test. The average fee of transactions in this bucket will give you an indication of the lowest fee you can put on a transaction and still have a sufficiently high chance of being confirmed within your desired 5 blocks.
When a transaction enters the mempool or is included within a block we decide whether it can be used as a data point for fee estimation, priority estimation or neither. If the value of exactly one of those properties was below the required minimum it can be used to estimate the other. In addition, if a priori our estimation code would indicate that the transaction would be much more quickly included in a block because of one of the properties compared to the other, we can also decide to use it as an estimate for that property.
Here is a brief description of the implementation for fee estimation. When a transaction that counts for fee estimation enters the mempool, we track the height of the block chain at entry. Whenever a block comes in, we count the number of transactions in each bucket and the total amount of fee paid in each bucket. Then we calculate how many blocks Y it took each transaction to be mined and we track an array of counters in each bucket for how long it to took transactions to get confirmed from 1 to a max of 25 and we increment all the counters from Y up to 25. This is because for any number Z>=Y the transaction was successfully mined within Z blocks. We want to save a history of this information, so at any time we have a counter of the total number of transactions that happened in a given fee bucket and the total number that were confirmed in each number 1-25 blocks or less for any bucket. We save this history by keeping an exponentially decaying moving average of each one of these stats. Furthermore we also keep track of the number unmined (in mempool) transactions in each bucket and for how many blocks they have been outstanding and use that to increase the number of transactions we've seen in that fee bucket when calculating an estimate for any number of confirmations below the number of blocks they've been outstanding.
CBlockPolicyEstimator::CBlockPolicyEstimator | ( | const CFeeRate & | minRelayFee | ) |
CFeeRate CBlockPolicyEstimator::estimateFee | ( | int | confTarget | ) |
Return a fee estimate
Definition at line 492 of file fees.cpp.
Referenced by CTxMemPool::estimateFee().
double CBlockPolicyEstimator::estimatePriority | ( | int | confTarget | ) |
Return a priority estimate
Definition at line 533 of file fees.cpp.
Referenced by CTxMemPool::estimatePriority().
CFeeRate CBlockPolicyEstimator::estimateSmartFee | ( | int | confTarget, |
int * | answerFoundAtTarget, | ||
const CTxMemPool & | pool | ||
) |
Estimate fee rate needed to get be included in a block within confTarget blocks. If no answer can be given at confTarget, return an estimate at the lowest target where one can be given.
Definition at line 506 of file fees.cpp.
Referenced by CTxMemPool::estimateSmartFee().
double CBlockPolicyEstimator::estimateSmartPriority | ( | int | confTarget, |
int * | answerFoundAtTarget, | ||
const CTxMemPool & | pool | ||
) |
Estimate priority needed to get be included in a block within confTarget blocks. If no answer can be given at confTarget, return an estimate at the lowest target where one can be given.
Definition at line 542 of file fees.cpp.
Referenced by CTxMemPool::estimateSmartPriority().
bool CBlockPolicyEstimator::isFeeDataPoint | ( | const CFeeRate & | fee, |
double | pri | ||
) |
Is this transaction likely included in a block because of its fee?
Definition at line 326 of file fees.cpp.
Referenced by processBlockTx(), and processTransaction().
bool CBlockPolicyEstimator::isPriDataPoint | ( | const CFeeRate & | fee, |
double | pri | ||
) |
Is this transaction likely included in a block because of its priority?
Definition at line 335 of file fees.cpp.
Referenced by processBlockTx(), and processTransaction().
void CBlockPolicyEstimator::processBlock | ( | unsigned int | nBlockHeight, |
std::vector< CTxMemPoolEntry > & | entries, | ||
bool | fCurrentEstimate | ||
) |
Process all the transactions that have been included in a block
Definition at line 434 of file fees.cpp.
Referenced by CTxMemPool::removeForBlock().
void CBlockPolicyEstimator::processBlockTx | ( | unsigned int | nBlockHeight, |
const CTxMemPoolEntry & | entry | ||
) |
Process a transaction confirmed in a block
Definition at line 397 of file fees.cpp.
Referenced by processBlock().
void CBlockPolicyEstimator::processTransaction | ( | const CTxMemPoolEntry & | entry, |
bool | fCurrentEstimate | ||
) |
Process a transaction accepted to the mempool
Definition at line 344 of file fees.cpp.
Referenced by CTxMemPool::addUnchecked().
void CBlockPolicyEstimator::Read | ( | CAutoFile & | filein | ) |
Read estimation data from a file
Definition at line 573 of file fees.cpp.
Referenced by CTxMemPool::ReadFeeEstimates().
void CBlockPolicyEstimator::removeTx | ( | uint256 | hash | ) |
Remove a transaction from the mempool tracking stats
Definition at line 285 of file fees.cpp.
Referenced by CTxMemPool::removeUnchecked().
void CBlockPolicyEstimator::Write | ( | CAutoFile & | fileout | ) |
Write estimation data to a file
Definition at line 566 of file fees.cpp.
Referenced by CTxMemPool::WriteFeeEstimates().
|
private |
Breakpoints to help determine whether a transaction was confirmed by priority or Fee
Definition at line 286 of file fees.h.
Referenced by CBlockPolicyEstimator(), isFeeDataPoint(), and processBlock().
|
private |
Classes to track historical data on transaction confirmations
Definition at line 283 of file fees.h.
Referenced by CBlockPolicyEstimator(), estimateFee(), estimateSmartFee(), processBlock(), processBlockTx(), processTransaction(), Read(), and Write().
|
private |
Definition at line 286 of file fees.h.
Referenced by CBlockPolicyEstimator(), and processBlock().
|
private |
Definition at line 280 of file fees.h.
Referenced by processBlock(), processTransaction(), and removeTx().
|
private |
Definition at line 268 of file fees.h.
Referenced by CBlockPolicyEstimator(), and isFeeDataPoint().
|
private |
Passed to constructor to avoid dependency on main.
Definition at line 269 of file fees.h.
Referenced by CBlockPolicyEstimator(), and isPriDataPoint().
|
private |
Set to AllowFreeThreshold.
Definition at line 270 of file fees.h.
Referenced by estimateFee(), estimatePriority(), estimateSmartFee(), estimateSmartPriority(), processBlock(), processTransaction(), Read(), removeTx(), and Write().
|
private |
Definition at line 287 of file fees.h.
Referenced by CBlockPolicyEstimator(), isPriDataPoint(), and processBlock().
|
private |
Definition at line 283 of file fees.h.
Referenced by CBlockPolicyEstimator(), estimatePriority(), estimateSmartPriority(), processBlock(), processBlockTx(), processTransaction(), Read(), and Write().
|
private |
Definition at line 287 of file fees.h.
Referenced by CBlockPolicyEstimator(), and processBlock().