fn run_auction(
        &mut self,
        era_end_timestamp_millis: u64,
        evicted_validators: Vec<PublicKey>,
    ) -> Result<(), Error> {
        if self.get_caller() != PublicKey::System.to_account_hash() {
            return Err(Error::InvalidCaller);
        }

        let validator_slots = detail::get_validator_slots(self)?;
        let auction_delay = detail::get_auction_delay(self)?;
        let snapshot_size = auction_delay as usize + 1;
        let mut era_id: EraId = detail::get_era_id(self)?;
        let mut bids = detail::get_bids(self)?;

        // Process unbond requests
        detail::process_unbond_requests(self)?;

        // Process bids
        let mut bids_modified = false;
        for (validator_public_key, bid) in bids.iter_mut() {
            if bid.process(era_end_timestamp_millis) {
                bids_modified = true;
            }

            if evicted_validators.contains(validator_public_key) {
                bids_modified = bid.deactivate()
            }
        }

        // Compute next auction winners
        let winners: ValidatorWeights = {
            let locked_validators: ValidatorWeights = bids
                .iter()
                .filter(|(_public_key, bid)| {
                    bid.is_locked(era_end_timestamp_millis) && !bid.inactive()
                })
                .map(|(public_key, bid)| {
                    let total_staked_amount = bid.total_staked_amount()?;
                    Ok((public_key.clone(), total_staked_amount))
                })
                .collect::<Result<ValidatorWeights, Error>>()?;

            // We collect these into a vec for sorting
            let mut unlocked_validators: Vec<(PublicKey, U512)> = bids
                .iter()
                .filter(|(_public_key, bid)| {
                    !bid.is_locked(era_end_timestamp_millis) && !bid.inactive()
                })
                .map(|(public_key, bid)| {
                    let total_staked_amount = bid.total_staked_amount()?;
                    Ok((public_key.clone(), total_staked_amount))
                })
                .collect::<Result<Vec<(PublicKey, U512)>, Error>>()?;

            unlocked_validators.sort_by(|(_, lhs), (_, rhs)| rhs.cmp(lhs));

            // This assumes that amount of founding validators does not exceed configured validator
            // slots. For a case where there are exactly N validators and the limit is N, only
            // founding validators will be the in the winning set. It is advised to set
            // `validator_slots` larger than amount of founding validators in accounts.toml to
            // accomodate non-genesis validators.
            let remaining_auction_slots = validator_slots.saturating_sub(locked_validators.len());

            locked_validators
                .into_iter()
                .chain(
                    unlocked_validators
                        .into_iter()
                        .take(remaining_auction_slots),
                )
                .collect()
        };

        // Increment era
        era_id = era_id.checked_add(1).ok_or(Error::ArithmeticOverflow)?;

        let delayed_era = era_id
            .checked_add(auction_delay)
            .ok_or(Error::ArithmeticOverflow)?;

        // Update seigniorage recipients for current era
        {
            let mut snapshot = detail::get_seigniorage_recipients_snapshot(self)?;

            let mut recipients = SeigniorageRecipients::new();

            for era_validator in winners.keys() {
                let seigniorage_recipient = match bids.get(era_validator) {
                    Some(bid) => bid.into(),
                    None => return Err(Error::BidNotFound),
                };
                recipients.insert(era_validator.clone(), seigniorage_recipient);
            }

            let previous_recipients = snapshot.insert(delayed_era, recipients);
            assert!(previous_recipients.is_none());

            let snapshot = snapshot.into_iter().rev().take(snapshot_size).collect();
            detail::set_seigniorage_recipients_snapshot(self, snapshot)?;
        }

        detail::set_era_id(self, era_id)?;
        detail::set_era_end_timestamp_millis(self, era_end_timestamp_millis)?;

        if bids_modified {
            detail::set_bids(self, bids)?;
        }

        Ok(())
    }
/// Takes active_bids and delegators to construct a list of validators' total bids (their own
/// added to their delegators') ordered by size from largest to smallest, then takes the top N
/// (number of auction slots) bidders and replaces era_validators with these.
///
/// Accessed by: node
Takes active_bids and delegators to construct a list of validators' total bids (their own
added to their delegators') ordered by size from largest to smallest, then takes the top N
(number of auction slots) bidders and replaces era_validators with these.

Accessed by: node
Takes active_bids and delegators to construct a list of validators ' total bids ( their own added to their delegators ' ) ordered by size from largest to smallest then takes the top N ( number of auction slots ) bidders and replaces era_validators with these . Accessed by : node
fn run_auction(
        &mut self,
        era_end_timestamp_millis: u64,
        evicted_validators: Vec<PublicKey>,
    ) -> Result<(), Error> {
        if self.get_caller() != PublicKey::System.to_account_hash() {
            return Err(Error::InvalidCaller);
        }
        let validator_slots = detail::get_validator_slots(self)?;
        let auction_delay = detail::get_auction_delay(self)?;
        let snapshot_size = auction_delay as usize + 1;
        let mut era_id: EraId = detail::get_era_id(self)?;
        let mut bids = detail::get_bids(self)?;
        // Process unbond requests
        detail::process_unbond_requests(self)?;
        // Process bids
        let mut bids_modified = false;
        for (validator_public_key, bid) in bids.iter_mut() {
            if bid.process(era_end_timestamp_millis) {
                bids_modified = true;
            }
            if evicted_validators.contains(validator_public_key) {
                bids_modified = bid.deactivate()
            }
        }
        // Compute next auction winners
        let winners: ValidatorWeights = {
            let locked_validators: ValidatorWeights = bids
                .iter()
                .filter(|(_public_key, bid)| {
                    bid.is_locked(era_end_timestamp_millis) && !bid.inactive()
                })
                .map(|(public_key, bid)| {
                    let total_staked_amount = bid.total_staked_amount()?;
                    Ok((public_key.clone(), total_staked_amount))
                })
                .collect::<Result<ValidatorWeights, Error>>()?;
            // We collect these into a vec for sorting
            let mut unlocked_validators: Vec<(PublicKey, U512)> = bids
                .iter()
                .filter(|(_public_key, bid)| {
                    !bid.is_locked(era_end_timestamp_millis) && !bid.inactive()
                })
                .map(|(public_key, bid)| {
                    let total_staked_amount = bid.total_staked_amount()?;
                    Ok((public_key.clone(), total_staked_amount))
                })
                .collect::<Result<Vec<(PublicKey, U512)>, Error>>()?;
            unlocked_validators.sort_by(|(_, lhs), (_, rhs)| rhs.cmp(lhs));
            // This assumes that amount of founding validators does not exceed configured validator
            // slots. For a case where there are exactly N validators and the limit is N, only
            // founding validators will be the in the winning set. It is advised to set
            // `validator_slots` larger than amount of founding validators in accounts.toml to
            // accomodate non-genesis validators.
            let remaining_auction_slots = validator_slots.saturating_sub(locked_validators.len());
            locked_validators
                .into_iter()
                .chain(
                    unlocked_validators
                        .into_iter()
                        .take(remaining_auction_slots),
                )
                .collect()
        };
        // Increment era
        era_id = era_id.checked_add(1).ok_or(Error::ArithmeticOverflow)?;
        let delayed_era = era_id
            .checked_add(auction_delay)
            .ok_or(Error::ArithmeticOverflow)?;
        // Update seigniorage recipients for current era
        {
            let mut snapshot = detail::get_seigniorage_recipients_snapshot(self)?;
            let mut recipients = SeigniorageRecipients::new();
            for era_validator in winners.keys() {
                let seigniorage_recipient = match bids.get(era_validator) {
                    Some(bid) => bid.into(),
                    None => return Err(Error::BidNotFound),
                };
                recipients.insert(era_validator.clone(), seigniorage_recipient);
            }
            let previous_recipients = snapshot.insert(delayed_era, recipients);
            assert!(previous_recipients.is_none());
            let snapshot = snapshot.into_iter().rev().take(snapshot_size).collect();
            detail::set_seigniorage_recipients_snapshot(self, snapshot)?;
        }
        detail::set_era_id(self, era_id)?;
        detail::set_era_end_timestamp_millis(self, era_end_timestamp_millis)?;
        if bids_modified {
            detail::set_bids(self, bids)?;
        }
        Ok(())
    }
fn run_auction ( & mut self , era_end_timestamp_millis : u64 , evicted_validators : Vec < PublicKey > , ) -> Result < ( ) , Error > { if self . get_caller ( ) != PublicKey :: System . to_account_hash ( ) { return Err ( Error :: InvalidCaller ) ; } let validator_slots = detail :: get_validator_slots ( self ) ? ; let auction_delay = detail :: get_auction_delay ( self ) ? ; let snapshot_size = auction_delay as usize + 1 ; let mut era_id : EraId = detail :: get_era_id ( self ) ? ; let mut bids = detail :: get_bids ( self ) ? ; // Process unbond requests detail :: process_unbond_requests ( self ) ? ; // Process bids let mut bids_modified = false ; for ( validator_public_key , bid ) in bids . iter_mut ( ) { if bid . process ( era_end_timestamp_millis ) { bids_modified = true ; } if evicted_validators . contains ( validator_public_key ) { bids_modified = bid . deactivate ( ) } } // Compute next auction winners let winners : ValidatorWeights = { let locked_validators : ValidatorWeights = bids . iter ( ) . filter ( | ( _public_key , bid ) | { bid . is_locked ( era_end_timestamp_millis ) && ! bid . inactive ( ) } ) . map ( | ( public_key , bid ) | { let total_staked_amount = bid . total_staked_amount ( ) ? ; Ok ( ( public_key . clone ( ) , total_staked_amount ) ) } ) . collect :: < Result < ValidatorWeights , Error > > ( ) ? ; // We collect these into a vec for sorting let mut unlocked_validators : Vec < ( PublicKey , U512 ) > = bids . iter ( ) . filter ( | ( _public_key , bid ) | { ! bid . is_locked ( era_end_timestamp_millis ) && ! bid . inactive ( ) } ) . map ( | ( public_key , bid ) | { let total_staked_amount = bid . total_staked_amount ( ) ? ; Ok ( ( public_key . clone ( ) , total_staked_amount ) ) } ) . collect :: < Result < Vec < ( PublicKey , U512 ) > , Error > > ( ) ? ; unlocked_validators . sort_by ( | ( _ , lhs ) , ( _ , rhs ) | rhs . cmp ( lhs ) ) ; // This assumes that amount of founding validators does not exceed configured validator // slots. For a case where there are exactly N validators and the limit is N, only // founding validators will be the in the winning set. It is advised to set // `validator_slots` larger than amount of founding validators in accounts.toml to // accomodate non-genesis validators. let remaining_auction_slots = validator_slots . saturating_sub ( locked_validators . len ( ) ) ; locked_validators . into_iter ( ) . chain ( unlocked_validators . into_iter ( ) . take ( remaining_auction_slots ) , ) . collect ( ) } ; // Increment era era_id = era_id . checked_add ( 1 ) . ok_or ( Error :: ArithmeticOverflow ) ? ; let delayed_era = era_id . checked_add ( auction_delay ) . ok_or ( Error :: ArithmeticOverflow ) ? ; // Update seigniorage recipients for current era { let mut snapshot = detail :: get_seigniorage_recipients_snapshot ( self ) ? ; let mut recipients = SeigniorageRecipients :: new ( ) ; for era_validator in winners . keys ( ) { let seigniorage_recipient = match bids . get ( era_validator ) { Some ( bid ) => bid . into ( ) , None => return Err ( Error :: BidNotFound ) , } ; recipients . insert ( era_validator . clone ( ) , seigniorage_recipient ) ; } let previous_recipients = snapshot . insert ( delayed_era , recipients ) ; assert ! ( previous_recipients is_none ( ) ) ; let snapshot = snapshot . into_iter ( ) . rev ( ) . take ( snapshot_size ) . collect ( ) ; detail :: set_seigniorage_recipients_snapshot ( self , snapshot ) ? ; } detail :: set_era_id ( self , era_id ) ? ; detail :: set_era_end_timestamp_millis ( self , era_end_timestamp_millis ) ? ; if bids_modified { detail :: set_bids ( self , bids ) ? ; } Ok ( ( ) ) }
Takes active_bids and delegators to construct a list of validators' total bids (their own
added to their delegators') ordered by size from largest to smallest, then takes the top N
(number of auction slots) bidders and replaces era_validators with these.
Takes active_bids and delegators to construct a list of validators ' total bids ( their own added to their delegators ' ) ordered by size from largest to smallest then takes the top N ( number of auction slots ) bidders and replaces era_validators with these .
&mut self
era_end_timestamp_millis
u64
evicted_validators
Vec<PublicKey>
&mut self
era_end_timestamp_millis
u64
evicted_validators
Vec<PublicKey>