Skip to main content

State

Struct State 

Source
pub struct State<Ctx>
where Ctx: Context,
{ pub rng: Box<dyn RngCore + Send>, pub config: Config, pub started: bool, pub consensus_height: Ctx::Height, pub tip_height: Ctx::Height, pub sync_height: Ctx::Height, pub pending_requests: BTreeMap<OutboundRequestId, (RangeInclusive<Ctx::Height>, PeerId)>, pub peers: BTreeMap<PeerId, Status<Ctx>>, pub peer_scorer: PeerScorer, }

Fields§

§rng: Box<dyn RngCore + Send>§config: Config

Configuration for the sync state and behaviour.

§started: bool

Consensus has started

§consensus_height: Ctx::Height

The height that consensus is at, but has not decided yet.

§tip_height: Ctx::Height

Height of last decided value

§sync_height: Ctx::Height

Next height to send a sync request. Invariant: sync_height > tip_height

§pending_requests: BTreeMap<OutboundRequestId, (RangeInclusive<Ctx::Height>, PeerId)>

The requested range of heights.

§peers: BTreeMap<PeerId, Status<Ctx>>

The set of peers we are connected to in order to get values, certificates and votes.

§peer_scorer: PeerScorer

Peer scorer for scoring peers based on their performance.

Implementations§

Source§

impl<Ctx> State<Ctx>
where Ctx: Context,

Source

pub fn new(rng: Box<dyn RngCore + Send>, config: Config) -> Self

Source

pub fn max_parallel_requests(&self) -> usize

The maximum number of parallel requests that can be made to peers. If the configuration is set to 0, it defaults to 1.

Source

pub fn update_status(&mut self, status: Status<Ctx>)

Source

pub fn update_request( &mut self, request_id: OutboundRequestId, peer_id: PeerId, range: RangeInclusive<Ctx::Height>, )

Source

pub fn filter_peers_by_range( peers: &BTreeMap<PeerId, Status<Ctx>>, range: &RangeInclusive<Ctx::Height>, except: Option<PeerId>, ) -> HashMap<PeerId, RangeInclusive<Ctx::Height>>

Filter peers to only include those that can provide the given range of values, or at least a prefix of the range.

If there is no peer with all requested values, select a peer that has a tip at or above the start of the range. Prefer peers that support batching (v2 sync protocol). Return the peer ID and the range of heights that the peer can provide.

Source

pub fn random_peer_with_except( &mut self, range: &RangeInclusive<Ctx::Height>, except: Option<PeerId>, ) -> Option<(PeerId, RangeInclusive<Ctx::Height>)>

Select at random a peer that can provide the given range of values, while excluding the given peer if provided.

Source

pub fn random_peer_with( &mut self, range: &RangeInclusive<Ctx::Height>, ) -> Option<(PeerId, RangeInclusive<Ctx::Height>)>
where Ctx: Context,

Same as Self::random_peer_with_except but without excluding any peer.

Source

pub fn get_request_id_by( &self, height: Ctx::Height, ) -> Option<(OutboundRequestId, PeerId)>

Get the request that contains the given height.

Assumes a height cannot be in multiple pending requests.

Source

pub fn trim_validated_heights( &mut self, range: &RangeInclusive<Ctx::Height>, ) -> RangeInclusive<Ctx::Height>

Return a new range of heights, trimming from the beginning any height that is validated by consensus.

Source

pub fn prune_pending_requests(&mut self)

Remove pending requests that are for heights that have already been validated by consensus.

Auto Trait Implementations§

§

impl<Ctx> Freeze for State<Ctx>
where <Ctx as Context>::Height: Freeze,

§

impl<Ctx> !RefUnwindSafe for State<Ctx>

§

impl<Ctx> Send for State<Ctx>

§

impl<Ctx> !Sync for State<Ctx>

§

impl<Ctx> Unpin for State<Ctx>
where <Ctx as Context>::Height: Unpin,

§

impl<Ctx> UnsafeUnpin for State<Ctx>
where <Ctx as Context>::Height: UnsafeUnpin,

§

impl<Ctx> !UnwindSafe for State<Ctx>

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> 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> 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> Same for T

Source§

type Output = T

Should always be Self
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<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