diff --git a/cmd/gaia/app/app.go b/cmd/gaia/app/app.go index 6c02b7aaa..5265db52b 100644 --- a/cmd/gaia/app/app.go +++ b/cmd/gaia/app/app.go @@ -3,6 +3,10 @@ package app import ( "encoding/json" "fmt" + "io" + "os" + "sort" + bam "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -19,9 +23,6 @@ import ( dbm "github.com/tendermint/tendermint/libs/db" "github.com/tendermint/tendermint/libs/log" tmtypes "github.com/tendermint/tendermint/types" - "io" - "os" - "sort" ) const ( @@ -334,8 +335,8 @@ var _ sdk.StakingHooks = Hooks{} func (h Hooks) OnValidatorCreated(ctx sdk.Context, addr sdk.ValAddress) { h.dh.OnValidatorCreated(ctx, addr) } -func (h Hooks) OnValidatorCommissionChange(ctx sdk.Context, addr sdk.ValAddress) { - h.dh.OnValidatorCommissionChange(ctx, addr) +func (h Hooks) OnValidatorModified(ctx sdk.Context, addr sdk.ValAddress) { + h.dh.OnValidatorModified(ctx, addr) } func (h Hooks) OnValidatorRemoved(ctx sdk.Context, addr sdk.ValAddress) { h.dh.OnValidatorRemoved(ctx, addr) diff --git a/docs/spec/staking/hooks.md b/docs/spec/staking/hooks.md index 60359b431..7d24e32e6 100644 --- a/docs/spec/staking/hooks.md +++ b/docs/spec/staking/hooks.md @@ -5,9 +5,9 @@ The staking module allow for the following hooks to be registered with staking e ``` golang // event hooks for staking validator object type StakingHooks interface { - OnValidatorCreated(ctx Context, address ValAddress) // called when a validator is created - OnValidatorCommissionChange(ctx Context, address ValAddress) // called when a validator's commission is modified - OnValidatorRemoved(ctx Context, address ValAddress) // called when a validator is deleted + OnValidatorCreated(ctx Context, address ValAddress) // Must be called when a validator is created + OnValidatorModified(ctx Context, address ValAddress) // Must be called when a validator's state changes + OnValidatorRemoved(ctx Context, address ValAddress) // Must be called when a validator is deleted OnValidatorBonded(ctx Context, address ConsAddress) // called when a validator is bonded OnValidatorBeginUnbonding(ctx Context, address ConsAddress, operator ValAddress) // called when a validator begins unbonding diff --git a/types/stake.go b/types/stake.go index b6e48bde7..25b897994 100644 --- a/types/stake.go +++ b/types/stake.go @@ -111,9 +111,9 @@ type DelegationSet interface { // event hooks for staking validator object type StakingHooks interface { - OnValidatorCreated(ctx Context, address ValAddress) // Must be called when a validator is created - 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 + OnValidatorCreated(ctx Context, address ValAddress) // Must be called when a validator is created + OnValidatorModified(ctx Context, address ValAddress) // Must be called when a validator's state changes + 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 OnValidatorBeginUnbonding(ctx Context, address ConsAddress, operator ValAddress) // Must be called when a validator begins unbonding diff --git a/x/distribution/keeper/hooks.go b/x/distribution/keeper/hooks.go index 698e72965..aeb394f26 100644 --- a/x/distribution/keeper/hooks.go +++ b/x/distribution/keeper/hooks.go @@ -14,9 +14,9 @@ func (k Keeper) onValidatorCreated(ctx sdk.Context, addr sdk.ValAddress) { vdi := types.ValidatorDistInfo{ OperatorAddr: addr, FeePoolWithdrawalHeight: height, - Pool: types.DecCoins{}, - PoolCommission: types.DecCoins{}, - DelAccum: types.NewTotalAccum(height), + Pool: types.DecCoins{}, + PoolCommission: types.DecCoins{}, + DelAccum: types.NewTotalAccum(height), } k.SetValidatorDistInfo(ctx, vdi) } @@ -80,7 +80,7 @@ func (k Keeper) Hooks() Hooks { return Hooks{k} } func (h Hooks) OnValidatorCreated(ctx sdk.Context, addr sdk.ValAddress) { h.k.onValidatorCreated(ctx, addr) } -func (h Hooks) OnValidatorCommissionChange(ctx sdk.Context, addr sdk.ValAddress) { +func (h Hooks) OnValidatorModified(ctx sdk.Context, addr sdk.ValAddress) { h.k.onValidatorModified(ctx, addr) } func (h Hooks) OnValidatorRemoved(ctx sdk.Context, addr sdk.ValAddress) { diff --git a/x/slashing/hooks.go b/x/slashing/hooks.go index d91c69579..3ad08b864 100644 --- a/x/slashing/hooks.go +++ b/x/slashing/hooks.go @@ -62,7 +62,7 @@ func (h Hooks) OnValidatorBeginUnbonding(ctx sdk.Context, address sdk.ConsAddres // nolint - unused hooks func (h Hooks) OnValidatorCreated(_ sdk.Context, _ sdk.ValAddress) {} -func (h Hooks) OnValidatorCommissionChange(_ sdk.Context, _ sdk.ValAddress) {} +func (h Hooks) OnValidatorModified(_ sdk.Context, _ sdk.ValAddress) {} func (h Hooks) OnValidatorRemoved(_ sdk.Context, _ sdk.ValAddress) {} func (h Hooks) OnDelegationCreated(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) {} func (h Hooks) OnDelegationSharesModified(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) {} diff --git a/x/stake/handler.go b/x/stake/handler.go index e251d2c32..24cbee717 100644 --- a/x/stake/handler.go +++ b/x/stake/handler.go @@ -148,7 +148,7 @@ func handleMsgEditValidator(ctx sdk.Context, msg types.MsgEditValidator, k keepe return err.Result() } validator.Commission = commission - k.OnValidatorCommissionChange(ctx, msg.ValidatorAddr) + k.OnValidatorModified(ctx, msg.ValidatorAddr) } k.SetValidator(ctx, validator) diff --git a/x/stake/keeper/hooks.go b/x/stake/keeper/hooks.go index 060c84f51..14eedb693 100644 --- a/x/stake/keeper/hooks.go +++ b/x/stake/keeper/hooks.go @@ -11,9 +11,9 @@ func (k Keeper) OnValidatorCreated(ctx sdk.Context, address sdk.ValAddress) { k.hooks.OnValidatorCreated(ctx, address) } } -func (k Keeper) OnValidatorCommissionChange(ctx sdk.Context, address sdk.ValAddress) { +func (k Keeper) OnValidatorModified(ctx sdk.Context, address sdk.ValAddress) { if k.hooks != nil { - k.hooks.OnValidatorCommissionChange(ctx, address) + k.hooks.OnValidatorModified(ctx, address) } } diff --git a/x/stake/keeper/slash.go b/x/stake/keeper/slash.go index af59726ae..eafb3cca3 100644 --- a/x/stake/keeper/slash.go +++ b/x/stake/keeper/slash.go @@ -51,6 +51,7 @@ func (k Keeper) Slash(ctx sdk.Context, consAddr sdk.ConsAddress, infractionHeigh } operatorAddress := validator.GetOperator() + k.OnValidatorModified(ctx, operatorAddress) // Track remaining slash amount for the validator // This will decrease when we slash unbondings and