github.com/Finschia/finschia-sdk@v0.48.1/x/slashing/types/genesis.go (about)

     1  package types
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	sdk "github.com/Finschia/finschia-sdk/types"
     8  )
     9  
    10  // NewGenesisState creates a new GenesisState object
    11  func NewGenesisState(
    12  	params Params, signingInfos []SigningInfo, missedBlocks []ValidatorMissedBlocks,
    13  ) *GenesisState {
    14  	return &GenesisState{
    15  		Params:       params,
    16  		SigningInfos: signingInfos,
    17  		MissedBlocks: missedBlocks,
    18  	}
    19  }
    20  
    21  // NewMissedBlock creates a new MissedBlock instance
    22  func NewMissedBlock(index int64, missed bool) MissedBlock {
    23  	return MissedBlock{
    24  		Index:  index,
    25  		Missed: missed,
    26  	}
    27  }
    28  
    29  // DefaultGenesisState - default GenesisState used by Cosmos Hub
    30  func DefaultGenesisState() *GenesisState {
    31  	return &GenesisState{
    32  		Params:       DefaultParams(),
    33  		SigningInfos: []SigningInfo{},
    34  		MissedBlocks: []ValidatorMissedBlocks{},
    35  	}
    36  }
    37  
    38  // ValidateGenesis validates the slashing genesis parameters
    39  func ValidateGenesis(data GenesisState) error {
    40  	downtime := data.Params.SlashFractionDowntime
    41  	if downtime.IsNegative() || downtime.GT(sdk.OneDec()) {
    42  		return fmt.Errorf("slashing fraction downtime should be less than or equal to one and greater than zero, is %s", downtime.String())
    43  	}
    44  
    45  	dblSign := data.Params.SlashFractionDoubleSign
    46  	if dblSign.IsNegative() || dblSign.GT(sdk.OneDec()) {
    47  		return fmt.Errorf("slashing fraction double sign should be less than or equal to one and greater than zero, is %s", dblSign.String())
    48  	}
    49  
    50  	minSign := data.Params.MinSignedPerWindow
    51  	if minSign.IsNegative() || minSign.GT(sdk.OneDec()) {
    52  		return fmt.Errorf("min signed per window should be less than or equal to one and greater than zero, is %s", minSign.String())
    53  	}
    54  
    55  	downtimeJail := data.Params.DowntimeJailDuration
    56  	if downtimeJail < 1*time.Minute {
    57  		return fmt.Errorf("downtime unjail duration must be at least 1 minute, is %s", downtimeJail.String())
    58  	}
    59  
    60  	signedWindow := data.Params.SignedBlocksWindow
    61  	if signedWindow < 10 {
    62  		return fmt.Errorf("signed blocks window must be at least 10, is %d", signedWindow)
    63  	}
    64  
    65  	return nil
    66  }