mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2024-12-22 03:30:38 +00:00
Fix overflow in reward calculations
Overflow occurs when using updated issuance parameters.
This commit is contained in:
parent
37f77c19c7
commit
2b3eb7b12d
@ -44,7 +44,7 @@ fn get_base_reward_per_increment(
|
||||
total_active_balance: u128,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<u64, ArithError> {
|
||||
spec.effective_balance_increment
|
||||
.safe_mul(spec.base_reward_factor)?
|
||||
.safe_div(total_active_balance.integer_sqrt() as u64)
|
||||
Ok((spec.effective_balance_increment as u128)
|
||||
.safe_mul(spec.base_reward_factor as u128)?
|
||||
.safe_div(total_active_balance.integer_sqrt())? as u64)
|
||||
}
|
||||
|
@ -22,14 +22,14 @@ pub fn process_slashings<T: EthSpec>(
|
||||
&& epoch.safe_add(T::EpochsPerSlashingsVector::to_u64().safe_div(2)?)?
|
||||
== validator.withdrawable_epoch
|
||||
{
|
||||
let increment = spec.effective_balance_increment;
|
||||
let increment = spec.effective_balance_increment as u128;
|
||||
let effective_balance = validator.effective_balance as u128;
|
||||
let penalty_numerator = effective_balance
|
||||
.safe_div(increment as u128)?
|
||||
.safe_div(increment)?
|
||||
.safe_mul(adjusted_total_slashing_balance)?;
|
||||
let penalty = penalty_numerator
|
||||
.safe_div(total_balance)?
|
||||
.safe_mul(increment as u128)?;
|
||||
.safe_mul(increment)?;
|
||||
|
||||
// Equivalent to `decrease_balance(state, index, penalty)`, but avoids borrowing `state`.
|
||||
let balance = balances
|
||||
|
Loading…
Reference in New Issue
Block a user