Use LTE instead of Equal (#4503)

This commit is contained in:
Alexander Bezobchuk 2019-06-06 16:32:14 -04:00 committed by frog power 4000
parent 3180e68c7b
commit 86da70d8aa
1 changed files with 6 additions and 3 deletions

View File

@ -98,14 +98,16 @@ func (k Keeper) calculateDelegationRewards(ctx sdk.Context, val exported.Validat
// when multiplied by slash fractions (see above). We could only use equals if
// we had arbitrary-precision rationals.
currentStake := val.TokensFromShares(del.GetShares())
if stake.GT(currentStake) {
if stake.GT(currentStake) {
// Account for rounding inconsistencies between:
//
// currentStake: calculated as in staking with a single computation
// stake: calculated as an accumulation of stake
// calculations across validator's distribution periods
//
// These inconsistencies are due to differing order of operations which
// will inevitably have different accumulated rounding and may lead to
// will inevitably have different accumulated rounding and may lead to
// the smallest decimal place being one greater in stake than
// currentStake. When we calculated slashing by period, even if we
// round down for each slash fraction, it's possible due to how much is
@ -118,7 +120,8 @@ func (k Keeper) calculateDelegationRewards(ctx sdk.Context, val exported.Validat
// A small amount of this error is tolerated and corrected for,
// however any greater amount should be considered a breach in expected
// behaviour.
if stake.Equal(currentStake.Add(sdk.SmallestDec().MulInt64(3))) {
marginOfErr := sdk.SmallestDec().MulInt64(3)
if stake.LTE(currentStake.Add(marginOfErr)) {
stake = currentStake
} else {
panic(fmt.Sprintf("calculated final stake for delegator %s greater than current stake"+