Merge PR #3836: Fix WithdrawValidatorCommission

This commit is contained in:
Alexander Bezobchuk 2019-03-12 11:10:20 -04:00 committed by Christopher Goes
parent db421fc0a6
commit b316c477c1
4 changed files with 18 additions and 6 deletions

View File

@ -44,11 +44,13 @@
* #3808 `gaiad` and `gaiacli` integration tests use ./build/ binaries.
### SDK
* #3801 `baseapp` saftey improvements
### Tendermint
### CI/CD
* [\198](https://github.com/cosmos/cosmos-sdk/pull/3832)
<!--------------------------------- BUG FIXES -------------------------------->
@ -63,4 +65,7 @@
### SDK
* [\#3837] Fix `WithdrawValidatorCommission` to properly set the validator's
remaining commission.
### Tendermint

View File

@ -179,7 +179,9 @@ func (coins DecCoins) TruncateDecimal() (Coins, DecCoins) {
for i, coin := range coins {
truncated, change := coin.TruncateDecimal()
out[i] = truncated
changeSum = changeSum.Add(DecCoins{change})
if !change.IsZero() {
changeSum = changeSum.Add(DecCoins{change})
}
}
return out, changeSum

View File

@ -79,9 +79,7 @@ func (k Keeper) WithdrawValidatorCommission(ctx sdk.Context, valAddr sdk.ValAddr
}
coins, remainder := commission.TruncateDecimal()
// leave remainder to withdraw later
k.SetValidatorAccumulatedCommission(ctx, valAddr, remainder)
k.SetValidatorAccumulatedCommission(ctx, valAddr, remainder) // leave remainder to withdraw later
// update outstanding
outstanding := k.GetValidatorOutstandingRewards(ctx, valAddr)

View File

@ -237,9 +237,16 @@ func (k Keeper) GetValidatorAccumulatedCommission(ctx sdk.Context, val sdk.ValAd
// set accumulated commission for a validator
func (k Keeper) SetValidatorAccumulatedCommission(ctx sdk.Context, val sdk.ValAddress, commission types.ValidatorAccumulatedCommission) {
var bz []byte
store := ctx.KVStore(k.storeKey)
b := k.cdc.MustMarshalBinaryLengthPrefixed(commission)
store.Set(GetValidatorAccumulatedCommissionKey(val), b)
if commission.IsZero() {
bz = k.cdc.MustMarshalBinaryLengthPrefixed(types.InitialValidatorAccumulatedCommission())
} else {
bz = k.cdc.MustMarshalBinaryLengthPrefixed(commission)
}
store.Set(GetValidatorAccumulatedCommissionKey(val), bz)
}
// delete accumulated commission for a validator