Struct TargetDifficultyManager

Source
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

Source

pub fn new(capacity: usize) -> Self

Source

pub fn get(&self, hash: &H256) -> Option<U256>

Source

pub fn set(&self, hash: H256, difficulty: U256)

Source

pub fn target_difficulty<C>( &self, consensus: C, pow_config: &ProofOfWorkConfig, cur_hash: &H256, ) -> U256

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§

Source§

impl MallocSizeOf for TargetDifficultyManager

Source§

fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize

Measure the heap usage of all descendant heap-allocated structures, but not the space taken up by the value itself.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
§

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

§

fn vzip(self) -> V