Skip to content

Commit

Permalink
Merge PR #3836: Fix WithdrawValidatorCommission
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez authored and cwgoes committed Mar 12, 2019
1 parent db421fc commit b316c47
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
5 changes: 5 additions & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 -------------------------------->
Expand All @@ -63,4 +65,7 @@

### SDK

* [\#3837] Fix `WithdrawValidatorCommission` to properly set the validator's
remaining commission.

### Tendermint
4 changes: 3 additions & 1 deletion types/dec_coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions x/distribution/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions x/distribution/keeper/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b316c47

Please sign in to comment.