diff --git a/PENDING.md b/PENDING.md index 007108cf7..1908cdae5 100644 --- a/PENDING.md +++ b/PENDING.md @@ -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) @@ -63,4 +65,7 @@ ### SDK +* [\#3837] Fix `WithdrawValidatorCommission` to properly set the validator's +remaining commission. + ### Tendermint diff --git a/types/dec_coin.go b/types/dec_coin.go index 19d5db2bd..4e734d2d7 100644 --- a/types/dec_coin.go +++ b/types/dec_coin.go @@ -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 diff --git a/x/distribution/keeper/keeper.go b/x/distribution/keeper/keeper.go index 0652a5166..5741893aa 100644 --- a/x/distribution/keeper/keeper.go +++ b/x/distribution/keeper/keeper.go @@ -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) diff --git a/x/distribution/keeper/store.go b/x/distribution/keeper/store.go index 1326c89d4..894ef9c56 100644 --- a/x/distribution/keeper/store.go +++ b/x/distribution/keeper/store.go @@ -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