mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-19 06:31:57 +00:00
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:
committed by
Ethan Buchman
parent
33b4617e9a
commit
0e1cd88863
@@ -204,6 +204,28 @@ func (b *Block) StringShort() string {
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// MaxDataBytes returns the maximum size of block's data.
|
||||
func MaxDataBytes(maxBytes, valsCount, evidenceCount int) int {
|
||||
return maxBytes -
|
||||
MaxAminoOverheadForBlock -
|
||||
MaxHeaderBytes -
|
||||
(valsCount * MaxVoteBytes) -
|
||||
(evidenceCount * MaxEvidenceBytes)
|
||||
}
|
||||
|
||||
// MaxDataBytesUnknownEvidence returns the maximum size of block's data when
|
||||
// evidence count is unknown. MaxEvidenceBytesPerBlock will be used as the size
|
||||
// of evidence.
|
||||
func MaxDataBytesUnknownEvidence(maxBytes, valsCount int) int {
|
||||
return maxBytes -
|
||||
MaxAminoOverheadForBlock -
|
||||
MaxHeaderBytes -
|
||||
(valsCount * MaxVoteBytes) -
|
||||
MaxEvidenceBytesPerBlock(maxBytes)
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Header defines the structure of a Tendermint block header
|
||||
// TODO: limit header size
|
||||
// NOTE: changes to the Header should be duplicated in the abci Header
|
||||
|
||||
@@ -52,6 +52,11 @@ func RegisterEvidences(cdc *amino.Codec) {
|
||||
cdc.RegisterConcrete(MockBadEvidence{}, "tendermint/MockBadEvidence", nil)
|
||||
}
|
||||
|
||||
// MaxEvidenceBytesPerBlock returns the maximum evidence size per block.
|
||||
func MaxEvidenceBytesPerBlock(blockMaxBytes int) int {
|
||||
return blockMaxBytes / 10
|
||||
}
|
||||
|
||||
//-------------------------------------------
|
||||
|
||||
// DuplicateVoteEvidence contains evidence a validator signed two conflicting votes.
|
||||
|
||||
+31
-69
@@ -9,34 +9,24 @@ import (
|
||||
const (
|
||||
// MaxBlockSizeBytes is the maximum permitted size of the blocks.
|
||||
MaxBlockSizeBytes = 104857600 // 100MB
|
||||
|
||||
// BlockPartSizeBytes is the size of one block part.
|
||||
BlockPartSizeBytes = 65536 // 64kB
|
||||
)
|
||||
|
||||
// ConsensusParams contains consensus critical parameters
|
||||
// that determine the validity of blocks.
|
||||
// ConsensusParams contains consensus critical parameters that determine the
|
||||
// validity of blocks.
|
||||
type ConsensusParams struct {
|
||||
BlockSize `json:"block_size_params"`
|
||||
TxSize `json:"tx_size_params"`
|
||||
BlockGossip `json:"block_gossip_params"`
|
||||
EvidenceParams `json:"evidence_params"`
|
||||
}
|
||||
|
||||
// BlockSize contain limits on the block size.
|
||||
type BlockSize struct {
|
||||
MaxBytes int `json:"max_txs_bytes"` // NOTE: must not be 0 nor greater than 100MB
|
||||
MaxGas int64 `json:"max_gas"`
|
||||
}
|
||||
|
||||
// TxSize contain limits on the tx size.
|
||||
type TxSize struct {
|
||||
MaxBytes int `json:"max_bytes"`
|
||||
MaxBytes int `json:"max_txs_bytes"`
|
||||
MaxGas int64 `json:"max_gas"`
|
||||
}
|
||||
|
||||
// BlockGossip determine consensus critical elements of how blocks are gossiped
|
||||
type BlockGossip struct {
|
||||
BlockPartSizeBytes int `json:"block_part_size_bytes"` // NOTE: must not be 0
|
||||
}
|
||||
|
||||
// EvidenceParams determine how we handle evidence of malfeasance
|
||||
type EvidenceParams struct {
|
||||
MaxAge int64 `json:"max_age"` // only accept new evidence more recent than this
|
||||
@@ -46,8 +36,6 @@ type EvidenceParams struct {
|
||||
func DefaultConsensusParams() *ConsensusParams {
|
||||
return &ConsensusParams{
|
||||
DefaultBlockSize(),
|
||||
DefaultTxSize(),
|
||||
DefaultBlockGossip(),
|
||||
DefaultEvidenceParams(),
|
||||
}
|
||||
}
|
||||
@@ -55,61 +43,49 @@ func DefaultConsensusParams() *ConsensusParams {
|
||||
// DefaultBlockSize returns a default BlockSize.
|
||||
func DefaultBlockSize() BlockSize {
|
||||
return BlockSize{
|
||||
MaxBytes: 22020096, // 21MB
|
||||
MaxGas: -1,
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultTxSize returns a default TxSize.
|
||||
func DefaultTxSize() TxSize {
|
||||
return TxSize{
|
||||
MaxBytes: 10240, // 10kB
|
||||
MaxBytes: 22020096, // 21MB
|
||||
MaxGas: -1,
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultBlockGossip returns a default BlockGossip.
|
||||
func DefaultBlockGossip() BlockGossip {
|
||||
return BlockGossip{
|
||||
BlockPartSizeBytes: 65536, // 64kB,
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultEvidence Params returns a default EvidenceParams.
|
||||
// DefaultEvidenceParams Params returns a default EvidenceParams.
|
||||
func DefaultEvidenceParams() EvidenceParams {
|
||||
return EvidenceParams{
|
||||
MaxAge: 100000, // 27.8 hrs at 1block/s
|
||||
}
|
||||
}
|
||||
|
||||
// Validate validates the ConsensusParams to ensure all values
|
||||
// are within their allowed limits, and returns an error if they are not.
|
||||
// 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 {
|
||||
// ensure some values are greater than 0
|
||||
if params.BlockSize.MaxBytes <= 0 {
|
||||
return cmn.NewError("BlockSize.MaxBytes must be greater than 0. Got %d", params.BlockSize.MaxBytes)
|
||||
return cmn.NewError("BlockSize.MaxBytes must be greater than 0. Got %d",
|
||||
params.BlockSize.MaxBytes)
|
||||
}
|
||||
if params.BlockGossip.BlockPartSizeBytes <= 0 {
|
||||
return cmn.NewError("BlockGossip.BlockPartSizeBytes must be greater than 0. Got %d", params.BlockGossip.BlockPartSizeBytes)
|
||||
}
|
||||
|
||||
// ensure blocks aren't too big
|
||||
if params.BlockSize.MaxBytes > MaxBlockSizeBytes {
|
||||
return cmn.NewError("BlockSize.MaxBytes is too big. %d > %d",
|
||||
params.BlockSize.MaxBytes, MaxBlockSizeBytes)
|
||||
}
|
||||
|
||||
if params.BlockSize.MaxGas < -1 {
|
||||
return cmn.NewError("BlockSize.MaxGas must be greater or equal to -1. Got %d",
|
||||
params.BlockSize.MaxGas)
|
||||
}
|
||||
|
||||
if params.EvidenceParams.MaxAge <= 0 {
|
||||
return cmn.NewError("EvidenceParams.MaxAge must be greater than 0. Got %d",
|
||||
params.EvidenceParams.MaxAge)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Hash returns a merkle hash of the parameters to store
|
||||
// in the block header
|
||||
// Hash returns a merkle hash of the parameters to store in the block header
|
||||
func (params *ConsensusParams) Hash() []byte {
|
||||
return merkle.SimpleHashFromMap(map[string]merkle.Hasher{
|
||||
"block_gossip_part_size_bytes": aminoHasher(params.BlockGossip.BlockPartSizeBytes),
|
||||
"block_size_max_bytes": aminoHasher(params.BlockSize.MaxBytes),
|
||||
"block_size_max_gas": aminoHasher(params.BlockSize.MaxGas),
|
||||
"tx_size_max_bytes": aminoHasher(params.TxSize.MaxBytes),
|
||||
"tx_size_max_gas": aminoHasher(params.TxSize.MaxGas),
|
||||
"block_size_max_bytes": aminoHasher(params.BlockSize.MaxBytes),
|
||||
"block_size_max_gas": aminoHasher(params.BlockSize.MaxGas),
|
||||
"evidence_params_max_age": aminoHasher(params.EvidenceParams.MaxAge),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -126,25 +102,11 @@ func (params ConsensusParams) Update(params2 *abci.ConsensusParams) ConsensusPar
|
||||
// XXX: it's cast city over here. It's ok because we only do int32->int
|
||||
// but still, watch it champ.
|
||||
if params2.BlockSize != nil {
|
||||
if params2.BlockSize.MaxBytes > 0 {
|
||||
res.BlockSize.MaxBytes = int(params2.BlockSize.MaxBytes)
|
||||
}
|
||||
if params2.BlockSize.MaxGas > 0 {
|
||||
res.BlockSize.MaxGas = params2.BlockSize.MaxGas
|
||||
}
|
||||
res.BlockSize.MaxBytes = int(params2.BlockSize.MaxBytes)
|
||||
res.BlockSize.MaxGas = params2.BlockSize.MaxGas
|
||||
}
|
||||
if params2.TxSize != nil {
|
||||
if params2.TxSize.MaxBytes > 0 {
|
||||
res.TxSize.MaxBytes = int(params2.TxSize.MaxBytes)
|
||||
}
|
||||
if params2.TxSize.MaxGas > 0 {
|
||||
res.TxSize.MaxGas = params2.TxSize.MaxGas
|
||||
}
|
||||
}
|
||||
if params2.BlockGossip != nil {
|
||||
if params2.BlockGossip.BlockPartSizeBytes > 0 {
|
||||
res.BlockGossip.BlockPartSizeBytes = int(params2.BlockGossip.BlockPartSizeBytes)
|
||||
}
|
||||
if params2.EvidenceParams != nil {
|
||||
res.EvidenceParams.MaxAge = params2.EvidenceParams.MaxAge
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
+30
-57
@@ -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 {
|
||||
|
||||
+8
-19
@@ -115,15 +115,11 @@ func (tm2pb) ValidatorUpdates(vals *ValidatorSet) []abci.ValidatorUpdate {
|
||||
func (tm2pb) ConsensusParams(params *ConsensusParams) *abci.ConsensusParams {
|
||||
return &abci.ConsensusParams{
|
||||
BlockSize: &abci.BlockSize{
|
||||
MaxBytes: int32(params.BlockSize.MaxBytes),
|
||||
MaxGas: params.BlockSize.MaxGas,
|
||||
MaxBytes: int32(params.BlockSize.MaxBytes),
|
||||
MaxGas: params.BlockSize.MaxGas,
|
||||
},
|
||||
TxSize: &abci.TxSize{
|
||||
MaxBytes: int32(params.TxSize.MaxBytes),
|
||||
MaxGas: params.TxSize.MaxGas,
|
||||
},
|
||||
BlockGossip: &abci.BlockGossip{
|
||||
BlockPartSizeBytes: int32(params.BlockGossip.BlockPartSizeBytes),
|
||||
EvidenceParams: &abci.EvidenceParams{
|
||||
MaxAge: params.EvidenceParams.MaxAge,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -215,18 +211,11 @@ func (pb2tm) ValidatorUpdates(vals []abci.ValidatorUpdate) ([]*Validator, error)
|
||||
func (pb2tm) ConsensusParams(csp *abci.ConsensusParams) ConsensusParams {
|
||||
return ConsensusParams{
|
||||
BlockSize: BlockSize{
|
||||
MaxBytes: int(csp.BlockSize.MaxBytes), // XXX
|
||||
MaxGas: csp.BlockSize.MaxGas,
|
||||
MaxBytes: int(csp.BlockSize.MaxBytes), // XXX
|
||||
MaxGas: csp.BlockSize.MaxGas,
|
||||
},
|
||||
TxSize: TxSize{
|
||||
MaxBytes: int(csp.TxSize.MaxBytes), // XXX
|
||||
MaxGas: csp.TxSize.MaxGas,
|
||||
EvidenceParams: EvidenceParams{
|
||||
MaxAge: csp.EvidenceParams.MaxAge, // XXX
|
||||
},
|
||||
BlockGossip: BlockGossip{
|
||||
BlockPartSizeBytes: int(csp.BlockGossip.BlockPartSizeBytes), // XXX
|
||||
},
|
||||
// TODO: EvidenceParams: EvidenceParams{
|
||||
// MaxAge: int(csp.Evidence.MaxAge), // XXX
|
||||
// },
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user