/// Poll the round. When the round is completable and messages have been flushed, it will return `Poll::Ready` but
/// can continue to be polled.
Poll the round. When the round is completable and messages have been flushed, it will return `Poll::Ready` but
can continue to be polled.
Poll the round . When the round is completable and messages have been flushed it will return ` Poll :: Ready ` but can continue to be polled .
pub(super) fn poll(&mut self, cx: &mut Context) -> Poll<Result<(), E::Error>> {
		trace!(target: "afg", "Polling round {}, state = {:?}, step = {:?}", self.votes.number(), self.votes.state(), self.state);
		let pre_state = self.votes.state();
		self.process_incoming(cx)?;
		// we only cast votes when we have access to the previous round state.
		// we might have started this round as a prospect "future" round to
		// check whether the voter is lagging behind the current round.
		let last_round_state = self.last_round_state.as_ref().map(|s| s.get(cx).clone());
		if let Some(ref last_round_state) = last_round_state {
			self.primary_propose(last_round_state)?;
			self.prevote(cx, last_round_state)?;
			self.precommit(cx, last_round_state)?;
		}
		ready!(self.outgoing.poll(cx))?;
		self.process_incoming(cx)?; // in case we got a new message signed locally.
		// broadcast finality notifications after attempting to cast votes
		let post_state = self.votes.state();
		self.notify(pre_state, post_state);
		// early exit if the current round is not completable
		if !self.votes.completable() {
			return Poll::Pending
		}
		// make sure that the previous round estimate has been finalized
		let last_round_estimate_finalized = match last_round_state {
			Some(RoundState {
				estimate: Some((_, last_round_estimate)),
				finalized: Some((_, last_round_finalized)),
				..
			}) => {
				// either it was already finalized in the previous round
				let finalized_in_last_round = last_round_estimate <= last_round_finalized;
				// or it must be finalized in the current round
				let finalized_in_current_round =
					self.finalized().map_or(false, |(_, current_round_finalized)| {
						last_round_estimate <= *current_round_finalized
					});
				finalized_in_last_round || finalized_in_current_round
			},
			None => {
				// NOTE: when we catch up to a round we complete the round
				// without any last round state. in this case we already started
				// a new round after we caught up so this guard is unneeded.
				true
			},
			_ => false,
		};
		// the previous round estimate must be finalized
		if !last_round_estimate_finalized {
			trace!(target: "afg", "Round {} completable but estimate not finalized.", self.round_number());
			self.log_participation(log::Level::Trace);
			return Poll::Pending
		}
		debug!(target: "afg", "Completed round {}, state = {:?}, step = {:?}",
			self.votes.number(), self.votes.state(), self.state);
		self.log_participation(log::Level::Debug);
		// both exit conditions verified, we can complete this round
		Poll::Ready(Ok(()))
	}
pub ( super ) fn poll ( & mut self , cx : & mut Context ) -> Poll < Result < ( ) , E :: Error > > { trace ! ( target " " " " self votes number ( ) self votes state ( ) self state ) ; let pre_state = self . votes . state ( ) ; self . process_incoming ( cx ) ? ; // we only cast votes when we have access to the previous round state. // we might have started this round as a prospect "future" round to // check whether the voter is lagging behind the current round. let last_round_state = self . last_round_state . as_ref ( ) . map ( | s | s . get ( cx ) . clone ( ) ) ; if let Some ( ref last_round_state ) = last_round_state { self . primary_propose ( last_round_state ) ? ; self . prevote ( cx , last_round_state ) ? ; self . precommit ( cx , last_round_state ) ? ; } ready ! ( self outgoing poll ( cx ) ) ? ; self . process_incoming ( cx ) ? ; // in case we got a new message signed locally. // broadcast finality notifications after attempting to cast votes let post_state = self . votes . state ( ) ; self . notify ( pre_state , post_state ) ; // early exit if the current round is not completable if ! self . votes . completable ( ) { return Poll :: Pending } // make sure that the previous round estimate has been finalized let last_round_estimate_finalized = match last_round_state { Some ( RoundState { estimate : Some ( ( _ , last_round_estimate ) ) , finalized : Some ( ( _ , last_round_finalized ) ) , .. } ) => { // either it was already finalized in the previous round let finalized_in_last_round = last_round_estimate <= last_round_finalized ; // or it must be finalized in the current round let finalized_in_current_round = self . finalized ( ) . map_or ( false , | ( _ , current_round_finalized ) | { last_round_estimate <= * current_round_finalized } ) ; finalized_in_last_round || finalized_in_current_round } , None => { // NOTE: when we catch up to a round we complete the round // without any last round state. in this case we already started // a new round after we caught up so this guard is unneeded. true } , _ => false , } ; // the previous round estimate must be finalized if ! last_round_estimate_finalized { trace ! ( target " " " " self round_number ( ) ) ; self . log_participation ( log :: Level :: Trace ) ; return Poll :: Pending } debug ! ( target " " " " self votes number ( ) self votes state ( ) self state ) ; self . log_participation ( log :: Level :: Debug ) ; // both exit conditions verified, we can complete this round Poll :: Ready ( Ok ( ( ) ) ) }
Poll the round.
Poll the round .
&mut self
cx
&mut Context