Merge PR #3163: Withdraw commission on self bond removal
* Withdraw commission on self bond removal * Update PENDING.md
This commit is contained in:
parent
46620d4abc
commit
2be19b9d33
|
@ -10,6 +10,8 @@ BREAKING CHANGES
|
||||||
|
|
||||||
* SDK
|
* SDK
|
||||||
|
|
||||||
|
* \#3163 Withdraw commission on self bond removal
|
||||||
|
|
||||||
* Tendermint
|
* Tendermint
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -87,6 +87,10 @@ func (k Keeper) onDelegationSharesModified(ctx sdk.Context, delAddr sdk.AccAddre
|
||||||
// Withdrawal all validator distribution rewards and cleanup the distribution record
|
// Withdrawal all validator distribution rewards and cleanup the distribution record
|
||||||
func (k Keeper) onDelegationRemoved(ctx sdk.Context, delAddr sdk.AccAddress,
|
func (k Keeper) onDelegationRemoved(ctx sdk.Context, delAddr sdk.AccAddress,
|
||||||
valAddr sdk.ValAddress) {
|
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)
|
k.RemoveDelegationDistInfo(ctx, delAddr, valAddr)
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,9 @@ func (k Keeper) RemoveValidatorDistInfo(ctx sdk.Context, valAddr sdk.ValAddress)
|
||||||
if vdi.DelAccum.Accum.IsPositive() {
|
if vdi.DelAccum.Accum.IsPositive() {
|
||||||
panic("Should not delete validator with unwithdrawn delegator accum")
|
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 := ctx.KVStore(k.storeKey)
|
||||||
store.Delete(GetValidatorDistInfoKey(valAddr))
|
store.Delete(GetValidatorDistInfoKey(valAddr))
|
||||||
|
@ -119,6 +122,15 @@ func (k Keeper) takeValidatorFeePoolRewards(ctx sdk.Context, operatorAddr sdk.Va
|
||||||
return nil
|
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
|
// withdrawal all the validator rewards including the commission
|
||||||
func (k Keeper) WithdrawValidatorRewardsAll(ctx sdk.Context, operatorAddr sdk.ValAddress) sdk.Error {
|
func (k Keeper) WithdrawValidatorRewardsAll(ctx sdk.Context, operatorAddr sdk.ValAddress) sdk.Error {
|
||||||
if !k.HasValidatorDistInfo(ctx, operatorAddr) {
|
if !k.HasValidatorDistInfo(ctx, operatorAddr) {
|
||||||
|
@ -130,11 +142,8 @@ func (k Keeper) WithdrawValidatorRewardsAll(ctx sdk.Context, operatorAddr sdk.Va
|
||||||
withdraw := k.withdrawDelegationRewardsAll(ctx, accAddr)
|
withdraw := k.withdrawDelegationRewardsAll(ctx, accAddr)
|
||||||
|
|
||||||
// withdrawal validator commission rewards
|
// withdrawal validator commission rewards
|
||||||
valInfo := k.GetValidatorDistInfo(ctx, operatorAddr)
|
feePool, commission := k.withdrawValidatorCommission(ctx, operatorAddr)
|
||||||
wc := k.GetWithdrawContext(ctx, operatorAddr)
|
|
||||||
valInfo, feePool, commission := valInfo.WithdrawCommission(wc)
|
|
||||||
withdraw = withdraw.Plus(commission)
|
withdraw = withdraw.Plus(commission)
|
||||||
k.SetValidatorDistInfo(ctx, valInfo)
|
|
||||||
|
|
||||||
k.WithdrawToDelegator(ctx, feePool, accAddr, withdraw)
|
k.WithdrawToDelegator(ctx, feePool, accAddr, withdraw)
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue