pub struct BlockPolicyEstimator {
pub cs_fee_estimator: Arc<Mutex<BlockPolicyEstimatorInner>>,
}Expand description
| \class BlockPolicyEstimator
|
| The BlockPolicyEstimator is used for estimating
| the feerate 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 feerates 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 feerate will
| be included in blocks before transactions of
| lower feerate.
|
| So for example if you wanted to know what
| feerate 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 feerate transactions and verifying
| that a sufficiently high percentage of them
| were confirmed within 5 blocks and then you
| would look at the next highest feerate bucket,
| and so on, stopping at the last bucket to pass
| the test.
|
| The average feerate of transactions in this
| bucket will give you an indication of the
| lowest feerate you can put on a transaction and
| still have a sufficiently high chance of being
| confirmed within your desired 5 blocks.
|
| –––––––––––
| Here is a brief description of the
| implementation: When a transaction enters the
| mempool, we track the height of the block chain
| at entry. All further calculations are
| conducted only on this set of “seen”
| transactions.
|
| Whenever a block comes in, we count the number
| of transactions in each bucket and the total
| amount of feerate paid in each bucket. Then we
| calculate how many blocks Y it took each
| transaction to be mined. We convert from
| a number of blocks to a number of periods Y’
| each encompassing “scale” blocks.
|
| This is tracked in 3 different data sets each
| up to a maximum number of periods. Within each
| data set we have an array of counters in each
| feerate bucket and we increment all the
| counters from Y’ up to max periods representing
| that a tx was successfully confirmed in less
| than or equal to that many periods.
|
| 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
| feerate bucket and the total number that were
| confirmed in each of the periods or less for
| any bucket.
|
| We save this history by keeping an
| exponentially decaying moving average of each
| one of these stats. This is done for
| a different decay in each of the 3 data sets to
| keep relevant data from different time
| horizons.
|
| Furthermore we also keep track of the number
| unmined (in mempool or left mempool without
| being included in a block) transactions in
| each bucket and for how many blocks they have
| been outstanding and use both of these numbers
| to increase the number of transactions we’ve
| seen in that feerate bucket when calculating an
| estimate for any number of confirmations below
| the number of blocks they’ve been outstanding.
|
| ––––––––––
| We want to be able to estimate feerates 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
Fields§
§cs_fee_estimator: Arc<Mutex<BlockPolicyEstimatorInner>>Implementations§
source§impl BlockPolicyEstimator
impl BlockPolicyEstimator
sourcepub fn block_span(&self) -> u32
pub fn block_span(&self) -> u32
| Number of blocks of data recorded while | fee estimates have been running |
sourcepub fn historical_block_span(&self) -> u32
pub fn historical_block_span(&self) -> u32
| Number of blocks of recorded fee estimate | data represented in saved data file |
source§impl BlockPolicyEstimator
impl BlockPolicyEstimator
sourcepub fn estimate_combined_fee(
&self,
conf_target: u32,
success_threshold: f64,
check_shorter_horizon: bool,
result: *mut EstimationResult
) -> f64
pub fn estimate_combined_fee( &self, conf_target: u32, success_threshold: f64, check_shorter_horizon: bool, result: *mut EstimationResult ) -> f64
| Helper for estimateSmartFee | | Return a fee estimate at the required | successThreshold from the shortest | time horizon which tracks confirmations | up to the desired target. If checkShorterHorizon | is requested, also allow short time | horizon estimates for a lower target | to reduce the given answer |
source§impl BlockPolicyEstimator
impl BlockPolicyEstimator
sourcepub fn estimate_conservative_fee(
&self,
double_target: u32,
result: *mut EstimationResult
) -> f64
pub fn estimate_conservative_fee( &self, double_target: u32, result: *mut EstimationResult ) -> f64
| Helper for estimateSmartFee | | Ensure that for a conservative estimate, | the | | DOUBLE_SUCCESS_PCT is also met at 2 | * target for any longer time horizons. |
source§impl BlockPolicyEstimator
impl BlockPolicyEstimator
sourcepub fn estimate_fee(&self, conf_target: i32) -> FeeRate
pub fn estimate_fee(&self, conf_target: i32) -> FeeRate
| DEPRECATED. Return a feerate estimate |
source§impl BlockPolicyEstimator
impl BlockPolicyEstimator
sourcepub fn estimate_raw_fee(
&self,
conf_target: i32,
success_threshold: f64,
horizon: FeeEstimateHorizon,
result: *mut EstimationResult
) -> FeeRate
pub fn estimate_raw_fee( &self, conf_target: i32, success_threshold: f64, horizon: FeeEstimateHorizon, result: *mut EstimationResult ) -> FeeRate
| Return a specific fee estimate calculation | with a given success threshold and time | horizon, and optionally return detailed | data about calculation |
source§impl BlockPolicyEstimator
impl BlockPolicyEstimator
sourcepub fn estimate_smart_fee(
&self,
conf_target: i32,
fee_calc: *mut FeeCalculation,
conservative: bool
) -> FeeRate
pub fn estimate_smart_fee( &self, conf_target: i32, fee_calc: *mut FeeCalculation, conservative: bool ) -> FeeRate
| Estimate feerate needed to get be included | in a block within confTarget blocks. | If no answer can be given at confTarget, | return an estimate at the closest target | where one can be given. ‘conservative’ | estimates are valid over longer time | horizons also. | | estimateSmartFee returns the max of | the feerates calculated with a 60% threshold | required at target / 2, an 85% threshold | required at target and a 95% threshold | required at 2 * target. | | Each calculation is performed at the | shortest time horizon which tracks | the required target. | | Conservative estimates, however, | required the 95% threshold at 2 * target | be met for any longer time horizons also. |
source§impl BlockPolicyEstimator
impl BlockPolicyEstimator
sourcepub fn flush_unconfirmed(&mut self)
pub fn flush_unconfirmed(&mut self)
| Empty mempool transactions on shutdown | to record failure to confirm for txs | still in mempool |
source§impl BlockPolicyEstimator
impl BlockPolicyEstimator
sourcepub fn highest_target_tracked(&self, horizon: FeeEstimateHorizon) -> u32
pub fn highest_target_tracked(&self, horizon: FeeEstimateHorizon) -> u32
| Calculation of highest target that | estimates are tracked for |
source§impl BlockPolicyEstimator
impl BlockPolicyEstimator
sourcepub fn max_usable_estimate(&self) -> u32
pub fn max_usable_estimate(&self) -> u32
| Calculation of highest target that | reasonable estimate can be provided | for |
source§impl BlockPolicyEstimator
impl BlockPolicyEstimator
sourcepub fn process_block(
self: Arc<Self>,
n_block_height: u32,
entries: &mut Vec<*const TxMemPoolEntry>
)
pub fn process_block( self: Arc<Self>, n_block_height: u32, entries: &mut Vec<*const TxMemPoolEntry> )
| Process all the transactions that have | been included in a block |
source§impl BlockPolicyEstimator
impl BlockPolicyEstimator
sourcepub fn process_block_tx(
&mut self,
n_block_height: u32,
entry: *const TxMemPoolEntry
) -> bool
pub fn process_block_tx( &mut self, n_block_height: u32, entry: *const TxMemPoolEntry ) -> bool
| Process a transaction confirmed in | a block |
source§impl BlockPolicyEstimator
impl BlockPolicyEstimator
sourcepub fn process_transaction(
&mut self,
entry: &TxMemPoolEntry,
valid_fee_estimate: bool
)
pub fn process_transaction( &mut self, entry: &TxMemPoolEntry, valid_fee_estimate: bool )
| Process a transaction accepted to the | mempool |
source§impl BlockPolicyEstimator
impl BlockPolicyEstimator
sourcepub fn remove_tx(&mut self, hash: u256, in_block: bool) -> bool
pub fn remove_tx(&mut self, hash: u256, in_block: bool) -> bool
| Remove a transaction from the mempool | tracking stats | | This function is called from | CTxMemPool::removeUnchecked to ensure txs | removed from the mempool for any reason are no | longer tracked. Txs that were part of a block | have already been removed in processBlockTx to | ensure they are never double tracked, but it is | of no harm to try to remove them again.