pub(crate) fn new(highway: &Highway<C>) -> Self {
        let now = Timestamp::now();
        let state = highway.state();
        let mut inactive_w = 0;
        let mut faulty_w = 0;
        let total_w = u128::from(state.total_weight().0);
        let mut inactive_validators = Vec::new();
        let mut faulty_validators = Vec::new();
        for (idx, v_id) in highway.validators().enumerate_ids() {
            if let Some(status) = Status::for_index(idx, state, now) {
                match status {
                    Status::Equivocated | Status::EquivocatedInOtherEra => {
                        faulty_w += u128::from(state.weight(idx).0);
                        faulty_validators.push((idx, v_id.clone(), status));
                    }
                    Status::Inactive | Status::LastSeenSecondsAgo(_) => {
                        inactive_w += u128::from(state.weight(idx).0);
                        inactive_validators.push((idx, v_id.clone(), status));
                    }
                }
            }
        }
        inactive_validators.sort_by_key(|(idx, _, status)| (Reverse(*status), *idx));
        faulty_validators.sort_by_key(|(idx, _, status)| (Reverse(*status), *idx));
        Participation {
            instance_id: *highway.instance_id(),
            inactive_stake_percent: div_round(inactive_w * 100, total_w) as u8,
            faulty_stake_percent: div_round(faulty_w * 100, total_w) as u8,
            inactive_validators,
            faulty_validators,
        }
    }
// We use u128 to prevent overflows in weight calculation.
We use u128 to prevent overflows in weight calculation.
We use u128 to prevent overflows in weight calculation .
pub(crate) fn new(highway: &Highway<C>) -> Self {
        let now = Timestamp::now();
        let state = highway.state();
        let mut inactive_w = 0;
        let mut faulty_w = 0;
        let total_w = u128::from(state.total_weight().0);
        let mut inactive_validators = Vec::new();
        let mut faulty_validators = Vec::new();
        for (idx, v_id) in highway.validators().enumerate_ids() {
            if let Some(status) = Status::for_index(idx, state, now) {
                match status {
                    Status::Equivocated | Status::EquivocatedInOtherEra => {
                        faulty_w += u128::from(state.weight(idx).0);
                        faulty_validators.push((idx, v_id.clone(), status));
                    }
                    Status::Inactive | Status::LastSeenSecondsAgo(_) => {
                        inactive_w += u128::from(state.weight(idx).0);
                        inactive_validators.push((idx, v_id.clone(), status));
                    }
                }
            }
        }
        inactive_validators.sort_by_key(|(idx, _, status)| (Reverse(*status), *idx));
        faulty_validators.sort_by_key(|(idx, _, status)| (Reverse(*status), *idx));
        Participation {
            instance_id: *highway.instance_id(),
            inactive_stake_percent: div_round(inactive_w * 100, total_w) as u8,
            faulty_stake_percent: div_round(faulty_w * 100, total_w) as u8,
            inactive_validators,
            faulty_validators,
        }
    }
pub ( crate ) fn new ( highway : & Highway < C > ) -> Self { let now = Timestamp :: now ( ) ; let state = highway . state ( ) ; let mut inactive_w = 0 ; let mut faulty_w = 0 ; let total_w = u128 :: from ( state . total_weight ( ) . 0 ) ; let mut inactive_validators = Vec :: new ( ) ; let mut faulty_validators = Vec :: new ( ) ; for ( idx , v_id ) in highway . validators ( ) . enumerate_ids ( ) { if let Some ( status ) = Status :: for_index ( idx , state , now ) { match status { Status :: Equivocated | Status :: EquivocatedInOtherEra => { faulty_w += u128 :: from ( state . weight ( idx ) . 0 ) ; faulty_validators . push ( ( idx , v_id . clone ( ) , status ) ) ; } Status :: Inactive | Status :: LastSeenSecondsAgo ( _ ) => { inactive_w += u128 :: from ( state . weight ( idx ) . 0 ) ; inactive_validators . push ( ( idx , v_id . clone ( ) , status ) ) ; } } } } inactive_validators . sort_by_key ( | ( idx , _ , status ) | ( Reverse ( * status ) , * idx ) ) ; faulty_validators . sort_by_key ( | ( idx , _ , status ) | ( Reverse ( * status ) , * idx ) ) ; Participation { instance_id : * highway . instance_id ( ) , inactive_stake_percent : div_round ( inactive_w * 100 , total_w ) as u8 , faulty_stake_percent : div_round ( faulty_w * 100 , total_w ) as u8 , inactive_validators , faulty_validators , } }
We use u128 to prevent overflows in weight calculation.
We use u128 to prevent overflows in weight calculation .
highway
&Highway<C>
highway
&Highway<C>