pub struct State<C>where
C: Context,{ /* private fields */ }Expand description
A passive instance of the Highway protocol, containing its local state.
Both observers and active validators must instantiate this, pass in all incoming vertices from peers, and use a FinalityDetector to determine the outcome of the consensus process.
Implementations§
Source§impl<C: Context> State<C>
impl<C: Context> State<C>
Sourcepub fn validator_count(&self) -> usize
pub fn validator_count(&self) -> usize
Returns the number of validators.
Sourcepub fn weight(&self, idx: ValidatorIndex) -> Weight
pub fn weight(&self, idx: ValidatorIndex) -> Weight
Returns the idxth validator’s voting weight.
Sourcepub fn weights(&self) -> &ValidatorMap<Weight>
pub fn weights(&self) -> &ValidatorMap<Weight>
Returns the map of validator weights.
Sourcepub fn faulty_weight_in(&self, panorama: &Panorama<C>) -> Weight
pub fn faulty_weight_in(&self, panorama: &Panorama<C>) -> Weight
Returns the total weight of all validators marked faulty in this panorama.
Sourcepub fn faulty_weight(&self) -> Weight
pub fn faulty_weight(&self) -> Weight
Returns the total weight of all known-faulty validators.
Sourcepub fn total_weight(&self) -> Weight
pub fn total_weight(&self) -> Weight
Returns the sum of all validators’ voting weights.
Sourcepub fn maybe_evidence(&self, idx: ValidatorIndex) -> Option<&Evidence<C>>
pub fn maybe_evidence(&self, idx: ValidatorIndex) -> Option<&Evidence<C>>
Returns evidence against validator nr. idx, if present.
Sourcepub fn maybe_endorsements(&self, unit: &C::Hash) -> Option<Endorsements<C>>
pub fn maybe_endorsements(&self, unit: &C::Hash) -> Option<Endorsements<C>>
Returns endorsements for unit, if any.
Sourcepub fn has_evidence(&self, idx: ValidatorIndex) -> bool
pub fn has_evidence(&self, idx: ValidatorIndex) -> bool
Returns whether evidence against validator nr. idx is known.
Sourcepub fn has_all_endorsements<I: IntoIterator<Item = ValidatorIndex>>(
&self,
unit: &C::Hash,
v_ids: I,
) -> bool
pub fn has_all_endorsements<I: IntoIterator<Item = ValidatorIndex>>( &self, unit: &C::Hash, v_ids: I, ) -> bool
Returns whether we have all endorsements for unit.
Sourcepub fn is_endorsed(&self, hash: &C::Hash) -> bool
pub fn is_endorsed(&self, hash: &C::Hash) -> bool
Returns whether we have seen enough endorsements for the unit. Unit is endorsed when it has endorsements from more than 50% of the validators (by weight).
Sourcepub fn needs_endorsements(&self, unit: &SignedWireUnit<C>) -> Option<C::Hash>
pub fn needs_endorsements(&self, unit: &SignedWireUnit<C>) -> Option<C::Hash>
Returns hash of unit that needs to be endorsed.
Sourcepub fn last_seen(&self, idx: ValidatorIndex) -> Timestamp
pub fn last_seen(&self, idx: ValidatorIndex) -> Timestamp
Returns the timestamp of the last ping or unit received from the validator, or the start timestamp if we haven’t received anything yet.
Sourcepub fn mark_faulty(&mut self, idx: ValidatorIndex)
pub fn mark_faulty(&mut self, idx: ValidatorIndex)
Marks the given validator as faulty, unless it is already banned or we have direct evidence.
Sourcepub fn maybe_fault(&self, idx: ValidatorIndex) -> Option<&Fault<C>>
pub fn maybe_fault(&self, idx: ValidatorIndex) -> Option<&Fault<C>>
Returns the fault type of validator nr. idx, if it is known to be faulty.
Sourcepub fn is_faulty(&self, idx: ValidatorIndex) -> bool
pub fn is_faulty(&self, idx: ValidatorIndex) -> bool
Returns whether validator nr. idx is known to be faulty.
Sourcepub fn faulty_validators(&self) -> impl Iterator<Item = ValidatorIndex> + '_
pub fn faulty_validators(&self) -> impl Iterator<Item = ValidatorIndex> + '_
Returns an iterator over all faulty validators.
Sourcepub fn iter_correct_hashes(&self) -> impl Iterator<Item = &C::Hash>
pub fn iter_correct_hashes(&self) -> impl Iterator<Item = &C::Hash>
Returns an iterator over latest unit hashes from honest validators.
Sourcepub fn maybe_unit(&self, hash: &C::Hash) -> Option<&Unit<C>>
pub fn maybe_unit(&self, hash: &C::Hash) -> Option<&Unit<C>>
Returns the unit with the given hash, if present.
Sourcepub fn has_unit(&self, hash: &C::Hash) -> bool
pub fn has_unit(&self, hash: &C::Hash) -> bool
Returns whether the unit with the given hash is known.
Sourcepub fn unit(&self, hash: &C::Hash) -> &Unit<C>
pub fn unit(&self, hash: &C::Hash) -> &Unit<C>
Returns the unit with the given hash. Panics if not found.
Sourcepub fn maybe_block(&self, hash: &C::Hash) -> Option<&Block<C>>
pub fn maybe_block(&self, hash: &C::Hash) -> Option<&Block<C>>
Returns the block contained in the unit with the given hash, if present.
Sourcepub fn block(&self, hash: &C::Hash) -> &Block<C>
pub fn block(&self, hash: &C::Hash) -> &Block<C>
Returns the block contained in the unit with the given hash. Panics if not found.
Sourcepub fn leader(&self, timestamp: Timestamp) -> ValidatorIndex
pub fn leader(&self, timestamp: Timestamp) -> ValidatorIndex
Returns the leader in the specified time slot.
First the assignment is computed ignoring the can_propose flags. Only if the selected
leader’s entry is false, the computation is repeated, this time with the flagged
validators excluded. This ensures that once the validator set has been decided, correct
validators’ slots never get reassigned to someone else, even if after the fact someone is
excluded as a leader.
Sourcepub fn has_endorsement(&self, uhash: &C::Hash, vidx: ValidatorIndex) -> bool
pub fn has_endorsement(&self, uhash: &C::Hash, vidx: ValidatorIndex) -> bool
Returns whether this state already includes an endorsement of uhash by vidx.
Sourcepub fn has_ping(&self, creator: ValidatorIndex, timestamp: Timestamp) -> bool
pub fn has_ping(&self, creator: ValidatorIndex, timestamp: Timestamp) -> bool
Returns true if the latest timestamp we have is older than the given timestamp.
Sourcepub fn find_conflicting_endorsements(
&self,
endorsements: &Endorsements<C>,
instance_id: &C::InstanceId,
) -> Vec<Evidence<C>>
pub fn find_conflicting_endorsements( &self, endorsements: &Endorsements<C>, instance_id: &C::InstanceId, ) -> Vec<Evidence<C>>
Creates new Evidence if the new endorsements contain any that conflict with existing
ones.
Endorsements must be validated before calling this: The endorsers must exist, the
signatures must be valid and the endorsed unit must be present in self.units.
Sourcepub fn wire_unit(
&self,
hash: &C::Hash,
instance_id: C::InstanceId,
) -> Option<SignedWireUnit<C>>
pub fn wire_unit( &self, hash: &C::Hash, instance_id: C::InstanceId, ) -> Option<SignedWireUnit<C>>
Returns the SignedWireUnit with the given hash, if it is present in the state.
Sourcepub fn fork_choice<'a>(&'a self, pan: &Panorama<C>) -> Option<&'a C::Hash>
pub fn fork_choice<'a>(&'a self, pan: &Panorama<C>) -> Option<&'a C::Hash>
Returns the fork choice from pan’s view, or None if there are no blocks yet.
The correct validators’ latest units count as votes for the block they point to, as well as all of its ancestors. At each level the block with the highest score is selected from the children of the previously selected block (or from all blocks at height 0), until a block is reached that has no children with any votes.
Sourcepub fn find_ancestor_proposal<'a>(
&'a self,
hash: &'a C::Hash,
height: u64,
) -> Option<&'a C::Hash>
pub fn find_ancestor_proposal<'a>( &'a self, hash: &'a C::Hash, height: u64, ) -> Option<&'a C::Hash>
Returns the ancestor of the block with the given hash, on the specified height, or
None if the block’s height is lower than that.
NOTE: Panics if used on non-proposal hashes.
Sourcepub fn find_in_swimlane<'a>(
&'a self,
hash: &'a C::Hash,
seq_number: u64,
) -> Option<&'a C::Hash>
pub fn find_in_swimlane<'a>( &'a self, hash: &'a C::Hash, seq_number: u64, ) -> Option<&'a C::Hash>
Returns the hash of the message with the given sequence number from the creator of hash,
or None if the sequence number is higher than that of the unit with hash.
Sourcepub fn swimlane<'a>(
&'a self,
uhash: &'a C::Hash,
) -> impl Iterator<Item = (&'a C::Hash, &'a Unit<C>)>
pub fn swimlane<'a>( &'a self, uhash: &'a C::Hash, ) -> impl Iterator<Item = (&'a C::Hash, &'a Unit<C>)>
Returns an iterator over units (with hashes) by the same creator, in reverse chronological
order, starting with the specified unit. Panics if no unit with uhash exists.
Sourcepub fn ancestor_hashes<'a>(
&'a self,
bhash: &'a C::Hash,
) -> impl Iterator<Item = &'a C::Hash>
pub fn ancestor_hashes<'a>( &'a self, bhash: &'a C::Hash, ) -> impl Iterator<Item = &'a C::Hash>
Returns an iterator over all hashes of ancestors of the block bhash, excluding bhash
itself. Panics if bhash is not the hash of a known block.
Sourcepub fn seen_endorsed(&self, pan: &Panorama<C>) -> BTreeSet<C::Hash>
pub fn seen_endorsed(&self, pan: &Panorama<C>) -> BTreeSet<C::Hash>
Returns the set of units (by hash) that are endorsed and seen from the panorama.
Sourcepub fn sees_correct(&self, hash0: &C::Hash, hash1: &C::Hash) -> bool
pub fn sees_correct(&self, hash0: &C::Hash, hash1: &C::Hash) -> bool
Returns whether the unit with hash0 sees the one with hash1 (i.e. hash0 ≥ hash1),
and sees hash1’s creator as correct.
Sourcepub fn sees(&self, hash0: &C::Hash, hash1: &C::Hash) -> bool
pub fn sees(&self, hash0: &C::Hash, hash1: &C::Hash) -> bool
Returns whether the unit with hash0 sees the one with hash1 (i.e. hash0 ≥ hash1).
Sourcepub fn confirmation_panorama(
&self,
creator: ValidatorIndex,
uhash: &C::Hash,
) -> Panorama<C>
pub fn confirmation_panorama( &self, creator: ValidatorIndex, uhash: &C::Hash, ) -> Panorama<C>
Returns the panorama of the confirmation for the leader unit uhash.
Sourcepub fn valid_panorama(
&self,
creator: ValidatorIndex,
pan: Panorama<C>,
) -> Panorama<C>
pub fn valid_panorama( &self, creator: ValidatorIndex, pan: Panorama<C>, ) -> Panorama<C>
Creates a panorama that is valid for use in creator’s next unit, and as close as possible
to the given one. It is only modified if necessary for validity:
- Cite
creator’s previous unit, i.e. don’t equivocate. - Satisfy the LNC, i.e. don’t add new naively cited forks.
Sourcepub fn inclusive_panorama(&self, uhash: &C::Hash) -> Panorama<C>
pub fn inclusive_panorama(&self, uhash: &C::Hash) -> Panorama<C>
Returns panorama of a unit where latest entry of the creator is that unit’s hash.
Trait Implementations§
Source§impl<C> DataSize for State<C>
impl<C> DataSize for State<C>
Source§const IS_DYNAMIC: bool = true
const IS_DYNAMIC: bool = true
true, the type has a heap size that can vary at runtime, depending on the actual value.Source§const STATIC_HEAP_SIZE: usize
const STATIC_HEAP_SIZE: usize
IS_DYNAMIC is false, this is
the total amount of heap memory occupied by the value. Otherwise this is a lower bound.Source§fn estimate_heap_size(&self) -> usize
fn estimate_heap_size(&self) -> usize
Source§fn estimate_detailed_heap_size(&self) -> MemUsageNode
fn estimate_detailed_heap_size(&self) -> MemUsageNode
Source§impl<'de, C> Deserialize<'de> for State<C>where
C: Context + Deserialize<'de>,
impl<'de, C> Deserialize<'de> for State<C>where
C: Context + Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl<C> !Freeze for State<C>
impl<C> RefUnwindSafe for State<C>where
<C as Context>::Hash: RefUnwindSafe,
<C as Context>::Signature: RefUnwindSafe,
<C as Context>::ConsensusValue: RefUnwindSafe,
<C as Context>::InstanceId: RefUnwindSafe,
impl<C> Send for State<C>
impl<C> Sync for State<C>
impl<C> Unpin for State<C>
impl<C> UnwindSafe for State<C>where
<C as Context>::Hash: UnwindSafe + RefUnwindSafe,
<C as Context>::Signature: UnwindSafe + RefUnwindSafe,
<C as Context>::ConsensusValue: UnwindSafe,
<C as Context>::InstanceId: UnwindSafe,
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<From, To> FallibleInto<To> for Fromwhere
To: TryFrom<From>,
impl<From, To> FallibleInto<To> for Fromwhere
To: TryFrom<From>,
fn try_into_wrapped(self) -> Result<To, VMError>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.