2019-06-05 16:26:17 -07:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewGenesisState creates a new GenesisState object
|
2019-07-05 05:34:02 -07:00
|
|
|
func NewGenesisState(
|
2020-08-04 05:58:36 -07:00
|
|
|
params Params, signingInfos []SigningInfo, missedBlocks []ValidatorMissedBlocks,
|
2020-08-11 07:22:30 -07:00
|
|
|
) *GenesisState {
|
2019-06-05 16:26:17 -07:00
|
|
|
|
2020-08-11 07:22:30 -07:00
|
|
|
return &GenesisState{
|
2019-06-05 16:26:17 -07:00
|
|
|
Params: params,
|
|
|
|
SigningInfos: signingInfos,
|
|
|
|
MissedBlocks: missedBlocks,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-19 06:43:38 -07:00
|
|
|
// NewMissedBlock creates a new MissedBlock instance
|
|
|
|
func NewMissedBlock(index int64, missed bool) MissedBlock {
|
|
|
|
return MissedBlock{
|
|
|
|
Index: index,
|
|
|
|
Missed: missed,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-05 16:26:17 -07:00
|
|
|
// DefaultGenesisState - default GenesisState used by Cosmos Hub
|
2020-08-11 07:22:30 -07:00
|
|
|
func DefaultGenesisState() *GenesisState {
|
|
|
|
return &GenesisState{
|
2019-06-05 16:26:17 -07:00
|
|
|
Params: DefaultParams(),
|
2020-08-04 05:58:36 -07:00
|
|
|
SigningInfos: []SigningInfo{},
|
|
|
|
MissedBlocks: []ValidatorMissedBlocks{},
|
2019-06-05 16:26:17 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ValidateGenesis validates the slashing genesis parameters
|
|
|
|
func ValidateGenesis(data GenesisState) error {
|
|
|
|
downtime := data.Params.SlashFractionDowntime
|
|
|
|
if downtime.IsNegative() || downtime.GT(sdk.OneDec()) {
|
2019-08-19 09:06:27 -07:00
|
|
|
return fmt.Errorf("slashing fraction downtime should be less than or equal to one and greater than zero, is %s", downtime.String())
|
2019-06-05 16:26:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
dblSign := data.Params.SlashFractionDoubleSign
|
|
|
|
if dblSign.IsNegative() || dblSign.GT(sdk.OneDec()) {
|
2019-08-19 09:06:27 -07:00
|
|
|
return fmt.Errorf("slashing fraction double sign should be less than or equal to one and greater than zero, is %s", dblSign.String())
|
2019-06-05 16:26:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
minSign := data.Params.MinSignedPerWindow
|
|
|
|
if minSign.IsNegative() || minSign.GT(sdk.OneDec()) {
|
2019-08-19 09:06:27 -07:00
|
|
|
return fmt.Errorf("min signed per window should be less than or equal to one and greater than zero, is %s", minSign.String())
|
2019-06-05 16:26:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
downtimeJail := data.Params.DowntimeJailDuration
|
|
|
|
if downtimeJail < 1*time.Minute {
|
2021-06-01 06:20:16 -07:00
|
|
|
return fmt.Errorf("downtime unjail duration must be at least 1 minute, is %s", downtimeJail.String())
|
2019-06-05 16:26:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
signedWindow := data.Params.SignedBlocksWindow
|
|
|
|
if signedWindow < 10 {
|
2019-08-19 09:06:27 -07:00
|
|
|
return fmt.Errorf("signed blocks window must be at least 10, is %d", signedWindow)
|
2019-06-05 16:26:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|