Documentation ¶
Overview ¶
nolint
Index ¶
- Constants
- Variables
- func AllInvariants() sdk.Invariant
- func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, sk Keeper) (tags sdk.Tags)
- func EndBlocker(ctx sdk.Context, req abci.RequestEndBlock, sk Keeper) (tags sdk.Tags)
- func ErrBadValidatorAddr(codespace sdk.CodespaceType) sdk.Error
- func ErrMissingSelfDelegation(codespace sdk.CodespaceType) sdk.Error
- func ErrNoValidatorForAddress(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, sdata types.GenesisState)
- func NewHandler(k Keeper) sdk.Handler
- func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt sdk.Int) stake.MsgCreateValidator
- func ParamTypeTable() params.TypeTable
- func RegisterCodec(cdc *codec.Codec)
- func ValidateGenesis(data GenesisState) error
- type CodeType
- type GenesisState
- type Hooks
- func (h Hooks) OnDelegationCreated(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress)
- func (h Hooks) OnDelegationRemoved(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress)
- func (h Hooks) OnDelegationSharesModified(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress)
- func (h Hooks) OnValidatorBeginUnbonding(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress)
- func (h Hooks) OnValidatorBonded(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress)
- func (h Hooks) OnValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress)
- func (h Hooks) OnValidatorModified(_ sdk.Context, _ sdk.ValAddress)
- func (h Hooks) OnValidatorPowerDidChange(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress)
- func (h Hooks) OnValidatorRemoved(ctx sdk.Context, consAddr sdk.ConsAddress, _ sdk.ValAddress)
- type Keeper
- func (k Keeper) CensorshipJailDuration(ctx sdk.Context) (res time.Duration)
- func (k Keeper) DeleteValidatorSlashingPeriods(ctx sdk.Context)
- func (k Keeper) DoubleSignJailDuration(ctx sdk.Context) (res time.Duration)
- func (k Keeper) DowntimeJailDuration(ctx sdk.Context) (res time.Duration)
- func (k Keeper) GetParamSet(ctx sdk.Context) Params
- func (k Keeper) Hooks() Hooks
- func (k Keeper) IterateValidatorSigningInfos(ctx sdk.Context, ...)
- func (k Keeper) MaxEvidenceAge(ctx sdk.Context) (res int64)
- func (k Keeper) MinSignedPerWindow(ctx sdk.Context) int64
- func (k Keeper) SetParamSet(ctx sdk.Context, params Params)
- func (k Keeper) SetValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress, info ValidatorSigningInfo)
- func (k Keeper) SetValidatorSlashingPeriod(ctx sdk.Context, slashingPeriod ValidatorSlashingPeriod)
- func (k Keeper) SignedBlocksWindow(ctx sdk.Context) (res int64)
- func (k Keeper) SlashFractionCensorship(ctx sdk.Context) (res sdk.Dec)
- func (k Keeper) SlashFractionDoubleSign(ctx sdk.Context) (res sdk.Dec)
- func (k Keeper) SlashFractionDowntime(ctx sdk.Context) (res sdk.Dec)
- type Metrics
- type MissedBlock
- type MsgUnjail
- type Params
- func (p *Params) GetParamSpace() string
- func (p *Params) KeyValuePairs() params.KeyValuePairs
- func (p *Params) ReadOnly() bool
- func (p Params) String() string
- func (p *Params) StringFromBytes(cdc *codec.Codec, key string, bytes []byte) (string, error)
- func (p *Params) Validate(key string, value string) (interface{}, sdk.Error)
- type ValidatorSigningInfo
- type ValidatorSlashingPeriod
- type ValidatorSlashingPeriodValue
Constants ¶
const ( DefaultParamspace = "slashing" BlocksPerMinute = 12 // 5 seconds a block BlocksPerDay = BlocksPerMinute * 60 * 24 // 17280 )
Default parameter namespace
const MetricsSubsystem = "module_slashing"
const MsgRoute = "slashing"
name to identify transaction types
Variables ¶
var ( ValidatorSigningInfoKey = []byte{0x01} // Prefix for signing info ValidatorMissedBlockBitArrayKey = []byte{0x02} // Prefix for missed block bit array ValidatorSlashingPeriodKey = []byte{0x03} // Prefix for slashing period AddrPubkeyRelationKey = []byte{0x04} // Prefix for address-pubkey relation )
key prefix bytes
var ( KeyMaxEvidenceAge = []byte("MaxEvidenceAge") KeySignedBlocksWindow = []byte("SignedBlocksWindow") KeyMinSignedPerWindow = []byte("MinSignedPerWindow") KeyDoubleSignJailDuration = []byte("DoubleSignJailDuration") KeyDowntimeJailDuration = []byte("DowntimeJailDuration") KeyCensorshipJailDuration = []byte("CensorshipJailDuration") KeySlashFractionDoubleSign = []byte("SlashFractionDoubleSign") KeySlashFractionDowntime = []byte("SlashFractionDowntime") KeySlashFractionCensorship = []byte("SlashFractionCensorship") )
Parameter store key
Functions ¶
func AllInvariants ¶
TODO Any invariants to check here? AllInvariants tests all slashing invariants
func BeginBlocker ¶
slashing begin block functionality
func EndBlocker ¶
slashing end block functionality
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 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)
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 ¶
func InitGenesis(ctx sdk.Context, keeper Keeper, data GenesisState, sdata types.GenesisState)
InitGenesis initialize default parameters and the keeper's address to pubkey map
func NewHandler ¶
func NewTestMsgCreateValidator ¶
func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt sdk.Int) stake.MsgCreateValidator
func ValidateGenesis ¶
func ValidateGenesis(data GenesisState) error
Types ¶
type GenesisState ¶
type GenesisState struct { Params Params `json:"params"` SigningInfos map[string]ValidatorSigningInfo `json:"signing_infos"` MissedBlocks map[string][]MissedBlock `json:"missed_blocks"` SlashingPeriods []ValidatorSlashingPeriod `json:"slashing_periods"` }
GenesisState - all slashing state that must be provided at genesis
func DefaultGenesisState ¶
func DefaultGenesisState() GenesisState
HubDefaultGenesisState - 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) OnDelegationCreated ¶
func (h Hooks) OnDelegationCreated(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress)
func (Hooks) OnDelegationRemoved ¶
func (h Hooks) OnDelegationRemoved(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress)
func (Hooks) OnDelegationSharesModified ¶
func (h Hooks) OnDelegationSharesModified(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress)
func (Hooks) OnValidatorBeginUnbonding ¶
func (h Hooks) OnValidatorBeginUnbonding(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress)
Implements sdk.ValidatorHooks
func (Hooks) OnValidatorBonded ¶
func (h Hooks) OnValidatorBonded(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress)
Implements sdk.ValidatorHooks
func (Hooks) OnValidatorCreated ¶
func (h Hooks) OnValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress)
Implements sdk.ValidatorHooks
func (Hooks) OnValidatorModified ¶
func (h Hooks) OnValidatorModified(_ sdk.Context, _ sdk.ValAddress)
func (Hooks) OnValidatorPowerDidChange ¶
func (h Hooks) OnValidatorPowerDidChange(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress)
nolint - unused hooks
func (Hooks) OnValidatorRemoved ¶
func (h Hooks) OnValidatorRemoved(ctx sdk.Context, consAddr sdk.ConsAddress, _ sdk.ValAddress)
Implements sdk.ValidatorHooks
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, metrics *Metrics) Keeper
NewKeeper creates a slashing keeper
func (Keeper) CensorshipJailDuration ¶
Censorship jail duration
func (Keeper) DeleteValidatorSlashingPeriods ¶
Delete all slashing periods in the store.
func (Keeper) DoubleSignJailDuration ¶
Double-sign jail duration
func (Keeper) DowntimeJailDuration ¶
Downtime jail duration
func (Keeper) GetParamSet ¶
get inflation params from the global param store
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 thershold - default 50% of the SignedBlocksWindow
func (Keeper) SetParamSet ¶
set inflation params from the global param store
func (Keeper) SetValidatorSigningInfo ¶
func (k Keeper) SetValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress, info ValidatorSigningInfo)
Stored by *validator* address (not operator address)
func (Keeper) SetValidatorSlashingPeriod ¶
func (k Keeper) SetValidatorSlashingPeriod(ctx sdk.Context, slashingPeriod ValidatorSlashingPeriod)
Stored by validator Tendermint address (not operator address) This function sets a validator slashing period for a particular validator, start height, end height, and current slashed-so-far total, or updates an existing slashing period for the same validator and start height.
func (Keeper) SignedBlocksWindow ¶
SignedBlocksWindow - sliding window for downtime slashing
func (Keeper) SlashFractionCensorship ¶
Slash fraction for Censorship
func (Keeper) SlashFractionDoubleSign ¶
Slash fraction for DoubleSign
type Metrics ¶
func NopMetrics ¶
func NopMetrics() *Metrics
func PrometheusMetrics ¶
func PrometheusMetrics(config *cfg.InstrumentationConfig) *Metrics
PrometheusMetrics returns Metrics build using Prometheus client library.
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 int64 `json:"max_evidence_age"` SignedBlocksWindow int64 `json:"signed_blocks_window"` MinSignedPerWindow sdk.Dec `json:"min_signed_per_window"` DoubleSignJailDuration time.Duration `json:"double_sign_jail_duration"` DowntimeJailDuration time.Duration `json:"downtime_jail_duration"` CensorshipJailDuration time.Duration `json:"censorship_jail_duration"` SlashFractionDoubleSign sdk.Dec `json:"slash_fraction_double_sign"` SlashFractionDowntime sdk.Dec `json:"slash_fraction_downtime"` SlashFractionCensorship sdk.Dec `json:"slash_fraction_censorship"` }
Params - used for initializing default parameter for slashing at genesis
func DefaultParamsForTestnet ¶
func DefaultParamsForTestnet() Params
func (*Params) GetParamSpace ¶
func (*Params) KeyValuePairs ¶
func (p *Params) KeyValuePairs() params.KeyValuePairs
Implements params.ParamStruct
func (*Params) StringFromBytes ¶
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 MissedBlocksCounter int64 `json:"missed_blocks_counter"` // missed blocks counter (to avoid scanning the array every time) }
Signing info for a validator
func NewValidatorSigningInfo ¶
func NewValidatorSigningInfo(startHeight int64, indexOffset int64, jailedUntil time.Time, missedBlocksCounter int64) ValidatorSigningInfo
Construct a new `ValidatorSigningInfo` struct
func (ValidatorSigningInfo) String ¶
func (i ValidatorSigningInfo) String() string
Return human readable signing info
type ValidatorSlashingPeriod ¶
type ValidatorSlashingPeriod struct { ValidatorAddr sdk.ConsAddress `json:"validator_addr"` // validator which this slashing period is for StartHeight int64 `json:"start_height"` // starting height of the slashing period EndHeight int64 `json:"end_height"` // ending height of the slashing period, or sentinel value of 0 for in-progress SlashedSoFar sdk.Dec `json:"slashed_so_far"` // fraction of validator stake slashed so far in this slashing period }
Slashing period for a validator
func NewValidatorSlashingPeriod ¶
func NewValidatorSlashingPeriod(startHeight int64, endHeight int64, slashedSoFar sdk.Dec) ValidatorSlashingPeriod
Construct a new `ValidatorSlashingPeriod` struct
func (ValidatorSlashingPeriod) HumanReadableString ¶
func (p ValidatorSlashingPeriod) HumanReadableString() string
Return human readable slashing period
type ValidatorSlashingPeriodValue ¶
type ValidatorSlashingPeriodValue struct { EndHeight int64 `json:"end_height"` SlashedSoFar sdk.Dec `json:"slashed_so_far"` }
Value part of slashing period (validator address & start height are stored in the key)