Documentation ¶
Overview ¶
nolint
nolint
Index ¶
- Constants
- Variables
- func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, sk Keeper) sdk.Tags
- func ErrBadValidatorAddr(codespace sdk.CodespaceType) sdk.Error
- func ErrMissingSelfDelegation(codespace sdk.CodespaceType) sdk.Error
- func ErrNoValidatorForAddress(codespace sdk.CodespaceType) sdk.Error
- func ErrSelfDelegationTooLowToUnjail(codespace sdk.CodespaceType) sdk.Error
- func ErrValidatorJailed(codespace sdk.CodespaceType) sdk.Error
- func ErrValidatorNotJailed(codespace sdk.CodespaceType) sdk.Error
- func GetValidatorMissedBlockBitArrayKey(v sdk.ConsAddress, i int64) []byte
- func GetValidatorMissedBlockBitArrayPrefixKey(v sdk.ConsAddress) []byte
- func GetValidatorSigningInfoAddress(key []byte) (v sdk.ConsAddress)
- func GetValidatorSigningInfoKey(v sdk.ConsAddress) []byte
- func GetValidatorSlashingPeriodKey(v sdk.ConsAddress, startHeight int64) []byte
- func GetValidatorSlashingPeriodPrefix(v sdk.ConsAddress) []byte
- func InitGenesis(ctx sdk.Context, keeper Keeper, data GenesisState, validators []sdk.Validator)
- func NewHandler(k Keeper) sdk.Handler
- func NewQuerier(k Keeper, cdc *codec.Codec) sdk.Querier
- func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt sdk.Int) staking.MsgCreateValidator
- func ParamKeyTable() params.KeyTable
- func RegisterCodec(cdc *codec.Codec)
- func ValidateGenesis(data GenesisState) error
- type CodeType
- type GenesisState
- type Hooks
- func (h Hooks) AfterDelegationModified(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress)
- func (h Hooks) AfterValidatorBeginUnbonding(_ sdk.Context, _ sdk.ConsAddress, _ sdk.ValAddress)
- func (h Hooks) AfterValidatorBonded(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress)
- func (h Hooks) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress)
- func (h Hooks) AfterValidatorRemoved(ctx sdk.Context, consAddr sdk.ConsAddress, _ sdk.ValAddress)
- func (h Hooks) BeforeDelegationCreated(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress)
- func (h Hooks) BeforeDelegationRemoved(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress)
- func (h Hooks) BeforeDelegationSharesModified(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress)
- func (h Hooks) BeforeValidatorModified(_ sdk.Context, _ sdk.ValAddress)
- func (h Hooks) BeforeValidatorSlashed(_ sdk.Context, _ sdk.ValAddress, _ sdk.Dec)
- type Keeper
- func (k Keeper) AfterValidatorBonded(ctx sdk.Context, address sdk.ConsAddress, _ sdk.ValAddress)
- func (k Keeper) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress)
- func (k Keeper) AfterValidatorRemoved(ctx sdk.Context, address sdk.ConsAddress)
- func (k Keeper) DowntimeJailDuration(ctx sdk.Context) (res time.Duration)
- func (k Keeper) GetParams(ctx sdk.Context) (params Params)
- func (k Keeper) Hooks() Hooks
- func (k Keeper) IterateValidatorMissedBlockBitArray(ctx sdk.Context, address sdk.ConsAddress, ...)
- func (k Keeper) IterateValidatorSigningInfos(ctx sdk.Context, ...)
- func (k Keeper) MaxEvidenceAge(ctx sdk.Context) (res time.Duration)
- func (k Keeper) MinSignedPerWindow(ctx sdk.Context) int64
- func (k Keeper) SetValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress, info ValidatorSigningInfo)
- func (k Keeper) SignedBlocksWindow(ctx sdk.Context) (res int64)
- func (k Keeper) SlashFractionDoubleSign(ctx sdk.Context) (res sdk.Dec)
- func (k Keeper) SlashFractionDowntime(ctx sdk.Context) (res sdk.Dec)
- type MissedBlock
- type MsgUnjail
- type Params
- type ValidatorSigningInfo
Constants ¶
const ( // ModuleName is the name of the module ModuleName = "slashing" // StoreKey is the store key string for slashing StoreKey = ModuleName // RouterKey is the message route for slashing RouterKey = ModuleName // QuerierRoute is the querier route for slashing QuerierRoute = ModuleName )
const ( DefaultParamspace = ModuleName DefaultMaxEvidenceAge time.Duration = 60 * 2 * time.Second DefaultSignedBlocksWindow int64 = 100 DefaultDowntimeJailDuration time.Duration = 60 * 10 * time.Second )
Default parameter namespace
const (
QueryParameters = "parameters"
)
Query endpoints supported by the slashing querier
Variables ¶
var ( // 感觉 节点公钥生成的node地址作为key,存储该地址的签名信息的key前缀 ValidatorSigningInfoKey = []byte{0x01} // Prefix for signing info ValidatorMissedBlockBitArrayKey = []byte{0x02} // Prefix for missed block bit array ValidatorSlashingPeriodKey = []byte{0x03} // Prefix for slashing period // 设置目前 验证人列表中的相关 pubkey addr 的key前缀 AddrPubkeyRelationKey = []byte{0x04} // Prefix for address-pubkey relation )
key prefix bytes
var ( DoubleSignJailEndTime = time.Unix(253402300799, 0) DefaultMinSignedPerWindow = sdk.NewDecWithPrec(5, 1) DefaultSlashFractionDoubleSign = sdk.NewDec(1).Quo(sdk.NewDec(20)) DefaultSlashFractionDowntime = sdk.NewDec(1).Quo(sdk.NewDec(100)) )
The Double Sign Jail period ends at Max Time supported by Amino (Dec 31, 9999 - 23:59:59 GMT)
var ( KeyMaxEvidenceAge = []byte("MaxEvidenceAge") KeySignedBlocksWindow = []byte("SignedBlocksWindow") KeyMinSignedPerWindow = []byte("MinSignedPerWindow") KeyDowntimeJailDuration = []byte("DowntimeJailDuration") KeySlashFractionDoubleSign = []byte("SlashFractionDoubleSign") KeySlashFractionDowntime = []byte("SlashFractionDowntime") )
Parameter store keys
Functions ¶
func BeginBlocker ¶
slashing begin block functionality 惩罚机制 开始 block 功能
func ErrBadValidatorAddr ¶
func ErrBadValidatorAddr(codespace sdk.CodespaceType) sdk.Error
func ErrMissingSelfDelegation ¶
func ErrMissingSelfDelegation(codespace sdk.CodespaceType) sdk.Error
func ErrNoValidatorForAddress ¶
func ErrNoValidatorForAddress(codespace sdk.CodespaceType) sdk.Error
func ErrSelfDelegationTooLowToUnjail ¶
func ErrSelfDelegationTooLowToUnjail(codespace sdk.CodespaceType) sdk.Error
func ErrValidatorJailed ¶
func ErrValidatorJailed(codespace sdk.CodespaceType) sdk.Error
func ErrValidatorNotJailed ¶
func ErrValidatorNotJailed(codespace sdk.CodespaceType) sdk.Error
func GetValidatorMissedBlockBitArrayKey ¶
func GetValidatorMissedBlockBitArrayKey(v sdk.ConsAddress, i int64) []byte
stored by *Tendermint* address (not operator address)
func GetValidatorMissedBlockBitArrayPrefixKey ¶
func GetValidatorMissedBlockBitArrayPrefixKey(v sdk.ConsAddress) []byte
stored by *Tendermint* address (not operator address)
func GetValidatorSigningInfoAddress ¶
func GetValidatorSigningInfoAddress(key []byte) (v sdk.ConsAddress)
extract the address from a validator signing info key
func GetValidatorSigningInfoKey ¶
func GetValidatorSigningInfoKey(v sdk.ConsAddress) []byte
stored by *Tendermint* address (not operator address) 存储* Tendermint *地址(非 质押地址)这里是指 由公钥生成的 node的addr
func GetValidatorSlashingPeriodKey ¶
func GetValidatorSlashingPeriodKey(v sdk.ConsAddress, startHeight int64) []byte
stored by *Tendermint* address (not operator address) followed by start height
func GetValidatorSlashingPeriodPrefix ¶
func GetValidatorSlashingPeriodPrefix(v sdk.ConsAddress) []byte
stored by *Tendermint* address (not operator address)
func InitGenesis ¶
InitGenesis initialize default parameters and the keeper's address to pubkey map
func NewQuerier ¶
NewQuerier creates a new querier for slashing clients.
func NewTestMsgCreateValidator ¶
func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt sdk.Int) staking.MsgCreateValidator
func ValidateGenesis ¶
func ValidateGenesis(data GenesisState) error
ValidateGenesis validates the slashing genesis parameters
Types ¶
type CodeType ¶
Local code type
const ( // Default slashing codespace DefaultCodespace sdk.CodespaceType = ModuleName CodeInvalidValidator CodeType = 101 CodeValidatorJailed CodeType = 102 CodeValidatorNotJailed CodeType = 103 CodeMissingSelfDelegation CodeType = 104 CodeSelfDelegationTooLow CodeType = 105 )
type GenesisState ¶
type GenesisState struct { Params Params `json:"params"` SigningInfos map[string]ValidatorSigningInfo `json:"signing_infos"` MissedBlocks map[string][]MissedBlock `json:"missed_blocks"` }
GenesisState - all slashing state that must be provided at genesis
func DefaultGenesisState ¶
func DefaultGenesisState() GenesisState
DefaultGenesisState - default GenesisState used by Cosmos Hub
func ExportGenesis ¶
func ExportGenesis(ctx sdk.Context, keeper Keeper) (data GenesisState)
ExportGenesis writes the current store values to a genesis file, which can be imported again with InitGenesis
type Hooks ¶
type Hooks struct {
// contains filtered or unexported fields
}
Wrapper struct
func (Hooks) AfterDelegationModified ¶
func (h Hooks) AfterDelegationModified(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress)
func (Hooks) AfterValidatorBeginUnbonding ¶
func (h Hooks) AfterValidatorBeginUnbonding(_ sdk.Context, _ sdk.ConsAddress, _ sdk.ValAddress)
nolint - unused hooks
func (Hooks) AfterValidatorBonded ¶
func (h Hooks) AfterValidatorBonded(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress)
Implements sdk.ValidatorHooks
func (Hooks) AfterValidatorCreated ¶
func (h Hooks) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress)
Implements sdk.ValidatorHooks
func (Hooks) AfterValidatorRemoved ¶
func (h Hooks) AfterValidatorRemoved(ctx sdk.Context, consAddr sdk.ConsAddress, _ sdk.ValAddress)
Implements sdk.ValidatorHooks
func (Hooks) BeforeDelegationCreated ¶
func (h Hooks) BeforeDelegationCreated(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress)
func (Hooks) BeforeDelegationRemoved ¶
func (h Hooks) BeforeDelegationRemoved(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress)
func (Hooks) BeforeDelegationSharesModified ¶
func (h Hooks) BeforeDelegationSharesModified(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress)
func (Hooks) BeforeValidatorModified ¶
func (h Hooks) BeforeValidatorModified(_ sdk.Context, _ sdk.ValAddress)
func (Hooks) BeforeValidatorSlashed ¶
type Keeper ¶
type Keeper struct {
// contains filtered or unexported fields
}
Keeper of the slashing store
func NewKeeper ¶
func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, vs sdk.ValidatorSet, paramspace params.Subspace, codespace sdk.CodespaceType) Keeper
NewKeeper creates a slashing keeper
func (Keeper) AfterValidatorBonded ¶
func (k Keeper) AfterValidatorBonded(ctx sdk.Context, address sdk.ConsAddress, _ sdk.ValAddress)
func (Keeper) AfterValidatorCreated ¶
func (k Keeper) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress)
When a validator is created, add the address-pubkey relation.
func (Keeper) AfterValidatorRemoved ¶
func (k Keeper) AfterValidatorRemoved(ctx sdk.Context, address sdk.ConsAddress)
When a validator is removed, delete the address-pubkey relation.
func (Keeper) DowntimeJailDuration ¶
Downtime unbond duration
func (Keeper) IterateValidatorMissedBlockBitArray ¶
func (k Keeper) IterateValidatorMissedBlockBitArray(ctx sdk.Context, address sdk.ConsAddress, handler func(index int64, missed bool) (stop bool))
Stored by *validator* address (not operator address)
func (Keeper) IterateValidatorSigningInfos ¶
func (k Keeper) IterateValidatorSigningInfos(ctx sdk.Context, handler func(address sdk.ConsAddress, info ValidatorSigningInfo) (stop bool))
Stored by *validator* address (not operator address)
func (Keeper) MaxEvidenceAge ¶
MaxEvidenceAge - max age for evidence
func (Keeper) MinSignedPerWindow ¶
Downtime slashing threshold
func (Keeper) SetValidatorSigningInfo ¶
func (k Keeper) SetValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress, info ValidatorSigningInfo)
Stored by *validator* address (not operator address)
func (Keeper) SignedBlocksWindow ¶
SignedBlocksWindow - sliding window for downtime slashing SignedBlocksWindow - 用于停机削减的滑动窗口
func (Keeper) SlashFractionDoubleSign ¶
SlashFractionDoubleSign
type MissedBlock ¶
MissedBlock
type MsgUnjail ¶
type MsgUnjail struct {
ValidatorAddr sdk.ValAddress `json:"address"` // address of the validator operator
}
MsgUnjail - struct for unjailing jailed validator 解禁入狱验证者
func NewMsgUnjail ¶
func NewMsgUnjail(validatorAddr sdk.ValAddress) MsgUnjail
func (MsgUnjail) GetSignBytes ¶
get the bytes for the message signer to sign on
func (MsgUnjail) GetSigners ¶
func (msg MsgUnjail) GetSigners() []sdk.AccAddress
func (MsgUnjail) ValidateBasic ¶
quick validity check
type Params ¶
type Params struct { MaxEvidenceAge time.Duration `json:"max_evidence_age"` SignedBlocksWindow int64 `json:"signed_blocks_window"` MinSignedPerWindow sdk.Dec `json:"min_signed_per_window"` DowntimeJailDuration time.Duration `json:"downtime_jail_duration"` SlashFractionDoubleSign sdk.Dec `json:"slash_fraction_double_sign"` SlashFractionDowntime sdk.Dec `json:"slash_fraction_downtime"` }
Params - used for initializing default parameter for slashing at genesis
func (*Params) ParamSetPairs ¶
func (p *Params) ParamSetPairs() params.ParamSetPairs
Implements params.ParamSet
type ValidatorSigningInfo ¶
type ValidatorSigningInfo struct { StartHeight int64 `json:"start_height"` // height at which validator was first a candidate OR was unjailed IndexOffset int64 `json:"index_offset"` // index offset into signed block bit array /* 该签名已发的惩罚,被处理时的时间 */ JailedUntil time.Time `json:"jailed_until"` // timestamp validator cannot be unjailed until // 验证器是否已被逻辑删除(从验证器集中删除) Tombstoned bool `json:"tombstoned"` // whether or not a validator has been tombstoned (killed out of validator set) MissedBlocksCounter int64 `json:"missed_blocks_counter"` // missed blocks counter (to avoid scanning the array every time) }
Signing info for a validator
某个验证人对某个block 的签名信息
func NewValidatorSigningInfo ¶
func NewValidatorSigningInfo(startHeight, indexOffset int64, jailedUntil time.Time, tombstoned bool, missedBlocksCounter int64) ValidatorSigningInfo
Construct a new `ValidatorSigningInfo` struct
func (ValidatorSigningInfo) String ¶
func (i ValidatorSigningInfo) String() string
Return human readable signing info