74 lines
2.5 KiB
Go
74 lines
2.5 KiB
Go
// nolint
|
|
package slashing
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/tendermint/tendermint/crypto"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
)
|
|
|
|
func (k Keeper) AfterValidatorBonded(ctx sdk.Context, address sdk.ConsAddress, _ sdk.ValAddress) {
|
|
// Update the signing info start height or create a new signing info
|
|
_, found := k.getValidatorSigningInfo(ctx, address)
|
|
if !found {
|
|
signingInfo := ValidatorSigningInfo{
|
|
StartHeight: ctx.BlockHeight(),
|
|
IndexOffset: 0,
|
|
JailedUntil: time.Unix(0, 0),
|
|
Tombstoned: false,
|
|
MissedBlocksCounter: 0,
|
|
}
|
|
k.SetValidatorSigningInfo(ctx, address, signingInfo)
|
|
}
|
|
}
|
|
|
|
// When a validator is created, add the address-pubkey relation.
|
|
func (k Keeper) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) {
|
|
validator := k.validatorSet.Validator(ctx, valAddr)
|
|
k.addPubkey(ctx, validator.GetConsPubKey())
|
|
}
|
|
|
|
// When a validator is removed, delete the address-pubkey relation.
|
|
func (k Keeper) AfterValidatorRemoved(ctx sdk.Context, address sdk.ConsAddress) {
|
|
k.deleteAddrPubkeyRelation(ctx, crypto.Address(address))
|
|
}
|
|
|
|
//_________________________________________________________________________________________
|
|
|
|
// Wrapper struct
|
|
type Hooks struct {
|
|
k Keeper
|
|
}
|
|
|
|
var _ sdk.StakingHooks = Hooks{}
|
|
|
|
// Return the wrapper struct
|
|
func (k Keeper) Hooks() Hooks {
|
|
return Hooks{k}
|
|
}
|
|
|
|
// Implements sdk.ValidatorHooks
|
|
func (h Hooks) AfterValidatorBonded(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) {
|
|
h.k.AfterValidatorBonded(ctx, consAddr, valAddr)
|
|
}
|
|
|
|
// Implements sdk.ValidatorHooks
|
|
func (h Hooks) AfterValidatorRemoved(ctx sdk.Context, consAddr sdk.ConsAddress, _ sdk.ValAddress) {
|
|
h.k.AfterValidatorRemoved(ctx, consAddr)
|
|
}
|
|
|
|
// Implements sdk.ValidatorHooks
|
|
func (h Hooks) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) {
|
|
h.k.AfterValidatorCreated(ctx, valAddr)
|
|
}
|
|
|
|
// nolint - unused hooks
|
|
func (h Hooks) AfterValidatorBeginUnbonding(_ sdk.Context, _ sdk.ConsAddress, _ sdk.ValAddress) {}
|
|
func (h Hooks) AfterValidatorPowerDidChange(_ sdk.Context, _ sdk.ConsAddress, _ sdk.ValAddress) {}
|
|
func (h Hooks) BeforeValidatorModified(_ sdk.Context, _ sdk.ValAddress) {}
|
|
func (h Hooks) BeforeDelegationCreated(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) {}
|
|
func (h Hooks) BeforeDelegationSharesModified(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) {}
|
|
func (h Hooks) BeforeDelegationRemoved(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) {}
|