referrerpolicy=no-referrer-when-downgrade
sc_consensus_epochs

Type Alias EpochChangesFor

Source
pub type EpochChangesFor<Block, Epoch> = EpochChanges<<Block as BlockT>::Hash, NumberFor<Block>, Epoch>;
Expand description

Type alias to produce the epoch-changes tree from a block type.

Aliased Type§

struct EpochChangesFor<Block, Epoch> { /* private fields */ }

Implementations

Source§

impl<Hash, Number, E: Epoch> EpochChanges<Hash, Number, E>
where Hash: PartialEq + Ord + AsRef<[u8]> + AsMut<[u8]> + Copy + Debug, Number: Ord + One + Zero + Add<Output = Number> + Sub<Output = Number> + Copy + Debug,

Source

pub fn new() -> Self

Create a new epoch change.

Source

pub fn rebalance(&mut self)

Rebalances the tree of epoch changes so that it is sorted by length of fork (longest fork first).

Source

pub fn map<B, F>(self, f: F) -> EpochChanges<Hash, Number, B>
where B: Epoch<Slot = E::Slot>, F: FnMut(&Hash, &Number, E) -> B,

Map the epoch changes from one storing data to a different one.

Source

pub fn prune_finalized<D: IsDescendentOfBuilder<Hash>>( &mut self, descendent_of_builder: D, hash: &Hash, number: Number, slot: E::Slot, ) -> Result<(), Error<D::Error>>

Prune out finalized epochs, except for the ancestor of the finalized block. The given slot should be the slot number at which the finalized block was authored.

Source

pub fn epoch(&self, id: &EpochIdentifier<Hash, Number>) -> Option<&E>

Get a reference to an epoch with given identifier.

Source

pub fn viable_epoch<G>( &self, descriptor: &ViableEpochDescriptor<Hash, Number, E>, make_genesis: G, ) -> Option<ViableEpoch<E, &E>>
where G: FnOnce(E::Slot) -> E,

Get a reference to a viable epoch with given descriptor.

Source

pub fn epoch_mut( &mut self, id: &EpochIdentifier<Hash, Number>, ) -> Option<&mut E>

Get a mutable reference to an epoch with given identifier.

Source

pub fn viable_epoch_mut<G>( &mut self, descriptor: &ViableEpochDescriptor<Hash, Number, E>, make_genesis: G, ) -> Option<ViableEpoch<E, &mut E>>
where G: FnOnce(E::Slot) -> E,

Get a mutable reference to a viable epoch with given descriptor.

Source

pub fn epoch_data<G>( &self, descriptor: &ViableEpochDescriptor<Hash, Number, E>, make_genesis: G, ) -> Option<E>
where G: FnOnce(E::Slot) -> E, E: Clone,

Get the epoch data from an epoch descriptor.

Note that this function ignores the fact that an genesis epoch might need to be imported. Mostly useful for testing.

Source

pub fn epoch_data_for_child_of<D: IsDescendentOfBuilder<Hash>, G>( &self, descendent_of_builder: D, parent_hash: &Hash, parent_number: Number, slot: E::Slot, make_genesis: G, ) -> Result<Option<E>, Error<D::Error>>
where G: FnOnce(E::Slot) -> E, E: Clone,

Finds the epoch data for a child of the given block. Similar to epoch_descriptor_for_child_of but returns the full data.

Note that this function ignores the fact that an genesis epoch might need to be imported. Mostly useful for testing.

Source

pub fn epoch_descriptor_for_child_of<D: IsDescendentOfBuilder<Hash>>( &self, descendent_of_builder: D, parent_hash: &Hash, parent_number: Number, slot: E::Slot, ) -> Result<Option<ViableEpochDescriptor<Hash, Number, E>>, Error<D::Error>>

Finds the epoch for a child of the given block, assuming the given slot number.

If the returned epoch is an UnimportedGenesis epoch, it should be imported into the tree.

Source

pub fn import<D: IsDescendentOfBuilder<Hash>>( &mut self, descendent_of_builder: D, hash: Hash, number: Number, parent_hash: Hash, epoch: IncrementedEpoch<E>, ) -> Result<(), Error<D::Error>>

Import a new epoch-change, signalled at the given block.

This assumes that the given block is prospective (i.e. has not been imported yet), but its parent has. This is why the parent hash needs to be provided.

Source

pub fn reset( &mut self, parent_hash: Hash, hash: Hash, number: Number, current: E, next: E, )

Reset to a specified pair of epochs, as if they were announced at blocks parent_hash and hash.

Source

pub fn revert<D: IsDescendentOfBuilder<Hash>>( &mut self, descendent_of_builder: D, hash: Hash, number: Number, )

Revert to a specified block given its hash and number. This removes all the epoch changes information that were announced by all the given block descendants.

Source

pub fn tree(&self) -> &ForkTree<Hash, Number, PersistedEpochHeader<E>>

Return the inner fork tree (mostly useful for testing)

Trait Implementations

Source§

impl<Hash: Clone, Number: Clone, E: Clone + Epoch> Clone for EpochChanges<Hash, Number, E>

Source§

fn clone(&self) -> EpochChanges<Hash, Number, E>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Hash: Debug, Number: Debug, E: Debug + Epoch> Debug for EpochChanges<Hash, Number, E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Hash, Number, E: Epoch> Decode for EpochChanges<Hash, Number, E>
where ForkTree<Hash, Number, PersistedEpochHeader<E>>: Decode, BTreeMap<(Hash, Number), PersistedEpoch<E>>: Decode,

Source§

fn decode<__CodecInputEdqy: Input>( __codec_input_edqy: &mut __CodecInputEdqy, ) -> Result<Self, Error>

Attempt to deserialise the value from input.
§

fn decode_into<I>( input: &mut I, dst: &mut MaybeUninit<Self>, ) -> Result<DecodeFinished, Error>
where I: Input,

Attempt to deserialize the value from input into a pre-allocated piece of memory. Read more
§

fn skip<I>(input: &mut I) -> Result<(), Error>
where I: Input,

Attempt to skip the encoded value from input. Read more
§

fn encoded_fixed_size() -> Option<usize>

Returns the fixed encoded size of the type. Read more
Source§

impl<Hash, Number, E: Epoch> Default for EpochChanges<Hash, Number, E>
where Hash: PartialEq + Ord, Number: Ord,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<Hash, Number, E: Epoch> Encode for EpochChanges<Hash, Number, E>
where ForkTree<Hash, Number, PersistedEpochHeader<E>>: Encode, BTreeMap<(Hash, Number), PersistedEpoch<E>>: Encode,

Source§

fn size_hint(&self) -> usize

If possible give a hint of expected size of the encoding. Read more
Source§

fn encode_to<__CodecOutputEdqy: Output + ?Sized>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy, )

Convert self to a slice and append it to the destination.
§

fn encode(&self) -> Vec<u8>

Convert self to an owned vector.
§

fn using_encoded<R, F>(&self, f: F) -> R
where F: FnOnce(&[u8]) -> R,

Convert self to a slice and then invoke the given closure with it.
§

fn encoded_size(&self) -> usize

Calculates the encoded size. Read more
Source§

impl<Hash, Number, E: Epoch> EncodeLike for EpochChanges<Hash, Number, E>
where ForkTree<Hash, Number, PersistedEpochHeader<E>>: Encode, BTreeMap<(Hash, Number), PersistedEpoch<E>>: Encode,