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

source

pub fn block_span(&self) -> u32

| Number of blocks of data recorded while | fee estimates have been running |

source

pub fn historical_block_span(&self) -> u32

| Number of blocks of recorded fee estimate | data represented in saved data file |

source§

impl BlockPolicyEstimator

source

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

source

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

source

pub fn estimate_fee(&self, conf_target: i32) -> FeeRate

| DEPRECATED. Return a feerate estimate |

source§

impl BlockPolicyEstimator

source

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

source

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

source

pub fn new() -> Self

source§

impl BlockPolicyEstimator

source

pub fn flush_unconfirmed(&mut self)

| Empty mempool transactions on shutdown | to record failure to confirm for txs | still in mempool |

source

pub fn flush(&mut self)

| Drop still unconfirmed transactions | and record current estimations, if | the fee estimation file is present. |

source§

impl BlockPolicyEstimator

source

pub fn highest_target_tracked(&self, horizon: FeeEstimateHorizon) -> u32

| Calculation of highest target that | estimates are tracked for |

source§

impl BlockPolicyEstimator

source

pub fn max_usable_estimate(&self) -> u32

| Calculation of highest target that | reasonable estimate can be provided | for |

source§

impl BlockPolicyEstimator

source

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

source

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

source

pub fn process_transaction( &mut self, entry: &TxMemPoolEntry, valid_fee_estimate: bool )

| Process a transaction accepted to the | mempool |

source§

impl BlockPolicyEstimator

source

pub fn read(&mut self, filein: &mut AutoFile) -> bool

| Read estimation data from a file |

source§

impl BlockPolicyEstimator

source

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.

source§

impl BlockPolicyEstimator

source

pub fn write(&self, fileout: &mut AutoFile) -> bool

| Write estimation data to a file |

Trait Implementations§

source§

impl Default for BlockPolicyEstimator

source§

fn default() -> Self

| Create new BlockPolicyEstimator and | initialize stats tracking classes | with default values |

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T, U> CastInto<U> for Twhere U: CastFrom<T>,

§

unsafe fn cast_into(self) -> U

Performs the conversion. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> StaticUpcast<T> for T

§

unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>

Convert type of a const pointer. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V