Remove ConsensusParams.TxSize and ConsensusParams.BlockGossip (#2364)

* remove ConsensusParams.TxSize and ConsensusParams.BlockGossip

Refs #2347

* block part size is now fixed

Refs #2347

* use max data size, not max bytes for tx limit

Refs #2347
This commit is contained in:
Anton Kaliaev
2018-09-12 23:44:43 +04:00
committed by Ethan Buchman
parent 33b4617e9a
commit 0e1cd88863
18 changed files with 584 additions and 913 deletions

View File

@ -9,10 +9,10 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
)
func newConsensusParams(txsBytes, partSize int) ConsensusParams {
func newConsensusParams(txsBytes, evidenceAge int) ConsensusParams {
return ConsensusParams{
BlockSize: BlockSize{MaxBytes: txsBytes},
BlockGossip: BlockGossip{BlockPartSizeBytes: partSize},
BlockSize: BlockSize{MaxBytes: txsBytes},
EvidenceParams: EvidenceParams{MaxAge: int64(evidenceAge)},
}
}
@ -21,50 +21,45 @@ func TestConsensusParamsValidation(t *testing.T) {
params ConsensusParams
valid bool
}{
{newConsensusParams(1, 1), true},
{newConsensusParams(1, 0), false},
{newConsensusParams(0, 1), false},
{newConsensusParams(0, 0), false},
{newConsensusParams(0, 10), false},
{newConsensusParams(10, -1), false},
{newConsensusParams(47*1024*1024, 400), true},
{newConsensusParams(10, 400), true},
{newConsensusParams(100*1024*1024, 400), true},
{newConsensusParams(101*1024*1024, 400), false},
{newConsensusParams(1024*1024*1024, 400), false},
// test block size
0: {newConsensusParams(1, 1), true},
1: {newConsensusParams(0, 1), false},
2: {newConsensusParams(47*1024*1024, 1), true},
3: {newConsensusParams(10, 1), true},
4: {newConsensusParams(100*1024*1024, 1), true},
5: {newConsensusParams(101*1024*1024, 1), false},
6: {newConsensusParams(1024*1024*1024, 1), false},
7: {newConsensusParams(1024*1024*1024, -1), false},
// test evidence age
8: {newConsensusParams(1, 0), false},
9: {newConsensusParams(1, -1), false},
}
for _, tc := range testCases {
for i, tc := range testCases {
if tc.valid {
assert.NoError(t, tc.params.Validate(), "expected no error for valid params")
assert.NoErrorf(t, tc.params.Validate(), "expected no error for valid params (#%d)", i)
} else {
assert.Error(t, tc.params.Validate(), "expected error for non valid params")
assert.Errorf(t, tc.params.Validate(), "expected error for non valid params (#%d)", i)
}
}
}
func makeParams(txsBytes, blockGas, txBytes, txGas, partSize int) ConsensusParams {
func makeParams(txsBytes, blockGas, evidenceAge int) ConsensusParams {
return ConsensusParams{
BlockSize: BlockSize{
MaxBytes: txsBytes,
MaxGas: int64(blockGas),
},
TxSize: TxSize{
MaxBytes: txBytes,
MaxGas: int64(txGas),
},
BlockGossip: BlockGossip{
BlockPartSizeBytes: partSize,
EvidenceParams: EvidenceParams{
MaxAge: int64(evidenceAge),
},
}
}
func TestConsensusParamsHash(t *testing.T) {
params := []ConsensusParams{
makeParams(6, 2, 3, 4, 5),
makeParams(1, 6, 3, 4, 5),
makeParams(1, 2, 6, 4, 5),
makeParams(1, 2, 3, 6, 5),
makeParams(1, 2, 3, 4, 6),
makeParams(4, 2, 3),
makeParams(1, 4, 3),
makeParams(1, 2, 4),
}
hashes := make([][]byte, len(params))
@ -90,45 +85,23 @@ func TestConsensusParamsUpdate(t *testing.T) {
}{
// empty updates
{
makeParams(1, 2, 3, 4, 5),
makeParams(1, 2, 3),
&abci.ConsensusParams{},
makeParams(1, 2, 3, 4, 5),
},
// negative BlockPartSizeBytes
{
makeParams(1, 2, 3, 4, 5),
&abci.ConsensusParams{
BlockSize: &abci.BlockSize{
MaxBytes: -100,
MaxGas: -200,
},
TxSize: &abci.TxSize{
MaxBytes: -400,
MaxGas: -500,
},
BlockGossip: &abci.BlockGossip{
BlockPartSizeBytes: -600,
},
},
makeParams(1, 2, 3, 4, 5),
makeParams(1, 2, 3),
},
// fine updates
{
makeParams(1, 2, 3, 4, 5),
makeParams(1, 2, 3),
&abci.ConsensusParams{
BlockSize: &abci.BlockSize{
MaxBytes: 100,
MaxGas: 200,
},
TxSize: &abci.TxSize{
MaxBytes: 300,
MaxGas: 400,
},
BlockGossip: &abci.BlockGossip{
BlockPartSizeBytes: 500,
EvidenceParams: &abci.EvidenceParams{
MaxAge: 300,
},
},
makeParams(100, 200, 300, 400, 500),
makeParams(100, 200, 300),
},
}
for _, tc := range testCases {