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

[Altair] Return error when total balance is zero #2366

Merged
merged 1 commit into from
May 25, 2021
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
13 changes: 5 additions & 8 deletions consensus/state_processing/src/common/altair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ pub fn get_base_reward<T: EthSpec>(
total_active_balance: u64,
spec: &ChainSpec,
) -> Result<u64, Error> {
if total_active_balance == 0 {
Ok(0)
} else {
Ok(state
.get_effective_balance(index)?
.safe_div(spec.effective_balance_increment)?
.safe_mul(get_base_reward_per_increment(total_active_balance, spec)?)?)
}
state
.get_effective_balance(index)?
.safe_div(spec.effective_balance_increment)?
.safe_mul(get_base_reward_per_increment(total_active_balance, spec)?)
.map_err(Into::into)
}

/// Returns the base reward for some validator.
Expand Down
15 changes: 6 additions & 9 deletions consensus/state_processing/src/common/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@ pub fn get_base_reward<T: EthSpec>(
total_active_balance: u64,
spec: &ChainSpec,
) -> Result<u64, BeaconStateError> {
if total_active_balance == 0 {
Ok(0)
} else {
Ok(state
.get_effective_balance(index)?
.safe_mul(spec.base_reward_factor)?
.safe_div(total_active_balance.integer_sqrt())?
.safe_div(spec.base_rewards_per_epoch)?)
}
state
.get_effective_balance(index)?
.safe_mul(spec.base_reward_factor)?
.safe_div(total_active_balance.integer_sqrt())?
.safe_div(spec.base_rewards_per_epoch)
.map_err(Into::into)
}