2019-07-19 06:43:38 -07:00
|
|
|
package keeper
|
2018-08-31 17:01:23 -07:00
|
|
|
|
|
|
|
import (
|
2018-10-11 13:48:00 -07:00
|
|
|
"time"
|
|
|
|
|
2018-11-08 16:28:28 -08:00
|
|
|
"github.com/tendermint/tendermint/crypto"
|
|
|
|
|
2018-08-31 17:01:23 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-02-19 16:04:13 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/slashing/types"
|
2018-08-31 17:01:23 -07:00
|
|
|
)
|
|
|
|
|
2021-06-30 03:13:07 -07:00
|
|
|
func (k Keeper) AfterValidatorBonded(ctx sdk.Context, address sdk.ConsAddress, _ sdk.ValAddress) error {
|
2018-10-11 15:15:58 -07:00
|
|
|
// Update the signing info start height or create a new signing info
|
2019-07-19 06:43:38 -07:00
|
|
|
_, found := k.GetValidatorSigningInfo(ctx, address)
|
2018-10-15 12:44:23 -07:00
|
|
|
if !found {
|
2019-06-05 16:26:17 -07:00
|
|
|
signingInfo := types.NewValidatorSigningInfo(
|
2019-05-09 10:38:15 -07:00
|
|
|
address,
|
|
|
|
ctx.BlockHeight(),
|
|
|
|
0,
|
|
|
|
time.Unix(0, 0),
|
|
|
|
false,
|
|
|
|
0,
|
|
|
|
)
|
2018-11-26 04:21:23 -08:00
|
|
|
k.SetValidatorSigningInfo(ctx, address, signingInfo)
|
2018-10-11 13:48:00 -07:00
|
|
|
}
|
2021-06-30 03:13:07 -07:00
|
|
|
|
|
|
|
return nil
|
2018-08-31 17:01:23 -07:00
|
|
|
}
|
|
|
|
|
2020-10-23 05:07:52 -07:00
|
|
|
// AfterValidatorCreated adds the address-pubkey relation when a validator is created.
|
|
|
|
func (k Keeper) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) error {
|
2019-06-04 15:06:58 -07:00
|
|
|
validator := k.sk.Validator(ctx, valAddr)
|
2020-11-09 08:01:43 -08:00
|
|
|
consPk, err := validator.ConsPubKey()
|
2020-10-23 05:07:52 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-11-09 08:01:43 -08:00
|
|
|
|
2021-06-30 03:13:07 -07:00
|
|
|
return k.AddPubkey(ctx, consPk)
|
2018-11-08 16:28:28 -08:00
|
|
|
}
|
|
|
|
|
2020-10-23 05:07:52 -07:00
|
|
|
// AfterValidatorRemoved deletes the address-pubkey relation when a validator is removed,
|
2021-06-30 03:13:07 -07:00
|
|
|
func (k Keeper) AfterValidatorRemoved(ctx sdk.Context, address sdk.ConsAddress) error {
|
2018-11-08 16:28:28 -08:00
|
|
|
k.deleteAddrPubkeyRelation(ctx, crypto.Address(address))
|
2021-06-30 03:13:07 -07:00
|
|
|
return nil
|
2018-11-08 16:28:28 -08:00
|
|
|
}
|
|
|
|
|
2019-06-04 15:06:58 -07:00
|
|
|
// Hooks wrapper struct for slashing keeper
|
2018-09-24 21:09:31 -07:00
|
|
|
type Hooks struct {
|
2018-08-31 17:01:23 -07:00
|
|
|
k Keeper
|
|
|
|
}
|
|
|
|
|
2019-06-05 16:26:17 -07:00
|
|
|
var _ types.StakingHooks = Hooks{}
|
2018-08-31 17:01:23 -07:00
|
|
|
|
2018-09-24 21:09:31 -07:00
|
|
|
// Return the wrapper struct
|
2018-09-25 23:11:57 -07:00
|
|
|
func (k Keeper) Hooks() Hooks {
|
2018-09-24 21:09:31 -07:00
|
|
|
return Hooks{k}
|
2018-08-31 17:01:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Implements sdk.ValidatorHooks
|
2021-06-30 03:13:07 -07:00
|
|
|
func (h Hooks) AfterValidatorBonded(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) error {
|
|
|
|
return h.k.AfterValidatorBonded(ctx, consAddr, valAddr)
|
2018-08-31 17:01:23 -07:00
|
|
|
}
|
|
|
|
|
2018-11-08 16:28:28 -08:00
|
|
|
// Implements sdk.ValidatorHooks
|
2021-06-30 03:13:07 -07:00
|
|
|
func (h Hooks) AfterValidatorRemoved(ctx sdk.Context, consAddr sdk.ConsAddress, _ sdk.ValAddress) error {
|
|
|
|
return h.k.AfterValidatorRemoved(ctx, consAddr)
|
2018-11-08 16:28:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Implements sdk.ValidatorHooks
|
2021-06-30 03:13:07 -07:00
|
|
|
func (h Hooks) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) error {
|
|
|
|
return h.k.AfterValidatorCreated(ctx, valAddr)
|
2018-11-08 16:28:28 -08:00
|
|
|
}
|
|
|
|
|
2021-06-30 03:13:07 -07:00
|
|
|
func (h Hooks) AfterValidatorBeginUnbonding(_ sdk.Context, _ sdk.ConsAddress, _ sdk.ValAddress) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
func (h Hooks) BeforeValidatorModified(_ sdk.Context, _ sdk.ValAddress) error { return nil }
|
|
|
|
func (h Hooks) BeforeDelegationCreated(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
func (h Hooks) BeforeDelegationSharesModified(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
func (h Hooks) BeforeDelegationRemoved(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
func (h Hooks) AfterDelegationModified(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
func (h Hooks) BeforeValidatorSlashed(_ sdk.Context, _ sdk.ValAddress, _ sdk.Dec) error { return nil }
|