pub(crate) fn apply_forced_changes<F, E>(
		&self,
		best_hash: H,
		best_number: N,
		is_descendent_of: &F,
	) -> Result<Option<(N, Self)>, E>
		where F: Fn(&H, &H) -> Result<bool, E>,
	{
		let mut new_set = None;

		for change in self.pending_forced_changes.iter()
			.take_while(|c| c.effective_number() <= best_number) // to prevent iterating too far
			.filter(|c| c.effective_number() == best_number)
		{
			// check if the given best block is in the same branch as the block that signaled the change.
			if is_descendent_of(&change.canon_hash, &best_hash)? {
				// apply this change: make the set canonical
				info!(target: "finality", "Applying authority set change forced at block #{:?}",
					  change.canon_height);
				telemetry!(CONSENSUS_INFO; "afg.applying_forced_authority_set_change";
					"block" => ?change.canon_height
				);

				let median_last_finalized = match change.delay_kind {
					DelayKind::Best { ref median_last_finalized } => median_last_finalized.clone(),
					_ => unreachable!("pending_forced_changes only contains forced changes; forced changes have delay kind Best; qed."),
				};

				new_set = Some((median_last_finalized, AuthoritySet {
					current_authorities: change.next_authorities.clone(),
					set_id: self.set_id + 1,
					pending_standard_changes: ForkTree::new(), // new set, new changes.
					pending_forced_changes: Vec::new(),
				}));

				break;
			}

			// we don't wipe forced changes until another change is
			// applied
		}

		Ok(new_set)
	}
/// Apply or prune any pending transitions based on a best-block trigger.
///
/// Returns `Ok((median, new_set))` when a forced change has occurred. The
/// median represents the median last finalized block at the time the change
/// was signaled, and it should be used as the canon block when starting the
/// new grandpa voter. Only alters the internal state in this case.
///
/// These transitions are always forced and do not lead to justifications
/// which light clients can follow.
Apply or prune any pending transitions based on a best-block trigger.
Returns `Ok((median, new_set))` when a forced change has occurred. The
median represents the median last finalized block at the time the change
was signaled, and it should be used as the canon block when starting the
new grandpa voter. Only alters the internal state in this case.

These transitions are always forced and do not lead to justifications
which light clients can follow.
Apply or prune any pending transitions based on a best - block trigger . Returns ` Ok (( median new_set )) ` when a forced change has occurred . The median represents the median last finalized block at the time the change was signaled and it should be used as the canon block when starting the new grandpa voter . Only alters the internal state in this case . These transitions are always forced and do not lead to justifications which light clients can follow .
pub(crate) fn apply_forced_changes<F, E>(
		&self,
		best_hash: H,
		best_number: N,
		is_descendent_of: &F,
	) -> Result<Option<(N, Self)>, E>
		where F: Fn(&H, &H) -> Result<bool, E>,
	{
		let mut new_set = None;
		for change in self.pending_forced_changes.iter()
			.take_while(|c| c.effective_number() <= best_number) // to prevent iterating too far
			.filter(|c| c.effective_number() == best_number)
		{
			// check if the given best block is in the same branch as the block that signaled the change.
			if is_descendent_of(&change.canon_hash, &best_hash)? {
				// apply this change: make the set canonical
				info!(target: "finality", "Applying authority set change forced at block #{:?}",
					  change.canon_height);
				telemetry!(CONSENSUS_INFO; "afg.applying_forced_authority_set_change";
					"block" => ?change.canon_height
				);
				let median_last_finalized = match change.delay_kind {
					DelayKind::Best { ref median_last_finalized } => median_last_finalized.clone(),
					_ => unreachable!("pending_forced_changes only contains forced changes; forced changes have delay kind Best; qed."),
				};
				new_set = Some((median_last_finalized, AuthoritySet {
					current_authorities: change.next_authorities.clone(),
					set_id: self.set_id + 1,
					pending_standard_changes: ForkTree::new(), // new set, new changes.
					pending_forced_changes: Vec::new(),
				}));
				break;
			}
			// we don't wipe forced changes until another change is
			// applied
		}
		Ok(new_set)
	}
pub ( crate ) fn apply_forced_changes < F , E > ( & self , best_hash : H , best_number : N , is_descendent_of : & F , ) -> Result < Option < ( N , Self ) > , E > where F : Fn ( & H , & H ) -> Result < bool , E > , { let mut new_set = None ; for change in self . pending_forced_changes . iter ( ) . take_while ( | c | c . effective_number ( ) <= best_number ) // to prevent iterating too far . filter ( | c | c . effective_number ( ) == best_number ) { // check if the given best block is in the same branch as the block that signaled the change. if is_descendent_of ( & change . canon_hash , & best_hash ) ? { // apply this change: make the set canonical info ! ( target " " " " change canon_height ) ; telemetry ! ( CONSENSUS_INFO " " " " change canon_height ) ; let median_last_finalized = match change . delay_kind { DelayKind :: Best { ref median_last_finalized } => median_last_finalized . clone ( ) , _ => unreachable ! ( " " ) , } ; new_set = Some ( ( median_last_finalized , AuthoritySet { current_authorities : change . next_authorities . clone ( ) , set_id : self . set_id + 1 , pending_standard_changes : ForkTree :: new ( ) , // new set, new changes. pending_forced_changes : Vec :: new ( ) , } ) ) ; break ; } // we don't wipe forced changes until another change is // applied } Ok ( new_set ) }
Apply or prune any pending transitions based on a best-block trigger.
Apply or prune any pending transitions based on a best - block trigger .
&self
best_hash
H
best_number
N
is_descendent_of
&F
&self
best_hash
H
best_number
N
is_descendent_of
&F