pub struct TargetDifficultyManager { /* private fields */ }
Expand description
This is a data structure to cache the computed target difficulty of a adjustment period. Each element is indexed by the hash of the upper boundary block of the period.
Implementations§
Source§impl TargetDifficultyManager
impl TargetDifficultyManager
pub fn new(capacity: usize) -> Self
pub fn get(&self, hash: &H256) -> Option<U256>
pub fn set(&self, hash: H256, difficulty: U256)
Sourcepub fn target_difficulty<C>(
&self,
consensus: C,
pow_config: &ProofOfWorkConfig,
cur_hash: &H256,
) -> U256where
C: ConsensusProvider,
pub fn target_difficulty<C>(
&self,
consensus: C,
pow_config: &ProofOfWorkConfig,
cur_hash: &H256,
) -> U256where
C: ConsensusProvider,
This function computes the target difficulty of the next period
based on the current period. cur_hash
should be the hash of
the block at the current period upper boundary and it must have been
inserted to BlockDataManager, otherwise the function will panic.
num_blocks_in_epoch
is a function that returns the epoch size
under the epoch view of a given block.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for TargetDifficultyManager
impl !RefUnwindSafe for TargetDifficultyManager
impl Send for TargetDifficultyManager
impl Sync for TargetDifficultyManager
impl Unpin for TargetDifficultyManager
impl UnwindSafe for TargetDifficultyManager
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
Mutably borrows from an owned value. Read more