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: ConfigConfiguration for the sync state and behaviour.
started: boolConsensus has started
consensus_height: Ctx::HeightThe height that consensus is at, but has not decided yet.
tip_height: Ctx::HeightHeight of last decided value
sync_height: Ctx::HeightNext 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: PeerScorerPeer scorer for scoring peers based on their performance.
Implementations§
Source§impl<Ctx> State<Ctx>where
Ctx: Context,
impl<Ctx> State<Ctx>where
Ctx: Context,
pub fn new(rng: Box<dyn RngCore + Send>, config: Config) -> Self
Sourcepub fn max_parallel_requests(&self) -> usize
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.
pub fn update_status(&mut self, status: Status<Ctx>)
pub fn update_request( &mut self, request_id: OutboundRequestId, peer_id: PeerId, range: RangeInclusive<Ctx::Height>, )
Sourcepub fn filter_peers_by_range(
peers: &BTreeMap<PeerId, Status<Ctx>>,
range: &RangeInclusive<Ctx::Height>,
except: Option<PeerId>,
) -> HashMap<PeerId, RangeInclusive<Ctx::Height>>
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.
Sourcepub fn random_peer_with_except(
&mut self,
range: &RangeInclusive<Ctx::Height>,
except: Option<PeerId>,
) -> Option<(PeerId, RangeInclusive<Ctx::Height>)>
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.
Sourcepub fn random_peer_with(
&mut self,
range: &RangeInclusive<Ctx::Height>,
) -> Option<(PeerId, RangeInclusive<Ctx::Height>)>where
Ctx: Context,
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.
Sourcepub fn get_request_id_by(
&self,
height: Ctx::Height,
) -> Option<(OutboundRequestId, PeerId)>
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.
Sourcepub fn trim_validated_heights(
&mut self,
range: &RangeInclusive<Ctx::Height>,
) -> RangeInclusive<Ctx::Height>
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.
Sourcepub fn prune_pending_requests(&mut self)
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>
impl<Ctx> !RefUnwindSafe for State<Ctx>
impl<Ctx> Send for State<Ctx>
impl<Ctx> !Sync for State<Ctx>
impl<Ctx> Unpin for State<Ctx>
impl<Ctx> UnsafeUnpin for State<Ctx>
impl<Ctx> !UnwindSafe for State<Ctx>
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> 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 more