diff --git a/consensus/types/src/beacon_state.rs b/consensus/types/src/beacon_state.rs index 295aaade1cf..8642036ad61 100644 --- a/consensus/types/src/beacon_state.rs +++ b/consensus/types/src/beacon_state.rs @@ -892,6 +892,8 @@ impl BeaconState { return Err(Error::InsufficientValidators); } + let max_effective_balance = spec.max_effective_balance_for_fork(self.fork_name_unchecked()); + let mut i = 0; loop { let shuffled_index = compute_shuffled_index( @@ -907,9 +909,7 @@ impl BeaconState { let random_byte = Self::shuffling_random_byte(i, seed)?; let effective_balance = self.get_effective_balance(candidate_index)?; if effective_balance.safe_mul(MAX_RANDOM_BYTE)? - >= spec - .max_effective_balance - .safe_mul(u64::from(random_byte))? + >= max_effective_balance.safe_mul(u64::from(random_byte))? { return Ok(candidate_index); } @@ -1091,6 +1091,8 @@ impl BeaconState { let seed = self.get_seed(epoch, Domain::SyncCommittee, spec)?; + let max_effective_balance = spec.max_effective_balance_for_fork(self.fork_name_unchecked()); + let mut i = 0; let mut sync_committee_indices = Vec::with_capacity(E::SyncCommitteeSize::to_usize()); while sync_committee_indices.len() < E::SyncCommitteeSize::to_usize() { @@ -1107,9 +1109,7 @@ impl BeaconState { let random_byte = Self::shuffling_random_byte(i, seed.as_bytes())?; let effective_balance = self.get_validator(candidate_index)?.effective_balance; if effective_balance.safe_mul(MAX_RANDOM_BYTE)? - >= spec - .max_effective_balance - .safe_mul(u64::from(random_byte))? + >= max_effective_balance.safe_mul(u64::from(random_byte))? { sync_committee_indices.push(candidate_index); } diff --git a/consensus/types/src/validator.rs b/consensus/types/src/validator.rs index b5e92d1f5d8..4173e18526e 100644 --- a/consensus/types/src/validator.rs +++ b/consensus/types/src/validator.rs @@ -219,6 +219,7 @@ impl Validator { } } + /// TODO(electra): refactor these functions and make it simpler.. this is a mess /// Returns `true` if the validator is partially withdrawable. fn is_partially_withdrawable_validator_capella(&self, balance: u64, spec: &ChainSpec) -> bool { self.has_eth1_withdrawal_credential(spec)