Struct tc_consensus_epochs::EpochChanges[][src]

pub struct EpochChanges<Hash, Number, E: Epoch> { /* fields omitted */ }

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

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

pub fn new() -> Self[src]

Create a new epoch change.

pub fn rebalance(&mut self)[src]

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

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

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>>
[src]

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.

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

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, 
[src]

Get a reference to a viable epoch with given descriptor.

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

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, 
[src]

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
[src]

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.

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
[src]

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>>
[src]

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>>
[src]

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.

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

Return the inner fork tree.

Trait Implementations

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

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
[src]

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

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
[src]

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
[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> CheckedConversion for T[src]

impl<S> Codec for S where
    S: Decode + Encode
[src]

impl<T> DecodeAll for T where
    T: Decode
[src]

impl<T> DecodeLimit for T where
    T: Decode
[src]

impl<T> Downcast for T where
    T: Any

impl<T> DowncastSync for T where
    T: Any + Send + Sync

impl<T> DynClone for T where
    T: Clone
[src]

impl<'_, '_, T> EncodeLike<&'_ &'_ T> for T where
    T: Encode
[src]

impl<'_, T> EncodeLike<&'_ T> for T where
    T: Encode
[src]

impl<'_, T> EncodeLike<&'_ mut T> for T where
    T: Encode
[src]

impl<T> EncodeLike<Arc<T>> for T where
    T: Encode
[src]

impl<T> EncodeLike<Box<T, Global>> for T where
    T: Encode
[src]

impl<'a, T> EncodeLike<Cow<'a, T>> for T where
    T: ToOwned + Encode
[src]

impl<T> EncodeLike<Rc<T>> for T where
    T: Encode
[src]

impl<T> From<T> for T[src]

impl<S> FullCodec for S where
    S: Decode + FullEncode
[src]

impl<S> FullEncode for S where
    S: Encode + EncodeLike<S>, 
[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, Outer> IsWrappedBy<Outer> for T where
    T: From<Outer>,
    Outer: AsRef<T> + AsMut<T> + From<T>, 

pub fn from_ref(outer: &Outer) -> &T

Get a reference to the inner from the outer.

pub fn from_mut(outer: &mut Outer) -> &mut T

Get a mutable reference to the inner from the outer.

impl<T> KeyedVec for T where
    T: Codec
[src]

impl<T> MaybeRefUnwindSafe for T where
    T: RefUnwindSafe

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> SaturatedConversion for T

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<S, T> UncheckedInto<T> for S where
    T: UncheckedFrom<S>, 

impl<T, S> UniqueSaturatedInto<T> for S where
    T: Bounded,
    S: TryInto<T>, 

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