Merge PR #3836: Fix WithdrawValidatorCommission
This commit is contained in:
parent
db421fc0a6
commit
b316c477c1
|
@ -44,11 +44,13 @@
|
||||||
* #3808 `gaiad` and `gaiacli` integration tests use ./build/ binaries.
|
* #3808 `gaiad` and `gaiacli` integration tests use ./build/ binaries.
|
||||||
|
|
||||||
### SDK
|
### SDK
|
||||||
|
|
||||||
* #3801 `baseapp` saftey improvements
|
* #3801 `baseapp` saftey improvements
|
||||||
|
|
||||||
### Tendermint
|
### Tendermint
|
||||||
|
|
||||||
### CI/CD
|
### CI/CD
|
||||||
|
|
||||||
* [\198](https://github.com/cosmos/cosmos-sdk/pull/3832)
|
* [\198](https://github.com/cosmos/cosmos-sdk/pull/3832)
|
||||||
|
|
||||||
<!--------------------------------- BUG FIXES -------------------------------->
|
<!--------------------------------- BUG FIXES -------------------------------->
|
||||||
|
@ -63,4 +65,7 @@
|
||||||
|
|
||||||
### SDK
|
### SDK
|
||||||
|
|
||||||
|
* [\#3837] Fix `WithdrawValidatorCommission` to properly set the validator's
|
||||||
|
remaining commission.
|
||||||
|
|
||||||
### Tendermint
|
### Tendermint
|
||||||
|
|
|
@ -179,7 +179,9 @@ func (coins DecCoins) TruncateDecimal() (Coins, DecCoins) {
|
||||||
for i, coin := range coins {
|
for i, coin := range coins {
|
||||||
truncated, change := coin.TruncateDecimal()
|
truncated, change := coin.TruncateDecimal()
|
||||||
out[i] = truncated
|
out[i] = truncated
|
||||||
changeSum = changeSum.Add(DecCoins{change})
|
if !change.IsZero() {
|
||||||
|
changeSum = changeSum.Add(DecCoins{change})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return out, changeSum
|
return out, changeSum
|
||||||
|
|
|
@ -79,9 +79,7 @@ func (k Keeper) WithdrawValidatorCommission(ctx sdk.Context, valAddr sdk.ValAddr
|
||||||
}
|
}
|
||||||
|
|
||||||
coins, remainder := commission.TruncateDecimal()
|
coins, remainder := commission.TruncateDecimal()
|
||||||
|
k.SetValidatorAccumulatedCommission(ctx, valAddr, remainder) // leave remainder to withdraw later
|
||||||
// leave remainder to withdraw later
|
|
||||||
k.SetValidatorAccumulatedCommission(ctx, valAddr, remainder)
|
|
||||||
|
|
||||||
// update outstanding
|
// update outstanding
|
||||||
outstanding := k.GetValidatorOutstandingRewards(ctx, valAddr)
|
outstanding := k.GetValidatorOutstandingRewards(ctx, valAddr)
|
||||||
|
|
|
@ -237,9 +237,16 @@ func (k Keeper) GetValidatorAccumulatedCommission(ctx sdk.Context, val sdk.ValAd
|
||||||
|
|
||||||
// set accumulated commission for a validator
|
// set accumulated commission for a validator
|
||||||
func (k Keeper) SetValidatorAccumulatedCommission(ctx sdk.Context, val sdk.ValAddress, commission types.ValidatorAccumulatedCommission) {
|
func (k Keeper) SetValidatorAccumulatedCommission(ctx sdk.Context, val sdk.ValAddress, commission types.ValidatorAccumulatedCommission) {
|
||||||
|
var bz []byte
|
||||||
|
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
b := k.cdc.MustMarshalBinaryLengthPrefixed(commission)
|
if commission.IsZero() {
|
||||||
store.Set(GetValidatorAccumulatedCommissionKey(val), b)
|
bz = k.cdc.MustMarshalBinaryLengthPrefixed(types.InitialValidatorAccumulatedCommission())
|
||||||
|
} else {
|
||||||
|
bz = k.cdc.MustMarshalBinaryLengthPrefixed(commission)
|
||||||
|
}
|
||||||
|
|
||||||
|
store.Set(GetValidatorAccumulatedCommissionKey(val), bz)
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete accumulated commission for a validator
|
// delete accumulated commission for a validator
|
||||||
|
|
Loading…
Reference in New Issue