Withdraw rewards on bonded to unbonding
This commit is contained in:
parent
a6ef3c42aa
commit
7770aec306
|
@ -343,8 +343,8 @@ func (h Hooks) OnValidatorRemoved(ctx sdk.Context, addr sdk.ValAddress) {
|
||||||
func (h Hooks) OnValidatorBonded(ctx sdk.Context, addr sdk.ConsAddress) {
|
func (h Hooks) OnValidatorBonded(ctx sdk.Context, addr sdk.ConsAddress) {
|
||||||
h.sh.OnValidatorBonded(ctx, addr)
|
h.sh.OnValidatorBonded(ctx, addr)
|
||||||
}
|
}
|
||||||
func (h Hooks) OnValidatorBeginUnbonding(ctx sdk.Context, addr sdk.ConsAddress) {
|
func (h Hooks) OnValidatorBeginUnbonding(ctx sdk.Context, addr sdk.ConsAddress, operator sdk.ValAddress) {
|
||||||
h.sh.OnValidatorBeginUnbonding(ctx, addr)
|
h.sh.OnValidatorBeginUnbonding(ctx, addr, operator)
|
||||||
}
|
}
|
||||||
func (h Hooks) OnDelegationCreated(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) {
|
func (h Hooks) OnDelegationCreated(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) {
|
||||||
h.dh.OnDelegationCreated(ctx, delAddr, valAddr)
|
h.dh.OnDelegationCreated(ctx, delAddr, valAddr)
|
||||||
|
|
|
@ -10,7 +10,7 @@ type StakingHooks interface {
|
||||||
OnValidatorRemoved(ctx Context, address ValAddress) // called when a validator is deleted
|
OnValidatorRemoved(ctx Context, address ValAddress) // called when a validator is deleted
|
||||||
|
|
||||||
OnValidatorBonded(ctx Context, address ConsAddress) // called when a validator is bonded
|
OnValidatorBonded(ctx Context, address ConsAddress) // called when a validator is bonded
|
||||||
OnValidatorBeginUnbonding(ctx Context, address ConsAddress) // called when a validator begins unbonding
|
OnValidatorBeginUnbonding(ctx Context, address ConsAddress, operator ValAddress) // called when a validator begins unbonding
|
||||||
|
|
||||||
OnDelegationCreated(ctx Context, delAddr AccAddress, valAddr ValAddress) // called when a delegation is created
|
OnDelegationCreated(ctx Context, delAddr AccAddress, valAddr ValAddress) // called when a delegation is created
|
||||||
OnDelegationSharesModified(ctx Context, delAddr AccAddress, valAddr ValAddress) // called when a delegation's shares are modified
|
OnDelegationSharesModified(ctx Context, delAddr AccAddress, valAddr ValAddress) // called when a delegation's shares are modified
|
||||||
|
|
|
@ -115,8 +115,8 @@ type StakingHooks interface {
|
||||||
OnValidatorCommissionChange(ctx Context, address ValAddress) // Must be called when a validator's commission is modified
|
OnValidatorCommissionChange(ctx Context, address ValAddress) // Must be called when a validator's commission is modified
|
||||||
OnValidatorRemoved(ctx Context, address ValAddress) // Must be called when a validator is deleted
|
OnValidatorRemoved(ctx Context, address ValAddress) // Must be called when a validator is deleted
|
||||||
|
|
||||||
OnValidatorBonded(ctx Context, address ConsAddress) // Must be called when a validator is bonded
|
OnValidatorBonded(ctx Context, address ConsAddress) // Must be called when a validator is bonded
|
||||||
OnValidatorBeginUnbonding(ctx Context, address ConsAddress) // Must be called when a validator begins unbonding
|
OnValidatorBeginUnbonding(ctx Context, address ConsAddress, operator ValAddress) // Must be called when a validator begins unbonding
|
||||||
|
|
||||||
OnDelegationCreated(ctx Context, delAddr AccAddress, valAddr ValAddress) // Must be called when a delegation is created
|
OnDelegationCreated(ctx Context, delAddr AccAddress, valAddr ValAddress) // Must be called when a delegation is created
|
||||||
OnDelegationSharesModified(ctx Context, delAddr AccAddress, valAddr ValAddress) // Must be called when a delegation's shares are modified
|
OnDelegationSharesModified(ctx Context, delAddr AccAddress, valAddr ValAddress) // Must be called when a delegation's shares are modified
|
||||||
|
|
|
@ -33,6 +33,13 @@ func (k Keeper) onValidatorRemoved(ctx sdk.Context, addr sdk.ValAddress) {
|
||||||
k.RemoveValidatorDistInfo(ctx, addr)
|
k.RemoveValidatorDistInfo(ctx, addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Withdraw all validator rewards
|
||||||
|
func (k Keeper) onValidatorBeginUnbonding(ctx sdk.Context, addr sdk.ValAddress) {
|
||||||
|
if err := k.WithdrawValidatorRewardsAll(ctx, addr); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//_________________________________________________________________________________________
|
//_________________________________________________________________________________________
|
||||||
|
|
||||||
// Create a new delegator distribution record
|
// Create a new delegator distribution record
|
||||||
|
@ -96,6 +103,9 @@ func (h Hooks) OnDelegationRemoved(ctx sdk.Context, delAddr sdk.AccAddress, valA
|
||||||
h.k.onDelegationRemoved(ctx, delAddr, valAddr)
|
h.k.onDelegationRemoved(ctx, delAddr, valAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h Hooks) OnValidatorBeginUnbonding(ctx sdk.Context, _ sdk.ConsAddress, addr sdk.ValAddress) {
|
||||||
|
h.k.onValidatorBeginUnbonding(ctx, addr)
|
||||||
|
}
|
||||||
|
|
||||||
// nolint - unused hooks for interface
|
// nolint - unused hooks for interface
|
||||||
func (h Hooks) OnValidatorBonded(ctx sdk.Context, addr sdk.ConsAddress) {}
|
func (h Hooks) OnValidatorBonded(ctx sdk.Context, addr sdk.ConsAddress) {}
|
||||||
func (h Hooks) OnValidatorBeginUnbonding(ctx sdk.Context, addr sdk.ConsAddress) {}
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ func (k Keeper) onValidatorBonded(ctx sdk.Context, address sdk.ConsAddress) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark the slashing period as having ended when a validator begins unbonding
|
// Mark the slashing period as having ended when a validator begins unbonding
|
||||||
func (k Keeper) onValidatorBeginUnbonding(ctx sdk.Context, address sdk.ConsAddress) {
|
func (k Keeper) onValidatorBeginUnbonding(ctx sdk.Context, address sdk.ConsAddress, _ sdk.ValAddress) {
|
||||||
slashingPeriod := k.getValidatorSlashingPeriodForHeight(ctx, address, ctx.BlockHeight())
|
slashingPeriod := k.getValidatorSlashingPeriodForHeight(ctx, address, ctx.BlockHeight())
|
||||||
slashingPeriod.EndHeight = ctx.BlockHeight()
|
slashingPeriod.EndHeight = ctx.BlockHeight()
|
||||||
k.addOrUpdateValidatorSlashingPeriod(ctx, slashingPeriod)
|
k.addOrUpdateValidatorSlashingPeriod(ctx, slashingPeriod)
|
||||||
|
@ -56,8 +56,8 @@ func (h Hooks) OnValidatorBonded(ctx sdk.Context, address sdk.ConsAddress) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements sdk.ValidatorHooks
|
// Implements sdk.ValidatorHooks
|
||||||
func (h Hooks) OnValidatorBeginUnbonding(ctx sdk.Context, address sdk.ConsAddress) {
|
func (h Hooks) OnValidatorBeginUnbonding(ctx sdk.Context, address sdk.ConsAddress, operator sdk.ValAddress) {
|
||||||
h.k.onValidatorBeginUnbonding(ctx, address)
|
h.k.onValidatorBeginUnbonding(ctx, address, operator)
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint - unused hooks
|
// nolint - unused hooks
|
||||||
|
|
|
@ -20,7 +20,7 @@ func TestHookOnValidatorBeginUnbonding(t *testing.T) {
|
||||||
ctx, _, _, _, keeper := createTestInput(t, DefaultParams())
|
ctx, _, _, _, keeper := createTestInput(t, DefaultParams())
|
||||||
addr := sdk.ConsAddress(addrs[0])
|
addr := sdk.ConsAddress(addrs[0])
|
||||||
keeper.onValidatorBonded(ctx, addr)
|
keeper.onValidatorBonded(ctx, addr)
|
||||||
keeper.onValidatorBeginUnbonding(ctx, addr)
|
keeper.onValidatorBeginUnbonding(ctx, addr, sdk.ValAddress(addrs[0]))
|
||||||
period := keeper.getValidatorSlashingPeriodForHeight(ctx, addr, ctx.BlockHeight())
|
period := keeper.getValidatorSlashingPeriodForHeight(ctx, addr, ctx.BlockHeight())
|
||||||
require.Equal(t, ValidatorSlashingPeriod{addr, ctx.BlockHeight(), ctx.BlockHeight(), sdk.ZeroDec()}, period)
|
require.Equal(t, ValidatorSlashingPeriod{addr, ctx.BlockHeight(), ctx.BlockHeight(), sdk.ZeroDec()}, period)
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,9 +29,9 @@ func (k Keeper) OnValidatorBonded(ctx sdk.Context, address sdk.ConsAddress) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k Keeper) OnValidatorBeginUnbonding(ctx sdk.Context, address sdk.ConsAddress) {
|
func (k Keeper) OnValidatorBeginUnbonding(ctx sdk.Context, address sdk.ConsAddress, operator sdk.ValAddress) {
|
||||||
if k.hooks != nil {
|
if k.hooks != nil {
|
||||||
k.hooks.OnValidatorBeginUnbonding(ctx, address)
|
k.hooks.OnValidatorBeginUnbonding(ctx, address, operator)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -219,7 +219,7 @@ func (k Keeper) beginUnbondingValidator(ctx sdk.Context, validator types.Validat
|
||||||
|
|
||||||
// call the unbond hook if present
|
// call the unbond hook if present
|
||||||
if k.hooks != nil {
|
if k.hooks != nil {
|
||||||
k.hooks.OnValidatorBeginUnbonding(ctx, validator.ConsAddress())
|
k.hooks.OnValidatorBeginUnbonding(ctx, validator.ConsAddress(), validator.OperatorAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
return validator
|
return validator
|
||||||
|
|
Loading…
Reference in New Issue