mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2025-01-03 01:37:39 +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,
|
total_active_balance: u128,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
) -> Result<u64, ArithError> {
|
) -> Result<u64, ArithError> {
|
||||||
spec.effective_balance_increment
|
Ok((spec.effective_balance_increment as u128)
|
||||||
.safe_mul(spec.base_reward_factor)?
|
.safe_mul(spec.base_reward_factor as u128)?
|
||||||
.safe_div(total_active_balance.integer_sqrt() as u64)
|
.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)?)?
|
&& epoch.safe_add(T::EpochsPerSlashingsVector::to_u64().safe_div(2)?)?
|
||||||
== validator.withdrawable_epoch
|
== 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 effective_balance = validator.effective_balance as u128;
|
||||||
let penalty_numerator = effective_balance
|
let penalty_numerator = effective_balance
|
||||||
.safe_div(increment as u128)?
|
.safe_div(increment)?
|
||||||
.safe_mul(adjusted_total_slashing_balance)?;
|
.safe_mul(adjusted_total_slashing_balance)?;
|
||||||
let penalty = penalty_numerator
|
let penalty = penalty_numerator
|
||||||
.safe_div(total_balance)?
|
.safe_div(total_balance)?
|
||||||
.safe_mul(increment as u128)?;
|
.safe_mul(increment)?;
|
||||||
|
|
||||||
// Equivalent to `decrease_balance(state, index, penalty)`, but avoids borrowing `state`.
|
// Equivalent to `decrease_balance(state, index, penalty)`, but avoids borrowing `state`.
|
||||||
let balance = balances
|
let balance = balances
|
||||||
|
Loading…
Reference in New Issue
Block a user