mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-28 03:46:33 +00:00
types: ConsensusParams test + document the ranges/limits
Fixes https://github.com/tendermint/tendermint/issues/747 Updates https://github.com/tendermint/tendermint/issues/693 * Document the unmentioned limits for ConsensusParams.Validate() * Make the limit for ConsensusParams.BlockSizeParams.MaxBytes clear at 100MiB
This commit is contained in:
+7
-3
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
maxBlockSizeBytes = 104857600 // 100MB
|
||||
_100MiB = 104857600
|
||||
)
|
||||
|
||||
// ConsensusParams contains consensus critical parameters
|
||||
@@ -69,6 +69,10 @@ func DefaultBlockGossipParams() BlockGossipParams {
|
||||
|
||||
// Validate validates the ConsensusParams to ensure all values
|
||||
// are within their allowed limits, and returns an error if they are not.
|
||||
// Expecting:
|
||||
// * BlockSizeParams.MaxBytes > 0
|
||||
// * BlockGossipParams.BlockPartSizeBytes > 0
|
||||
// * BlockSizeParams.MaxBytes <= 100MiB
|
||||
func (params *ConsensusParams) Validate() error {
|
||||
// ensure some values are greater than 0
|
||||
if params.BlockSizeParams.MaxBytes <= 0 {
|
||||
@@ -79,9 +83,9 @@ func (params *ConsensusParams) Validate() error {
|
||||
}
|
||||
|
||||
// ensure blocks aren't too big
|
||||
if params.BlockSizeParams.MaxBytes > maxBlockSizeBytes {
|
||||
if params.BlockSizeParams.MaxBytes > _100MiB {
|
||||
return errors.Errorf("BlockSizeParams.MaxBytes is too big. %d > %d",
|
||||
params.BlockSizeParams.MaxBytes, maxBlockSizeBytes)
|
||||
params.BlockSizeParams.MaxBytes, _100MiB)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package types_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
func TestConsensusParamsValidation(t *testing.T) {
|
||||
tests := [...]struct {
|
||||
params *types.ConsensusParams
|
||||
wantErr string
|
||||
}{
|
||||
{&types.ConsensusParams{}, "BlockSizeParams.MaxBytes must be greater than 0"},
|
||||
{
|
||||
&types.ConsensusParams{BlockSizeParams: types.BlockSizeParams{MaxBytes: 10}},
|
||||
"BlockGossipParams.BlockPartSizeBytes must be greater than 0",
|
||||
},
|
||||
{
|
||||
&types.ConsensusParams{
|
||||
BlockSizeParams: types.BlockSizeParams{MaxBytes: 10},
|
||||
BlockGossipParams: types.BlockGossipParams{BlockPartSizeBytes: -1},
|
||||
}, "BlockGossipParams.BlockPartSizeBytes must be greater than 0",
|
||||
},
|
||||
{
|
||||
&types.ConsensusParams{
|
||||
BlockSizeParams: types.BlockSizeParams{MaxBytes: 10},
|
||||
BlockGossipParams: types.BlockGossipParams{BlockPartSizeBytes: 400},
|
||||
}, ""},
|
||||
{
|
||||
&types.ConsensusParams{
|
||||
BlockSizeParams: types.BlockSizeParams{MaxBytes: 1024 * 1024 * 47},
|
||||
BlockGossipParams: types.BlockGossipParams{BlockPartSizeBytes: 400},
|
||||
}, "",
|
||||
},
|
||||
{
|
||||
&types.ConsensusParams{
|
||||
BlockSizeParams: types.BlockSizeParams{MaxBytes: 1024 * 1024 * 100},
|
||||
BlockGossipParams: types.BlockGossipParams{BlockPartSizeBytes: 400},
|
||||
}, "",
|
||||
},
|
||||
{
|
||||
&types.ConsensusParams{
|
||||
BlockSizeParams: types.BlockSizeParams{MaxBytes: 1024 * 1024 * 101},
|
||||
BlockGossipParams: types.BlockGossipParams{BlockPartSizeBytes: 400},
|
||||
}, "BlockSizeParams.MaxBytes is too big",
|
||||
},
|
||||
{
|
||||
&types.ConsensusParams{
|
||||
BlockSizeParams: types.BlockSizeParams{MaxBytes: 1024 * 1024 * 1024},
|
||||
BlockGossipParams: types.BlockGossipParams{BlockPartSizeBytes: 400},
|
||||
}, "BlockSizeParams.MaxBytes is too big",
|
||||
},
|
||||
}
|
||||
|
||||
for i, tt := range tests {
|
||||
err := tt.params.Validate()
|
||||
if tt.wantErr != "" {
|
||||
assert.Contains(t, err.Error(), tt.wantErr, "#%d: params: %#v", i, tt.params)
|
||||
} else {
|
||||
assert.Nil(t, err, "#%d: want nil error; Params: %#v", i, tt.params)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user