Merge PR #3163: Withdraw commission on self bond removal

* Withdraw commission on self bond removal
* Update PENDING.md
This commit is contained in:
Hendrik Hofstadt 2018-12-19 17:05:33 +01:00 committed by Christopher Goes
parent 46620d4abc
commit 2be19b9d33
3 changed files with 19 additions and 4 deletions

View File

@ -10,6 +10,8 @@ BREAKING CHANGES
* SDK
* \#3163 Withdraw commission on self bond removal
* Tendermint

View File

@ -87,6 +87,10 @@ func (k Keeper) onDelegationSharesModified(ctx sdk.Context, delAddr sdk.AccAddre
// Withdrawal all validator distribution rewards and cleanup the distribution record
func (k Keeper) onDelegationRemoved(ctx sdk.Context, delAddr sdk.AccAddress,
valAddr sdk.ValAddress) {
if valAddr.Equals(sdk.ValAddress(delAddr)) {
feePool, commission := k.withdrawValidatorCommission(ctx, valAddr)
k.WithdrawToDelegator(ctx, feePool, delAddr, commission)
}
k.RemoveDelegationDistInfo(ctx, delAddr, valAddr)
}

View File

@ -42,6 +42,9 @@ func (k Keeper) RemoveValidatorDistInfo(ctx sdk.Context, valAddr sdk.ValAddress)
if vdi.DelAccum.Accum.IsPositive() {
panic("Should not delete validator with unwithdrawn delegator accum")
}
if !vdi.ValCommission.IsZero() {
panic("Should not delete validator with unwithdrawn validator commission")
}
store := ctx.KVStore(k.storeKey)
store.Delete(GetValidatorDistInfoKey(valAddr))
@ -119,6 +122,15 @@ func (k Keeper) takeValidatorFeePoolRewards(ctx sdk.Context, operatorAddr sdk.Va
return nil
}
func (k Keeper) withdrawValidatorCommission(ctx sdk.Context, operatorAddr sdk.ValAddress) (types.FeePool, types.DecCoins) {
valInfo := k.GetValidatorDistInfo(ctx, operatorAddr)
wc := k.GetWithdrawContext(ctx, operatorAddr)
valInfo, feePool, commission := valInfo.WithdrawCommission(wc)
k.SetValidatorDistInfo(ctx, valInfo)
return feePool, commission
}
// withdrawal all the validator rewards including the commission
func (k Keeper) WithdrawValidatorRewardsAll(ctx sdk.Context, operatorAddr sdk.ValAddress) sdk.Error {
if !k.HasValidatorDistInfo(ctx, operatorAddr) {
@ -130,11 +142,8 @@ func (k Keeper) WithdrawValidatorRewardsAll(ctx sdk.Context, operatorAddr sdk.Va
withdraw := k.withdrawDelegationRewardsAll(ctx, accAddr)
// withdrawal validator commission rewards
valInfo := k.GetValidatorDistInfo(ctx, operatorAddr)
wc := k.GetWithdrawContext(ctx, operatorAddr)
valInfo, feePool, commission := valInfo.WithdrawCommission(wc)
feePool, commission := k.withdrawValidatorCommission(ctx, operatorAddr)
withdraw = withdraw.Plus(commission)
k.SetValidatorDistInfo(ctx, valInfo)
k.WithdrawToDelegator(ctx, feePool, accAddr, withdraw)
return nil