Merge PR #3726: Cap(clip) reward to remaining coins in AllocateTokens

This commit is contained in:
Jae Kwon
2019-02-27 21:38:57 +01:00
committed by Christopher Goes
parent e78a6da2bf
commit 7e08b62f4e
4 changed files with 49 additions and 1 deletions
+2 -1
View File
@@ -48,10 +48,11 @@ func (k Keeper) AllocateTokens(ctx sdk.Context, sumPrecommitPower, totalPower in
for _, vote := range votes {
validator := k.stakingKeeper.ValidatorByConsAddr(ctx, vote.Validator.Address)
// TODO likely we should only reward validators who actually signed the block.
// TODO consider microslashing for missing votes.
// ref https://github.com/cosmos/cosmos-sdk/issues/2525#issuecomment-430838701
powerFraction := sdk.NewDec(vote.Validator.Power).QuoTruncate(sdk.NewDec(totalPower))
reward := feesCollected.MulDecTruncate(voteMultiplier).MulDecTruncate(powerFraction)
reward = reward.Cap(remaining)
k.AllocateTokensToValidator(ctx, validator, reward)
remaining = remaining.Sub(reward)
}