pub fn compute_proposer_index(
        &self,
        indices: &[usize],
        seed: &[u8],
        spec: &ChainSpec,
    ) -> Result<usize, Error> {
        if indices.is_empty() {
            return Err(Error::InsufficientValidators);
        }

        let mut i = 0;
        loop {
            let candidate_index = indices[compute_shuffled_index(
                i.safe_rem(indices.len())?,
                indices.len(),
                seed,
                spec.shuffle_round_count,
            )
            .ok_or(Error::UnableToShuffle)?];
            let random_byte = {
                let mut preimage = seed.to_vec();
                preimage.append(&mut int_to_bytes8(i.safe_div(32)? as u64));
                let hash = hash(&preimage);
                hash[i.safe_rem(32)?]
            };
            let effective_balance = self.validators[candidate_index].effective_balance;
            if effective_balance.safe_mul(MAX_RANDOM_BYTE)?
                >= spec
                    .max_effective_balance
                    .safe_mul(u64::from(random_byte))?
            {
                return Ok(candidate_index);
            }
            i.safe_add_assign(1)?;
        }
    }
/// Compute the proposer (not necessarily for the Beacon chain) from a list of indices.
///
/// Spec v0.12.1
// NOTE: be sure to test this bad boy.
Compute the proposer (not necessarily for the Beacon chain) from a list of indices.
Spec v0.12.1
NOTE: be sure to test this bad boy.
Compute the proposer ( not necessarily for the Beacon chain ) from a list of indices . Spec v0 . 12 . 1 NOTE : be sure to test this bad boy .
pub fn compute_proposer_index(
        &self,
        indices: &[usize],
        seed: &[u8],
        spec: &ChainSpec,
    ) -> Result<usize, Error> {
        if indices.is_empty() {
            return Err(Error::InsufficientValidators);
        }
        let mut i = 0;
        loop {
            let candidate_index = indices[compute_shuffled_index(
                i.safe_rem(indices.len())?,
                indices.len(),
                seed,
                spec.shuffle_round_count,
            )
            .ok_or(Error::UnableToShuffle)?];
            let random_byte = {
                let mut preimage = seed.to_vec();
                preimage.append(&mut int_to_bytes8(i.safe_div(32)? as u64));
                let hash = hash(&preimage);
                hash[i.safe_rem(32)?]
            };
            let effective_balance = self.validators[candidate_index].effective_balance;
            if effective_balance.safe_mul(MAX_RANDOM_BYTE)?
                >= spec
                    .max_effective_balance
                    .safe_mul(u64::from(random_byte))?
            {
                return Ok(candidate_index);
            }
            i.safe_add_assign(1)?;
        }
    }
pub fn compute_proposer_index ( & self , indices : & [ usize ] , seed : & [ u8 ] , spec : & ChainSpec , ) -> Result < usize , Error > { if indices . is_empty ( ) { return Err ( Error :: InsufficientValidators ) ; } let mut i = 0 ; loop { let candidate_index = indices [ compute_shuffled_index ( i . safe_rem ( indices . len ( ) ) ? , indices . len ( ) , seed , spec . shuffle_round_count , ) . ok_or ( Error :: UnableToShuffle ) ? ] ; let random_byte = { let mut preimage = seed . to_vec ( ) ; preimage . append ( & mut int_to_bytes8 ( i . safe_div ( 32 ) ? as u64 ) ) ; let hash = hash ( & preimage ) ; hash [ i . safe_rem ( 32 ) ? ] } ; let effective_balance = self . validators [ candidate_index ] . effective_balance ; if effective_balance . safe_mul ( MAX_RANDOM_BYTE ) ? >= spec . max_effective_balance . safe_mul ( u64 :: from ( random_byte ) ) ? { return Ok ( candidate_index ) ; } i . safe_add_assign ( 1 ) ? ; } }
Compute the proposer (not necessarily for the Beacon chain) from a list of indices.
Compute the proposer ( not necessarily for the Beacon chain ) from a list of indices .
&self
indices
&[usize]
seed
&[u8]
spec
&ChainSpec