github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/slashing/internal/types/genesis.go (about) 1 package types 2 3 import ( 4 "fmt" 5 "time" 6 7 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 8 ) 9 10 // GenesisState - all slashing state that must be provided at genesis 11 type GenesisState struct { 12 Params Params `json:"params" yaml:"params"` 13 SigningInfos map[string]ValidatorSigningInfo `json:"signing_infos" yaml:"signing_infos"` 14 MissedBlocks map[string][]MissedBlock `json:"missed_blocks" yaml:"missed_blocks"` 15 } 16 17 // NewGenesisState creates a new GenesisState object 18 func NewGenesisState( 19 params Params, signingInfos map[string]ValidatorSigningInfo, missedBlocks map[string][]MissedBlock, 20 ) GenesisState { 21 22 return GenesisState{ 23 Params: params, 24 SigningInfos: signingInfos, 25 MissedBlocks: missedBlocks, 26 } 27 } 28 29 // MissedBlock 30 type MissedBlock struct { 31 Index int64 `json:"index" yaml:"index"` 32 Missed bool `json:"missed" yaml:"missed"` 33 } 34 35 // NewMissedBlock creates a new MissedBlock instance 36 func NewMissedBlock(index int64, missed bool) MissedBlock { 37 return MissedBlock{ 38 Index: index, 39 Missed: missed, 40 } 41 } 42 43 // DefaultGenesisState - default GenesisState used by Cosmos Hub 44 func DefaultGenesisState() GenesisState { 45 return GenesisState{ 46 Params: DefaultParams(), 47 SigningInfos: make(map[string]ValidatorSigningInfo), 48 MissedBlocks: make(map[string][]MissedBlock), 49 } 50 } 51 52 // ValidateGenesis validates the slashing genesis parameters 53 func ValidateGenesis(data GenesisState) error { 54 downtime := data.Params.SlashFractionDowntime 55 if downtime.IsNegative() || downtime.GT(sdk.OneDec()) { 56 return fmt.Errorf("slashing fraction downtime should be less than or equal to one and greater than zero, is %s", downtime.String()) 57 } 58 59 dblSign := data.Params.SlashFractionDoubleSign 60 if dblSign.IsNegative() || dblSign.GT(sdk.OneDec()) { 61 return fmt.Errorf("slashing fraction double sign should be less than or equal to one and greater than zero, is %s", dblSign.String()) 62 } 63 64 minSign := data.Params.MinSignedPerWindow 65 if minSign.IsNegative() || minSign.GT(sdk.OneDec()) { 66 return fmt.Errorf("min signed per window should be less than or equal to one and greater than zero, is %s", minSign.String()) 67 } 68 69 downtimeJail := data.Params.DowntimeJailDuration 70 if downtimeJail < 1*time.Minute { 71 return fmt.Errorf("downtime unblond duration must be at least 1 minute, is %s", downtimeJail.String()) 72 } 73 74 signedWindow := data.Params.SignedBlocksWindow 75 if signedWindow < 10 { 76 return fmt.Errorf("signed blocks window must be at least 10, is %d", signedWindow) 77 } 78 79 return nil 80 }