github.com/Finschia/finschia-sdk@v0.48.1/baseapp/params.go (about)

     1  package baseapp
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  
     7  	abci "github.com/tendermint/tendermint/abci/types"
     8  	tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
     9  	tmtypes "github.com/tendermint/tendermint/types"
    10  
    11  	sdk "github.com/Finschia/finschia-sdk/types"
    12  )
    13  
    14  // Paramspace defines the parameter subspace to be used for the paramstore.
    15  const Paramspace = "baseapp"
    16  
    17  // Parameter store keys for all the consensus parameter types.
    18  var (
    19  	ParamStoreKeyBlockParams     = []byte("BlockParams")
    20  	ParamStoreKeyEvidenceParams  = []byte("EvidenceParams")
    21  	ParamStoreKeyValidatorParams = []byte("ValidatorParams")
    22  )
    23  
    24  // ParamStore defines the interface the parameter store used by the BaseApp must
    25  // fulfill.
    26  type ParamStore interface {
    27  	Get(ctx sdk.Context, key []byte, ptr interface{})
    28  	Has(ctx sdk.Context, key []byte) bool
    29  	Set(ctx sdk.Context, key []byte, param interface{})
    30  }
    31  
    32  // ValidateBlockParams defines a stateless validation on BlockParams. This function
    33  // is called whenever the parameters are updated or stored.
    34  func ValidateBlockParams(i interface{}) error {
    35  	v, ok := i.(abci.BlockParams)
    36  	if !ok {
    37  		return fmt.Errorf("invalid parameter type: %T", i)
    38  	}
    39  
    40  	if v.MaxBytes <= 0 {
    41  		return fmt.Errorf("block maximum bytes must be positive: %d", v.MaxBytes)
    42  	}
    43  
    44  	if v.MaxGas < -1 {
    45  		return fmt.Errorf("block maximum gas must be greater than or equal to -1: %d", v.MaxGas)
    46  	}
    47  
    48  	return nil
    49  }
    50  
    51  // ValidateEvidenceParams defines a stateless validation on EvidenceParams. This
    52  // function is called whenever the parameters are updated or stored.
    53  func ValidateEvidenceParams(i interface{}) error {
    54  	v, ok := i.(tmproto.EvidenceParams)
    55  	if !ok {
    56  		return fmt.Errorf("invalid parameter type: %T", i)
    57  	}
    58  
    59  	if v.MaxAgeNumBlocks <= 0 {
    60  		return fmt.Errorf("evidence maximum age in blocks must be positive: %d", v.MaxAgeNumBlocks)
    61  	}
    62  
    63  	if v.MaxAgeDuration <= 0 {
    64  		return fmt.Errorf("evidence maximum age time duration must be positive: %v", v.MaxAgeDuration)
    65  	}
    66  
    67  	if v.MaxBytes < 0 {
    68  		return fmt.Errorf("maximum evidence bytes must be non-negative: %v", v.MaxBytes)
    69  	}
    70  
    71  	return nil
    72  }
    73  
    74  // ValidateValidatorParams defines a stateless validation on ValidatorParams. This
    75  // function is called whenever the parameters are updated or stored.
    76  func ValidateValidatorParams(i interface{}) error {
    77  	v, ok := i.(tmproto.ValidatorParams)
    78  	if !ok {
    79  		return fmt.Errorf("invalid parameter type: %T", i)
    80  	}
    81  
    82  	if len(v.PubKeyTypes) == 0 {
    83  		return errors.New("validator allowed pubkey types must not be empty")
    84  	}
    85  
    86  	for _, pubKeyType := range v.PubKeyTypes {
    87  		switch pubKeyType {
    88  		case tmtypes.ABCIPubKeyTypeEd25519, tmtypes.ABCIPubKeyTypeSecp256k1:
    89  			continue
    90  		default:
    91  			return fmt.Errorf("not-allowed pubkey type: %s", pubKeyType)
    92  		}
    93  	}
    94  
    95  	return nil
    96  }