mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Correct how we handle rounding errors within the penalty fn
We explicitly no longer slash stakes but we still set the maximum slash to the allocated stake + the rewards. Now, the reward slash is bound to the rewards and the stake slash is bound to the stake. This prevents an improperly rounded reward slash from effecting a stake slash.
This commit is contained in:
@@ -121,6 +121,8 @@ impl Slash {
|
||||
}
|
||||
})
|
||||
};
|
||||
// Ensure the slash never exceeds the amount slashable (due to rounding errors)
|
||||
let reward_slash = reward_slash.min(session_rewards);
|
||||
|
||||
/*
|
||||
let slash_points_for_entire_session =
|
||||
@@ -192,10 +194,9 @@ impl Slash {
|
||||
let offline_slash = 0;
|
||||
let disruptive_slash = 0;
|
||||
|
||||
// The penalty is all slashes, but never more than the validator's balance
|
||||
// (handles any rounding errors which may or may not exist)
|
||||
let penalty_u128 =
|
||||
(reward_slash + offline_slash + disruptive_slash).min(allocated_stake + session_rewards);
|
||||
let stake_slash = (offline_slash + disruptive_slash).min(allocated_stake);
|
||||
|
||||
let penalty_u128 = reward_slash + stake_slash;
|
||||
// saturating_into
|
||||
Amount(u64::try_from(penalty_u128).unwrap_or(u64::MAX))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user