mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-06 08:07:11 +00:00
updated to match adr 005
This commit is contained in:
+14
-5
@@ -52,22 +52,31 @@ func TestGenesis(t *testing.T) {
|
||||
assert.Nil(t, err, "expected no error for valid genDoc json")
|
||||
|
||||
// test with invalid consensus params
|
||||
genDoc.ConsensusParams.MaxBlockSizeBytes = 0
|
||||
genDoc.ConsensusParams.BlockSizeParams.MaxBytes = 0
|
||||
genDocBytes, err = json.Marshal(genDoc)
|
||||
assert.Nil(t, err, "error marshalling genDoc")
|
||||
genDoc, err = GenesisDocFromJSON(genDocBytes)
|
||||
assert.NotNil(t, err, "expected error for genDoc json with block size of 0")
|
||||
}
|
||||
|
||||
func newConsensusParams(blockSize, partSize int) *ConsensusParams {
|
||||
return &ConsensusParams{
|
||||
BlockSizeParams: &BlockSizeParams{MaxBytes: blockSize},
|
||||
BlockGossipParams: &BlockGossipParams{BlockPartSizeBytes: partSize},
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestConsensusParams(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
params *ConsensusParams
|
||||
valid bool
|
||||
}{
|
||||
{&ConsensusParams{1, 1}, true},
|
||||
{&ConsensusParams{1, 0}, false},
|
||||
{&ConsensusParams{0, 1}, false},
|
||||
{&ConsensusParams{0, 0}, false},
|
||||
{newConsensusParams(1, 1), true},
|
||||
{newConsensusParams(1, 0), false},
|
||||
{newConsensusParams(0, 1), false},
|
||||
{newConsensusParams(0, 0), false},
|
||||
}
|
||||
for _, testCase := range testCases {
|
||||
if testCase.valid {
|
||||
|
||||
+52
-8
@@ -7,26 +7,70 @@ import (
|
||||
// ConsensusParams contains consensus critical parameters
|
||||
// that determine the validity of blocks.
|
||||
type ConsensusParams struct {
|
||||
MaxBlockSizeBytes int `json:"max_block_size_bytes"`
|
||||
BlockPartSizeBytes int `json:"block_part_size_bytes"`
|
||||
*BlockSizeParams `json:"block_size_params"`
|
||||
*TxSizeParams `json:"tx_size_params"`
|
||||
*BlockGossipParams `json:"block_gossip_params"`
|
||||
}
|
||||
|
||||
// BlockSizeParams contain limits on the block size.
|
||||
type BlockSizeParams struct {
|
||||
MaxBytes int `json:"max_bytes"` // NOTE: must not be 0
|
||||
MaxTxs int `json:"max_txs"`
|
||||
MaxGas int `json:"max_gas"`
|
||||
}
|
||||
|
||||
// TxSizeParams contain limits on the tx size.
|
||||
type TxSizeParams struct {
|
||||
MaxBytes int `json:"max_bytes"`
|
||||
MaxGas int `json:"max_gas"`
|
||||
}
|
||||
|
||||
// BlockGossipParams determine consensus critical elements of how blocks are gossiped
|
||||
type BlockGossipParams struct {
|
||||
BlockPartSizeBytes int `json:"block_part_size_bytes"` // NOTE: must not be 0
|
||||
}
|
||||
|
||||
// DefaultConsensusParams returns a default ConsensusParams.
|
||||
func DefaultConsensusParams() *ConsensusParams {
|
||||
return &ConsensusParams{
|
||||
MaxBlockSizeBytes: 22020096, // 21MB
|
||||
BlockPartSizeBytes: 65536, // 64kB,
|
||||
DefaultBlockSizeParams(),
|
||||
DefaultTxSizeParams(),
|
||||
DefaultBlockGossipParams(),
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultBlockSizeParams returns a default BlockSizeParams.
|
||||
func DefaultBlockSizeParams() *BlockSizeParams {
|
||||
return &BlockSizeParams{
|
||||
MaxBytes: 22020096, // 21MB
|
||||
MaxTxs: 100000,
|
||||
MaxGas: -1,
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultTxSizeParams returns a default TxSizeParams.
|
||||
func DefaultTxSizeParams() *TxSizeParams {
|
||||
return &TxSizeParams{
|
||||
MaxBytes: 10240, // 10kB
|
||||
MaxGas: -1,
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultBlockGossipParams returns a default BlockGossipParams.
|
||||
func DefaultBlockGossipParams() *BlockGossipParams {
|
||||
return &BlockGossipParams{
|
||||
BlockPartSizeBytes: 65536, // 64kB,
|
||||
}
|
||||
}
|
||||
|
||||
// Validate validates the ConsensusParams to ensure all values
|
||||
// are within their allowed limits, and returns an error if they are not.
|
||||
func (params *ConsensusParams) Validate() error {
|
||||
if params.MaxBlockSizeBytes <= 0 {
|
||||
return errors.Errorf("MaxBlockSizeBytes must be greater than 0. Got %d", params.MaxBlockSizeBytes)
|
||||
if params.BlockSizeParams.MaxBytes <= 0 {
|
||||
return errors.Errorf("BlockSizeParams.MaxBytes must be greater than 0. Got %d", params.BlockSizeParams.MaxBytes)
|
||||
}
|
||||
if params.BlockPartSizeBytes <= 0 {
|
||||
return errors.Errorf("BlockPartSizeBytes must be greater than 0. Got %d", params.BlockPartSizeBytes)
|
||||
if params.BlockGossipParams.BlockPartSizeBytes <= 0 {
|
||||
return errors.Errorf("BlockGossipParams.BlockPartSizeBytes must be greater than 0. Got %d", params.BlockGossipParams.BlockPartSizeBytes)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user