Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Calculations Relying on MAX_EB #5983

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions consensus/types/src/beacon_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,8 @@ impl<E: EthSpec> BeaconState<E> {
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(
Expand All @@ -907,9 +909,7 @@ impl<E: EthSpec> BeaconState<E> {
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);
}
Expand Down Expand Up @@ -1091,6 +1091,8 @@ impl<E: EthSpec> BeaconState<E> {

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() {
Expand All @@ -1107,9 +1109,7 @@ impl<E: EthSpec> BeaconState<E> {
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);
}
Expand Down
1 change: 1 addition & 0 deletions consensus/types/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading