pub struct ConsensusState<Ctx>where
Ctx: Context,{
pub ctx: Ctx,
pub params: Params<Ctx>,
pub driver: Driver<Ctx>,
pub input_queue: BoundedQueue<<Ctx as Context>::Height, Input<Ctx>>,
pub full_proposal_keeper: FullProposalKeeper<Ctx>,
pub last_signed_prevote: Option<SignedMessage<Ctx, <Ctx as Context>::Vote>>,
pub last_signed_precommit: Option<SignedMessage<Ctx, <Ctx as Context>::Vote>>,
pub target_time: Option<Duration>,
pub height_start_time: Option<Instant>,
pub finalization_period: bool,
}Expand description
The state maintained by consensus for processing a Input.
Fields§
§ctx: CtxThe context for the consensus state machine
params: Params<Ctx>The consensus parameters
driver: Driver<Ctx>Driver for the per-round consensus state machine
input_queue: BoundedQueue<<Ctx as Context>::Height, Input<Ctx>>A queue of inputs that were received before the driver started.
full_proposal_keeper: FullProposalKeeper<Ctx>The proposals to decide on.
last_signed_prevote: Option<SignedMessage<Ctx, <Ctx as Context>::Vote>>Last prevote broadcasted by this node
last_signed_precommit: Option<SignedMessage<Ctx, <Ctx as Context>::Vote>>Last precommit broadcasted by this node
target_time: Option<Duration>Target time for the current height
height_start_time: Option<Instant>Start time of the current height
finalization_period: boolWhether we are in the finalization period.
The finalization period is entered in decide, cleared in finalize_height, and only valid during the commit step.
It allows collecting additional precommits for the decided value after the decision is made in decide, which can be included in the commit certificate.
Implementations§
Source§impl<Ctx> State<Ctx>where
Ctx: Context,
impl<Ctx> State<Ctx>where
Ctx: Context,
pub fn new( ctx: Ctx, height: <Ctx as Context>::Height, validator_set: <Ctx as Context>::ValidatorSet, params: Params<Ctx>, queue_capacity: usize, ) -> State<Ctx>
pub fn height(&self) -> <Ctx as Context>::Height
pub fn round(&self) -> Round
pub fn address(&self) -> &<Ctx as Context>::Address
pub fn validator_set(&self) -> &<Ctx as Context>::ValidatorSet
pub fn get_proposer( &self, height: <Ctx as Context>::Height, round: Round, ) -> &<Ctx as Context>::Address
pub fn set_last_vote( &mut self, vote: SignedMessage<Ctx, <Ctx as Context>::Vote>, )
pub fn restore_precommits( &self, height: <Ctx as Context>::Height, round: Round, value: &<Ctx as Context>::Value, ) -> Vec<SignedMessage<Ctx, <Ctx as Context>::Vote>>
Sourcepub fn polka_certificate(
&self,
round: Round,
value_id: &<<Ctx as Context>::Value as Value>::Id,
) -> Option<&PolkaCertificate<Ctx>>
pub fn polka_certificate( &self, round: Round, value_id: &<<Ctx as Context>::Value as Value>::Id, ) -> Option<&PolkaCertificate<Ctx>>
Get the polka certificate at the current height for the specified round and value, if it exists
pub fn full_proposal_at_round_and_value( &self, height: &<Ctx as Context>::Height, round: Round, value: &<Ctx as Context>::Value, ) -> Option<&FullProposal<Ctx>>
pub fn full_proposal_at_round_and_proposer( &self, height: &<Ctx as Context>::Height, round: Round, address: &<Ctx as Context>::Address, ) -> Option<&FullProposal<Ctx>>
Sourcepub fn get_proposed_value_by_id(
&self,
height: <Ctx as Context>::Height,
round: Round,
value_id: &<<Ctx as Context>::Value as Value>::Id,
) -> Option<ProposedValue<Ctx>>
pub fn get_proposed_value_by_id( &self, height: <Ctx as Context>::Height, round: Round, value_id: &<<Ctx as Context>::Value as Value>::Id, ) -> Option<ProposedValue<Ctx>>
Get a proposed value by its ID at the specified height and round.
pub fn proposals_for_value( &self, proposed_value: &ProposedValue<Ctx>, ) -> Vec<SignedMessage<Ctx, <Ctx as Context>::Proposal>>
pub fn store_proposal( &mut self, new_proposal: SignedMessage<Ctx, <Ctx as Context>::Proposal>, )
Sourcepub fn store_value(&mut self, new_value: &ProposedValue<Ctx>) -> Validity
pub fn store_value(&mut self, new_value: &ProposedValue<Ctx>) -> Validity
Store the proposed value and return its validity, which may be now be different from the one provided.
pub fn reset_and_start_height( &mut self, height: <Ctx as Context>::Height, validator_set: <Ctx as Context>::ValidatorSet, target_time: Option<Duration>, )
Sourcepub fn decided_value(&self) -> Option<(Round, <Ctx as Context>::Value)>
pub fn decided_value(&self) -> Option<(Round, <Ctx as Context>::Value)>
Return the round and value id of the decided value.
Sourcepub fn buffer_input(
&mut self,
height: <Ctx as Context>::Height,
input: Input<Ctx>,
_metrics: &Metrics,
)
pub fn buffer_input( &mut self, height: <Ctx as Context>::Height, input: Input<Ctx>, _metrics: &Metrics, )
Queue an input for later processing, only keep inputs for the highest height seen so far.
Sourcepub fn take_pending_inputs(&mut self, _metrics: &Metrics) -> Vec<Input<Ctx>>where
Ctx: Context,
pub fn take_pending_inputs(&mut self, _metrics: &Metrics) -> Vec<Input<Ctx>>where
Ctx: Context,
Take all inputs that are pending for the specified height and remove from the input queue.
pub fn print_state(&self)
Sourcepub fn is_active_validator(&self) -> bool
pub fn is_active_validator(&self) -> bool
Check if this node is an active validator.
Returns true only if:
- Consensus is enabled in the configuration, AND
- This node is present in the current validator set
pub fn round_certificate(&self) -> Option<&EnterRoundCertificate<Ctx>>
Auto Trait Implementations§
impl<Ctx> Freeze for State<Ctx>
impl<Ctx> RefUnwindSafe for State<Ctx>where
Ctx: RefUnwindSafe,
<Ctx as Context>::Address: RefUnwindSafe,
<Ctx as Context>::ValidatorSet: RefUnwindSafe,
<Ctx as Context>::Height: RefUnwindSafe,
<Ctx as Context>::Vote: RefUnwindSafe,
<<Ctx as Context>::SigningScheme as SigningScheme>::Signature: RefUnwindSafe,
<Ctx as Context>::Value: RefUnwindSafe,
<<Ctx as Context>::Value as Value>::Id: RefUnwindSafe,
<Ctx as Context>::Proposal: RefUnwindSafe,
impl<Ctx> Send for State<Ctx>
impl<Ctx> Sync for State<Ctx>
impl<Ctx> Unpin for State<Ctx>where
Ctx: Unpin,
<Ctx as Context>::Address: Unpin,
<Ctx as Context>::ValidatorSet: Unpin,
<Ctx as Context>::Height: Unpin,
<Ctx as Context>::Vote: Unpin,
<<Ctx as Context>::SigningScheme as SigningScheme>::Signature: Unpin,
<Ctx as Context>::Value: Unpin,
<<Ctx as Context>::Value as Value>::Id: Unpin,
<Ctx as Context>::Proposal: Unpin,
impl<Ctx> UnsafeUnpin for State<Ctx>where
Ctx: UnsafeUnpin,
<Ctx as Context>::Address: UnsafeUnpin,
<Ctx as Context>::ValidatorSet: UnsafeUnpin,
<Ctx as Context>::Height: UnsafeUnpin,
<Ctx as Context>::Vote: UnsafeUnpin,
<<Ctx as Context>::SigningScheme as SigningScheme>::Signature: UnsafeUnpin,
<Ctx as Context>::Value: UnsafeUnpin,
impl<Ctx> UnwindSafe for State<Ctx>where
Ctx: UnwindSafe,
<Ctx as Context>::Address: UnwindSafe + RefUnwindSafe,
<Ctx as Context>::ValidatorSet: UnwindSafe + RefUnwindSafe,
<Ctx as Context>::Height: UnwindSafe + RefUnwindSafe,
<Ctx as Context>::Vote: UnwindSafe + RefUnwindSafe,
<<Ctx as Context>::SigningScheme as SigningScheme>::Signature: UnwindSafe + RefUnwindSafe,
<Ctx as Context>::Value: UnwindSafe + RefUnwindSafe,
<<Ctx as Context>::Value as Value>::Id: UnwindSafe + RefUnwindSafe,
<Ctx as Context>::Proposal: UnwindSafe + RefUnwindSafe,
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