github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/tm2/pkg/bft/types/params.go (about)

     1  package types
     2  
     3  import (
     4  	"github.com/gnolang/gno/tm2/pkg/amino"
     5  	abci "github.com/gnolang/gno/tm2/pkg/bft/abci/types"
     6  	"github.com/gnolang/gno/tm2/pkg/crypto/ed25519"
     7  	"github.com/gnolang/gno/tm2/pkg/errors"
     8  )
     9  
    10  const (
    11  	// MaxBlockSizeBytes is the maximum permitted size of the blocks.
    12  	MaxBlockSizeBytes = 104857600 // 100MB
    13  
    14  	// BlockPartSizeBytes is the size of one block part.
    15  	BlockPartSizeBytes = 65536 // 64kB
    16  
    17  	// MaxBlockPartsCount is the maximum count of block parts.
    18  	MaxBlockPartsCount = (MaxBlockSizeBytes / BlockPartSizeBytes) + 1
    19  
    20  	// MaxBlockTxBytes is the max size of the block transaction
    21  	MaxBlockTxBytes int64 = 1000000 // 1MB
    22  
    23  	// MaxBlockDataBytes is the max size of the block data
    24  	MaxBlockDataBytes int64 = 2000000 // 2MB
    25  
    26  	// MaxBlockMaxGas is the max gas limit for the block
    27  	MaxBlockMaxGas int64 = 100000000 // 100M gas
    28  
    29  	// BlockTimeIotaMS is the block time iota (in ms)
    30  	BlockTimeIotaMS int64 = 100 // ms
    31  )
    32  
    33  var validatorPubKeyTypeURLs = map[string]struct{}{
    34  	amino.GetTypeURL(ed25519.PubKeyEd25519{}): {},
    35  }
    36  
    37  func DefaultConsensusParams() abci.ConsensusParams {
    38  	return abci.ConsensusParams{
    39  		DefaultBlockParams(),
    40  		DefaultValidatorParams(),
    41  	}
    42  }
    43  
    44  func DefaultBlockParams() *abci.BlockParams {
    45  	return &abci.BlockParams{
    46  		MaxTxBytes:   MaxBlockTxBytes,
    47  		MaxDataBytes: MaxBlockDataBytes,
    48  		MaxGas:       MaxBlockMaxGas,
    49  		TimeIotaMS:   BlockTimeIotaMS,
    50  	}
    51  }
    52  
    53  func DefaultValidatorParams() *abci.ValidatorParams {
    54  	return &abci.ValidatorParams{[]string{
    55  		amino.GetTypeURL(ed25519.PubKeyEd25519{}),
    56  	}}
    57  }
    58  
    59  func ValidateConsensusParams(params abci.ConsensusParams) error {
    60  	if params.Block.MaxTxBytes <= 0 {
    61  		return errors.New("Block.MaxTxBytes must be greater than 0. Got %d",
    62  			params.Block.MaxTxBytes)
    63  	}
    64  	if params.Block.MaxTxBytes > MaxBlockSizeBytes {
    65  		return errors.New("Block.MaxTxBytes is too big. %d > %d",
    66  			params.Block.MaxTxBytes, MaxBlockSizeBytes)
    67  	}
    68  
    69  	if params.Block.MaxGas < -1 {
    70  		return errors.New("Block.MaxGas must be greater or equal to -1. Got %d",
    71  			params.Block.MaxGas)
    72  	}
    73  
    74  	if params.Block.TimeIotaMS <= 0 {
    75  		return errors.New("Block.TimeIotaMS must be greater than 0. Got %v",
    76  			params.Block.TimeIotaMS)
    77  	}
    78  
    79  	if len(params.Validator.PubKeyTypeURLs) == 0 {
    80  		return errors.New("len(Validator.PubKeyTypeURLs) must be greater than 0")
    81  	}
    82  
    83  	// Check if keyType is a known ABCIPubKeyType
    84  	for i := 0; i < len(params.Validator.PubKeyTypeURLs); i++ {
    85  		keyType := params.Validator.PubKeyTypeURLs[i]
    86  		if _, ok := validatorPubKeyTypeURLs[keyType]; !ok {
    87  			return errors.New("params.Validator.PubKeyTypeURLs[%d], %s, is an unknown pubKey type",
    88  				i, keyType)
    89  		}
    90  	}
    91  
    92  	return nil
    93  }