Struct sc_consensus_epochs::EpochChanges [−][src]
pub struct EpochChanges<Hash, Number, E: Epoch> { /* fields omitted */ }
Expand description
Tree of all epoch changes across all seen forks. Data stored in tree is the hash and block number of the block signaling the epoch change, and the epoch that was signalled at that block.
The first epoch, epoch_0, is special cased by saying that it starts at slot number of the first block in the chain. When bootstrapping a chain, there can be multiple competing block #1s, so we have to ensure that the overlayed DAG doesn’t get confused.
The first block of every epoch should be producing a descriptor for the next epoch - this is checked in higher-level code. So the first block of epoch_0 contains a descriptor for epoch_1. We special-case these and bundle them together in the same DAG entry, pinned to a specific block #1.
Further epochs (epoch_2, …, epoch_n) each get their own entry.
Implementations
Rebalances the tree of epoch changes so that it is sorted by length of fork (longest fork first).
Map the epoch changes from one storing data to a different one.
pub fn prune_finalized<D: IsDescendentOfBuilder<Hash>>(
&mut self,
descendent_of_builder: D,
hash: &Hash,
number: Number,
slot: E::Slot
) -> Result<(), Error<D::Error>>
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.
Get a reference to an epoch with given identifier.
pub fn viable_epoch<G>(
&self,
descriptor: &ViableEpochDescriptor<Hash, Number, E>,
make_genesis: G
) -> Option<ViableEpoch<E, &E>> where
G: FnOnce(E::Slot) -> E,
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.
Get a mutable reference to an epoch with given identifier.
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,
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.
pub fn epoch_data<G>(
&self,
descriptor: &ViableEpochDescriptor<Hash, Number, E>,
make_genesis: G
) -> Option<E> where
G: FnOnce(E::Slot) -> E,
E: Clone,
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.
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.
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>>
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.
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>>
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.
Return the inner fork tree.
Trait Implementations
impl<Hash, Number, E: Epoch> Decode for EpochChanges<Hash, Number, E> where
ForkTree<Hash, Number, PersistedEpochHeader<E>>: Decode,
ForkTree<Hash, Number, PersistedEpochHeader<E>>: Decode,
BTreeMap<(Hash, Number), PersistedEpoch<E>>: Decode,
BTreeMap<(Hash, Number), PersistedEpoch<E>>: Decode,
impl<Hash, Number, E: Epoch> Decode for EpochChanges<Hash, Number, E> where
ForkTree<Hash, Number, PersistedEpochHeader<E>>: Decode,
ForkTree<Hash, Number, PersistedEpochHeader<E>>: Decode,
BTreeMap<(Hash, Number), PersistedEpoch<E>>: Decode,
BTreeMap<(Hash, Number), PersistedEpoch<E>>: Decode,
Attempt to deserialise the value from input.
Attempt to skip the encoded value from input. Read more
fn encoded_fixed_size() -> Option<usize>
fn encoded_fixed_size() -> Option<usize>
Returns the fixed encoded size of the type. Read more
impl<Hash, Number, E: Epoch> Encode for EpochChanges<Hash, Number, E> where
ForkTree<Hash, Number, PersistedEpochHeader<E>>: Encode,
ForkTree<Hash, Number, PersistedEpochHeader<E>>: Encode,
BTreeMap<(Hash, Number), PersistedEpoch<E>>: Encode,
BTreeMap<(Hash, Number), PersistedEpoch<E>>: Encode,
impl<Hash, Number, E: Epoch> Encode for EpochChanges<Hash, Number, E> where
ForkTree<Hash, Number, PersistedEpochHeader<E>>: Encode,
ForkTree<Hash, Number, PersistedEpochHeader<E>>: Encode,
BTreeMap<(Hash, Number), PersistedEpoch<E>>: Encode,
BTreeMap<(Hash, Number), PersistedEpoch<E>>: Encode,
Convert self to a slice and append it to the destination.
fn using_encoded<R, F>(&self, f: F) -> R where
F: FnOnce(&[u8]) -> R,
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
fn encoded_size(&self) -> usize
Calculates the encoded size. Read more
impl<Hash, Number, E: Epoch> EncodeLike<EpochChanges<Hash, Number, E>> for EpochChanges<Hash, Number, E> where
ForkTree<Hash, Number, PersistedEpochHeader<E>>: Encode,
ForkTree<Hash, Number, PersistedEpochHeader<E>>: Encode,
BTreeMap<(Hash, Number), PersistedEpoch<E>>: Encode,
BTreeMap<(Hash, Number), PersistedEpoch<E>>: Encode,
Auto Trait Implementations
impl<Hash, Number, E> RefUnwindSafe for EpochChanges<Hash, Number, E> where
E: RefUnwindSafe,
Hash: RefUnwindSafe,
Number: RefUnwindSafe,
<E as Epoch>::Slot: RefUnwindSafe,
impl<Hash, Number, E> Send for EpochChanges<Hash, Number, E> where
E: Send,
Hash: Send,
Number: Send,
<E as Epoch>::Slot: Send,
impl<Hash, Number, E> Sync for EpochChanges<Hash, Number, E> where
E: Sync,
Hash: Sync,
Number: Sync,
<E as Epoch>::Slot: Sync,
impl<Hash, Number, E> Unpin for EpochChanges<Hash, Number, E> where
Hash: Unpin,
Number: Unpin,
<E as Epoch>::Slot: Unpin,
impl<Hash, Number, E> UnwindSafe for EpochChanges<Hash, Number, E> where
E: RefUnwindSafe,
Hash: RefUnwindSafe + UnwindSafe,
Number: RefUnwindSafe + UnwindSafe,
<E as Epoch>::Slot: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
type Output = T
type Output = T
Should always be Self
The counterpart to unchecked_from
.
Consume self to return an equivalent value of T
.
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
impl<'_, '_, T> EncodeLike<&'_ &'_ T> for T where
T: Encode,
impl<'_, T> EncodeLike<&'_ T> for T where
T: Encode,
impl<'_, T> EncodeLike<&'_ mut T> for T where
T: Encode,
impl<T> EncodeLike<Arc<T>> for T where
T: Encode,
impl<T> EncodeLike<Rc<T>> for T where
T: Encode,