Skip to content

Commit

Permalink
fix(distribution): rewards stake calculation (cosmos#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
ezreal1997 authored Jan 18, 2025
1 parent 0513e90 commit 634759f
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions x/distribution/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper

import (
"context"
"fmt"

"cosmossdk.io/math"

Expand Down Expand Up @@ -171,14 +170,18 @@ func (k Keeper) CalculateDelegationRewards(ctx context.Context, val stakingtypes
// however any greater amount should be considered a breach in expected
// behavior.
marginOfErr := math.LegacySmallestDec().MulInt64(3)
if rewardsStake.LTE(currentRewardsStake.Add(marginOfErr)) {
rewardsStake = currentRewardsStake
} else {
panic(fmt.Sprintf("calculated final rewards stake for delegator %s greater than current rewards stake"+
"\n\tfinal rewards stake:\t%s"+
"\n\tcurrent rewards stake:\t%s",
del.GetDelegatorAddr(), rewardsStake, currentRewardsStake))
if rewardsStake.GT(currentRewardsStake.Add(marginOfErr)) {
k.Logger(ctx).Error(
"[MONITOR] Calculated final rewards stake for delegator greater than current rewards stake",
"delegator", del.GetDelegatorAddr(),
"validator", del.GetValidatorAddr(),
"calculated_rewards_stake", rewardsStake.String(),
"current_rewards_stake", currentRewardsStake.String(),
"start_height", startingHeight,
"end_height", endingHeight,
)
}
rewardsStake = currentRewardsStake.TruncateDec()
}

// calculate rewards for final period
Expand Down

0 comments on commit 634759f

Please sign in to comment.