State

Struct State 

Source
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>

Source

pub fn params(&self) -> &Params

Returns the fixed parameters.

Source

pub fn validator_count(&self) -> usize

Returns the number of validators.

Source

pub fn weight(&self, idx: ValidatorIndex) -> Weight

Returns the idxth validator’s voting weight.

Source

pub fn weights(&self) -> &ValidatorMap<Weight>

Returns the map of validator weights.

Source

pub fn faulty_weight_in(&self, panorama: &Panorama<C>) -> Weight

Returns the total weight of all validators marked faulty in this panorama.

Source

pub fn faulty_weight(&self) -> Weight

Returns the total weight of all known-faulty validators.

Source

pub fn total_weight(&self) -> Weight

Returns the sum of all validators’ voting weights.

Source

pub fn maybe_evidence(&self, idx: ValidatorIndex) -> Option<&Evidence<C>>

Returns evidence against validator nr. idx, if present.

Source

pub fn maybe_endorsements(&self, unit: &C::Hash) -> Option<Endorsements<C>>

Returns endorsements for unit, if any.

Source

pub fn has_evidence(&self, idx: ValidatorIndex) -> bool

Returns whether evidence against validator nr. idx is known.

Source

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.

Source

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).

Source

pub fn needs_endorsements(&self, unit: &SignedWireUnit<C>) -> Option<C::Hash>

Returns hash of unit that needs to be endorsed.

Source

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.

Source

pub fn mark_faulty(&mut self, idx: ValidatorIndex)

Marks the given validator as faulty, unless it is already banned or we have direct evidence.

Source

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.

Source

pub fn is_faulty(&self, idx: ValidatorIndex) -> bool

Returns whether validator nr. idx is known to be faulty.

Source

pub fn faulty_validators(&self) -> impl Iterator<Item = ValidatorIndex> + '_

Returns an iterator over all faulty validators.

Source

pub fn iter_correct_hashes(&self) -> impl Iterator<Item = &C::Hash>

Returns an iterator over latest unit hashes from honest validators.

Source

pub fn maybe_unit(&self, hash: &C::Hash) -> Option<&Unit<C>>

Returns the unit with the given hash, if present.

Source

pub fn has_unit(&self, hash: &C::Hash) -> bool

Returns whether the unit with the given hash is known.

Source

pub fn unit(&self, hash: &C::Hash) -> &Unit<C>

Returns the unit with the given hash. Panics if not found.

Source

pub fn maybe_block(&self, hash: &C::Hash) -> Option<&Block<C>>

Returns the block contained in the unit with the given hash, if present.

Source

pub fn block(&self, hash: &C::Hash) -> &Block<C>

Returns the block contained in the unit with the given hash. Panics if not found.

Source

pub fn panorama(&self) -> &Panorama<C>

Returns the complete protocol state’s latest panorama.

Source

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.

Source

pub fn has_endorsement(&self, uhash: &C::Hash, vidx: ValidatorIndex) -> bool

Returns whether this state already includes an endorsement of uhash by vidx.

Source

pub fn has_ping(&self, creator: ValidatorIndex, timestamp: Timestamp) -> bool

Returns true if the latest timestamp we have is older than the given timestamp.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

pub fn confirmation_panorama( &self, creator: ValidatorIndex, uhash: &C::Hash, ) -> Panorama<C>

Returns the panorama of the confirmation for the leader unit uhash.

Source

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.
Source

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> Clone for State<C>
where C: Context + Clone, C::Hash: Clone, C::Signature: Clone,

Source§

fn clone(&self) -> State<C>

Returns a duplicate 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<C> DataSize for State<C>
where HashMap<ValidatorIndex, Fault<C>>: DataSize, Panorama<C>: DataSize, C: Context,

Source§

const IS_DYNAMIC: bool = true

If true, the type has a heap size that can vary at runtime, depending on the actual value.
Source§

const STATIC_HEAP_SIZE: usize

The amount of space a value of the type always occupies. If 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

Estimates the size of heap memory taken up by this value. Read more
Source§

fn estimate_detailed_heap_size(&self) -> MemUsageNode

Create a tree of memory estimations. Read more
Source§

impl<C> Debug for State<C>
where C: Context + Debug, C::Hash: Debug, C::Signature: Debug,

Source§

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

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

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>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<C> Serialize for State<C>
where C: Context + Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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>
where <C as Context>::Hash: Sync, <C as Context>::Signature: Sync, <C as Context>::ConsensusValue: Sync, <C as Context>::InstanceId: Sync,

§

impl<C> Unpin for State<C>
where <C as Context>::Hash: Unpin, <C as Context>::Signature: Unpin, <C as Context>::ConsensusValue: Unpin, <C as Context>::InstanceId: Unpin,

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn 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.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<From, To> FallibleInto<To> for From
where To: TryFrom<From>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<Ok, Error>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> Upcastable for T
where T: Any + Send + Sync + 'static,

Source§

fn upcast_any_ref(&self) -> &(dyn Any + 'static)

upcast ref
Source§

fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)

upcast mut ref
Source§

fn upcast_any_box(self: Box<T>) -> Box<dyn Any>

upcast boxed dyn
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,