pub(crate) fn try_trigger_new_era(
		start_session_index: SessionIndex,
		is_genesis: bool,
	) -> Option<Vec<T::AccountId>> {
		let (election_result, weight) = if is_genesis {
			T::GenesisElectionProvider::elect().map_err(|e| {
				log!(warn, "genesis election provider failed due to {:?}", e);
				Self::deposit_event(Event::StakingElectionFailed);
			})
		} else {
			T::ElectionProvider::elect().map_err(|e| {
				log!(warn, "election provider failed due to {:?}", e);
				Self::deposit_event(Event::StakingElectionFailed);
			})
		}
		.ok()?;

		<frame_system::Pallet<T>>::register_extra_weight_unchecked(
			weight,
			frame_support::weights::DispatchClass::Mandatory,
		);

		let exposures = Self::collect_exposures(election_result);

		if (exposures.len() as u32) < Self::minimum_validator_count().max(1) {
			// Session will panic if we ever return an empty validator set, thus max(1) ^^.
			match CurrentEra::<T>::get() {
				Some(current_era) if current_era > 0 => log!(
					warn,
					"chain does not have enough staking candidates to operate for era {:?} ({} \
					elected, minimum is {})",
					CurrentEra::<T>::get().unwrap_or(0),
					exposures.len(),
					Self::minimum_validator_count(),
				),
				None => {
					// The initial era is allowed to have no exposures.
					// In this case the SessionManager is expected to choose a sensible validator
					// set.
					// TODO: this should be simplified #8911
					CurrentEra::<T>::put(0);
					ErasStartSessionIndex::<T>::insert(&0, &start_session_index);
				},
				_ => (),
			}

			Self::deposit_event(Event::StakingElectionFailed);
			return None
		}

		Self::deposit_event(Event::StakersElected);
		Some(Self::trigger_new_era(start_session_index, exposures))
	}
/// Potentially plan a new era.
///
/// Get election result from `T::ElectionProvider`.
/// In case election result has more than [`MinimumValidatorCount`] validator trigger a new era.
///
/// In case a new era is planned, the new validator set is returned.
Potentially plan a new era.
Get election result from `T::ElectionProvider`.
In case election result has more than [`MinimumValidatorCount`] validator trigger a new era.

In case a new era is planned, the new validator set is returned.
Potentially plan a new era . Get election result from ` T :: ElectionProvider ` . In case election result has more than [ ` MinimumValidatorCount ` ] validator trigger a new era . In case a new era is planned the new validator set is returned .
pub(crate) fn try_trigger_new_era(
		start_session_index: SessionIndex,
		is_genesis: bool,
	) -> Option<Vec<T::AccountId>> {
		let (election_result, weight) = if is_genesis {
			T::GenesisElectionProvider::elect().map_err(|e| {
				log!(warn, "genesis election provider failed due to {:?}", e);
				Self::deposit_event(Event::StakingElectionFailed);
			})
		} else {
			T::ElectionProvider::elect().map_err(|e| {
				log!(warn, "election provider failed due to {:?}", e);
				Self::deposit_event(Event::StakingElectionFailed);
			})
		}
		.ok()?;
		<frame_system::Pallet<T>>::register_extra_weight_unchecked(
			weight,
			frame_support::weights::DispatchClass::Mandatory,
		);
		let exposures = Self::collect_exposures(election_result);
		if (exposures.len() as u32) < Self::minimum_validator_count().max(1) {
			// Session will panic if we ever return an empty validator set, thus max(1) ^^.
			match CurrentEra::<T>::get() {
				Some(current_era) if current_era > 0 => log!(
					warn,
					"chain does not have enough staking candidates to operate for era {:?} ({} \
					elected, minimum is {})",
					CurrentEra::<T>::get().unwrap_or(0),
					exposures.len(),
					Self::minimum_validator_count(),
				),
				None => {
					// The initial era is allowed to have no exposures.
					// In this case the SessionManager is expected to choose a sensible validator
					// set.
					// TODO: this should be simplified #8911
					CurrentEra::<T>::put(0);
					ErasStartSessionIndex::<T>::insert(&0, &start_session_index);
				},
				_ => (),
			}
			Self::deposit_event(Event::StakingElectionFailed);
			return None
		}
		Self::deposit_event(Event::StakersElected);
		Some(Self::trigger_new_era(start_session_index, exposures))
	}
pub ( crate ) fn try_trigger_new_era ( start_session_index : SessionIndex , is_genesis : bool , ) -> Option < Vec < T :: AccountId > > { let ( election_result , weight ) = if is_genesis { T :: GenesisElectionProvider :: elect ( ) . map_err ( | e | { log ! ( warn " " e ) ; Self :: deposit_event ( Event :: StakingElectionFailed ) ; } ) } else { T :: ElectionProvider :: elect ( ) . map_err ( | e | { log ! ( warn " " e ) ; Self :: deposit_event ( Event :: StakingElectionFailed ) ; } ) } . ok ( ) ? ; < frame_system :: Pallet < T > > :: register_extra_weight_unchecked ( weight , frame_support :: weights :: DispatchClass :: Mandatory , ) ; let exposures = Self :: collect_exposures ( election_result ) ; if ( exposures . len ( ) as u32 ) < Self :: minimum_validator_count ( ) . max ( 1 ) { // Session will panic if we ever return an empty validator set, thus max(1) ^^. match CurrentEra :: < T > :: get ( ) { Some ( current_era ) if current_era > 0 => log ! ( warn " \
 " CurrentEra T get ( ) unwrap_or ( 0 ) exposures len ( ) Self minimum_validator_count ( ) ) , None => { // The initial era is allowed to have no exposures. // In this case the SessionManager is expected to choose a sensible validator // set. // TODO: this should be simplified #8911 CurrentEra :: < T > :: put ( 0 ) ; ErasStartSessionIndex :: < T > :: insert ( & 0 , & start_session_index ) ; } , _ => ( ) , } Self :: deposit_event ( Event :: StakingElectionFailed ) ; return None } Self :: deposit_event ( Event :: StakersElected ) ; Some ( Self :: trigger_new_era ( start_session_index , exposures ) ) }
Potentially plan a new era.
Potentially plan a new era .
start_session_index
SessionIndex
is_genesis
bool
start_session_index
SessionIndex
is_genesis
bool