@@ -16,6 +16,7 @@ func (k Keeper) initializeDelegation(ctx sdk.Context, val sdk.ValAddress, del sd
1616
1717 // calculate delegation stake in tokens
1818 // we don't store directly, so multiply delegation shares * (tokens per share)
19+ // note: necessary to truncate so we don't allow withdrawing more rewards than owed
1920 stake := delegation .GetShares ().MulTruncate (validator .GetDelegatorShareExRate ())
2021 k .SetDelegatorStartingInfo (ctx , val , del , types .NewDelegatorStartingInfo (previousPeriod , stake , uint64 (ctx .BlockHeight ())))
2122}
@@ -32,6 +33,7 @@ func (k Keeper) calculateDelegationRewardsBetween(ctx sdk.Context, val sdk.Valid
3233 starting := k .GetValidatorHistoricalRewards (ctx , val .GetOperator (), startingPeriod )
3334 ending := k .GetValidatorHistoricalRewards (ctx , val .GetOperator (), endingPeriod )
3435 difference := ending .CumulativeRewardRatio .Minus (starting .CumulativeRewardRatio )
36+ // note: necessary to truncate so we don't allow withdrawing more rewards than owed
3537 rewards = difference .MulDecTruncate (stake )
3638 return
3739}
@@ -54,6 +56,7 @@ func (k Keeper) calculateDelegationRewards(ctx sdk.Context, val sdk.Validator, d
5456 func (height uint64 , event types.ValidatorSlashEvent ) (stop bool ) {
5557 endingPeriod := event .ValidatorPeriod
5658 rewards = rewards .Plus (k .calculateDelegationRewardsBetween (ctx , val , startingPeriod , endingPeriod , stake ))
59+ // note: necessary to truncate so we don't allow withdrawing more rewards than owed
5760 stake = stake .MulTruncate (sdk .OneDec ().Sub (event .Fraction ))
5861 startingPeriod = endingPeriod
5962 return false
0 commit comments