pub struct BlockWeightsCache { /* private fields */ }Expand description
A cache used to calculate block weight limits, the effective median and long term block weights.
These calculations require a lot of data from the database so by caching this data it reduces the load on the database.
Implementations§
Source§impl BlockWeightsCache
impl BlockWeightsCache
Sourcepub async fn init_from_chain_height<D: Database + Clone>(
chain_height: usize,
config: BlockWeightsCacheConfig,
database: D,
chain: Chain,
) -> Result<Self, ContextCacheError>
pub async fn init_from_chain_height<D: Database + Clone>( chain_height: usize, config: BlockWeightsCacheConfig, database: D, chain: Chain, ) -> Result<Self, ContextCacheError>
Initialize the BlockWeightsCache at the the given chain height.
Sourcepub async fn pop_blocks_main_chain<D: Database + Clone>(
&mut self,
numb_blocks: usize,
database: D,
) -> Result<(), ContextCacheError>
pub async fn pop_blocks_main_chain<D: Database + Clone>( &mut self, numb_blocks: usize, database: D, ) -> Result<(), ContextCacheError>
Pop some blocks from the top of the cache.
The cache will be returned to the state it would have been in numb_blocks ago.
Sourcepub fn new_block(
&mut self,
block_height: usize,
block_weight: usize,
long_term_weight: usize,
)
pub fn new_block( &mut self, block_height: usize, block_weight: usize, long_term_weight: usize, )
Add a new block to the cache.
The block_height MUST be one more than the last height the cache has
seen.
Sourcepub fn median_long_term_weight(&self) -> usize
pub fn median_long_term_weight(&self) -> usize
Returns the median long term weight over the last LONG_TERM_WINDOW blocks, or custom amount of blocks in the config.
Sourcepub fn median_short_term_weight(&self) -> usize
pub fn median_short_term_weight(&self) -> usize
Returns the median weight over the last SHORT_TERM_WINDOW blocks, or custom amount of blocks in the config.
Sourcepub fn effective_median_block_weight(&self, hf: HardFork) -> usize
pub fn effective_median_block_weight(&self, hf: HardFork) -> usize
Returns the effective median weight, used for block reward calculations and to calculate the block weight limit.
Sourcepub fn median_for_block_reward(&self, hf: HardFork) -> usize
pub fn median_for_block_reward(&self, hf: HardFork) -> usize
Returns the median weight used to calculate block reward punishment.
https://cuprate.github.io/monero-book/consensus_rules/blocks/reward.html#calculating-block-reward
Sourcepub fn fee_estimate_2021(
&self,
grace_blocks: u64,
hf: HardFork,
already_generated_coins: u64,
) -> Result<FeeEstimate, BoxError>
pub fn fee_estimate_2021( &self, grace_blocks: u64, hf: HardFork, already_generated_coins: u64, ) -> Result<FeeEstimate, BoxError>
Computes the 2021 fee estimates.
Trait Implementations§
Source§impl Clone for BlockWeightsCache
impl Clone for BlockWeightsCache
Source§fn clone(&self) -> BlockWeightsCache
fn clone(&self) -> BlockWeightsCache
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BlockWeightsCache
impl Debug for BlockWeightsCache
impl Eq for BlockWeightsCache
Source§impl PartialEq for BlockWeightsCache
impl PartialEq for BlockWeightsCache
impl StructuralPartialEq for BlockWeightsCache
Auto Trait Implementations§
impl Freeze for BlockWeightsCache
impl RefUnwindSafe for BlockWeightsCache
impl Send for BlockWeightsCache
impl Sync for BlockWeightsCache
impl Unpin for BlockWeightsCache
impl UnsafeUnpin for BlockWeightsCache
impl UnwindSafe for BlockWeightsCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 152 bytes