params: remove blockTimeIota (#5987)

## Description

- removes blocktimeiota 
- merges block params in abci and core state
- spec change: https://github.com/tendermint/spec/pull/248


Closes: #5939
This commit is contained in:
Marko
2021-01-28 13:47:24 +00:00
committed by GitHub
parent c900303ac6
commit 1f01e5d726
30 changed files with 434 additions and 1163 deletions
+19 -24
View File
@@ -5,8 +5,8 @@ import (
"fmt"
"time"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/tmhash"
tmstrings "github.com/tendermint/tendermint/libs/strings"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)
@@ -43,9 +43,6 @@ type HashedParams struct {
type BlockParams struct {
MaxBytes int64 `json:"max_bytes"`
MaxGas int64 `json:"max_gas"`
// Minimum time increment between consecutive blocks (in milliseconds)
// Not exposed to the application.
TimeIotaMs int64 `json:"time_iota_ms"`
}
// EvidenceParams determine how we handle evidence of malfeasance.
@@ -78,9 +75,8 @@ func DefaultConsensusParams() *ConsensusParams {
// DefaultBlockParams returns a default BlockParams.
func DefaultBlockParams() BlockParams {
return BlockParams{
MaxBytes: 22020096, // 21MB
MaxGas: -1,
TimeIotaMs: 1, // 1s, parameter is now unused
MaxBytes: 22020096, // 21MB
MaxGas: -1,
}
}
@@ -133,11 +129,6 @@ func (params ConsensusParams) ValidateConsensusParams() error {
params.Block.MaxGas)
}
if params.Block.TimeIotaMs <= 0 {
return fmt.Errorf("block.TimeIotaMs must be greater than 0. Got %v",
params.Block.TimeIotaMs)
}
if params.Evidence.MaxAgeNumBlocks <= 0 {
return fmt.Errorf("evidence.MaxAgeNumBlocks must be greater than 0. Got %d",
params.Evidence.MaxAgeNumBlocks)
@@ -198,9 +189,15 @@ func (params ConsensusParams) HashConsensusParams() []byte {
return hasher.Sum(nil)
}
func (params *ConsensusParams) Equals(params2 *ConsensusParams) bool {
return params.Block == params2.Block &&
params.Evidence == params2.Evidence &&
tmstrings.StringSliceEqual(params.Validator.PubKeyTypes, params2.Validator.PubKeyTypes)
}
// Update returns a copy of the params with updates from the non-zero fields of p2.
// NOTE: note: must not modify the original
func (params ConsensusParams) UpdateConsensusParams(params2 *abci.ConsensusParams) ConsensusParams {
func (params ConsensusParams) UpdateConsensusParams(params2 *tmproto.ConsensusParams) ConsensusParams {
res := params // explicit copy
if params2 == nil {
@@ -228,22 +225,21 @@ func (params ConsensusParams) UpdateConsensusParams(params2 *abci.ConsensusParam
return res
}
func (params ConsensusParams) ToProto() tmproto.ConsensusParams {
func (params *ConsensusParams) ToProto() tmproto.ConsensusParams {
return tmproto.ConsensusParams{
Block: tmproto.BlockParams{
MaxBytes: params.Block.MaxBytes,
MaxGas: params.Block.MaxGas,
TimeIotaMs: params.Block.TimeIotaMs,
Block: &tmproto.BlockParams{
MaxBytes: params.Block.MaxBytes,
MaxGas: params.Block.MaxGas,
},
Evidence: tmproto.EvidenceParams{
Evidence: &tmproto.EvidenceParams{
MaxAgeNumBlocks: params.Evidence.MaxAgeNumBlocks,
MaxAgeDuration: params.Evidence.MaxAgeDuration,
MaxBytes: params.Evidence.MaxBytes,
},
Validator: tmproto.ValidatorParams{
Validator: &tmproto.ValidatorParams{
PubKeyTypes: params.Validator.PubKeyTypes,
},
Version: tmproto.VersionParams{
Version: &tmproto.VersionParams{
AppVersion: params.Version.AppVersion,
},
}
@@ -252,9 +248,8 @@ func (params ConsensusParams) ToProto() tmproto.ConsensusParams {
func ConsensusParamsFromProto(pbParams tmproto.ConsensusParams) ConsensusParams {
return ConsensusParams{
Block: BlockParams{
MaxBytes: pbParams.Block.MaxBytes,
MaxGas: pbParams.Block.MaxGas,
TimeIotaMs: pbParams.Block.TimeIotaMs,
MaxBytes: pbParams.Block.MaxBytes,
MaxGas: pbParams.Block.MaxGas,
},
Evidence: EvidenceParams{
MaxAgeNumBlocks: pbParams.Evidence.MaxAgeNumBlocks,
+42 -46
View File
@@ -8,7 +8,6 @@ import (
"github.com/stretchr/testify/assert"
abci "github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)
@@ -23,24 +22,23 @@ func TestConsensusParamsValidation(t *testing.T) {
valid bool
}{
// test block params
0: {makeParams(1, 0, 10, 2, 0, valEd25519), true},
1: {makeParams(0, 0, 10, 2, 0, valEd25519), false},
2: {makeParams(47*1024*1024, 0, 10, 2, 0, valEd25519), true},
3: {makeParams(10, 0, 10, 2, 0, valEd25519), true},
4: {makeParams(100*1024*1024, 0, 10, 2, 0, valEd25519), true},
5: {makeParams(101*1024*1024, 0, 10, 2, 0, valEd25519), false},
6: {makeParams(1024*1024*1024, 0, 10, 2, 0, valEd25519), false},
7: {makeParams(1024*1024*1024, 0, 10, -1, 0, valEd25519), false},
8: {makeParams(1, 0, -10, 2, 0, valEd25519), false},
0: {makeParams(1, 0, 2, 0, valEd25519), true},
1: {makeParams(0, 0, 2, 0, valEd25519), false},
2: {makeParams(47*1024*1024, 0, 2, 0, valEd25519), true},
3: {makeParams(10, 0, 2, 0, valEd25519), true},
4: {makeParams(100*1024*1024, 0, 2, 0, valEd25519), true},
5: {makeParams(101*1024*1024, 0, 2, 0, valEd25519), false},
6: {makeParams(1024*1024*1024, 0, 2, 0, valEd25519), false},
7: {makeParams(1024*1024*1024, 0, -1, 0, valEd25519), false},
// test evidence params
9: {makeParams(1, 0, 10, 0, 0, valEd25519), false},
10: {makeParams(1, 0, 10, 2, 2, valEd25519), false},
11: {makeParams(1000, 0, 10, 2, 1, valEd25519), true},
12: {makeParams(1, 0, 10, -1, 0, valEd25519), false},
8: {makeParams(1, 0, 0, 0, valEd25519), false},
9: {makeParams(1, 0, 2, 2, valEd25519), false},
10: {makeParams(1000, 0, 2, 1, valEd25519), true},
11: {makeParams(1, 0, -1, 0, valEd25519), false},
// test no pubkey type provided
13: {makeParams(1, 0, 10, 2, 0, []string{}), false},
12: {makeParams(1, 0, 2, 0, []string{}), false},
// test invalid pubkey type provided
14: {makeParams(1, 0, 10, 2, 0, []string{"potatoes make good pubkeys"}), false},
13: {makeParams(1, 0, 2, 0, []string{"potatoes make good pubkeys"}), false},
}
for i, tc := range testCases {
if tc.valid {
@@ -53,16 +51,14 @@ func TestConsensusParamsValidation(t *testing.T) {
func makeParams(
blockBytes, blockGas int64,
blockTimeIotaMs int64,
evidenceAge int64,
maxEvidenceBytes int64,
pubkeyTypes []string,
) ConsensusParams {
return ConsensusParams{
Block: BlockParams{
MaxBytes: blockBytes,
MaxGas: blockGas,
TimeIotaMs: blockTimeIotaMs,
MaxBytes: blockBytes,
MaxGas: blockGas,
},
Evidence: EvidenceParams{
MaxAgeNumBlocks: evidenceAge,
@@ -77,14 +73,14 @@ func makeParams(
func TestConsensusParamsHash(t *testing.T) {
params := []ConsensusParams{
makeParams(4, 2, 10, 3, 1, valEd25519),
makeParams(1, 4, 10, 3, 1, valEd25519),
makeParams(1, 2, 10, 4, 1, valEd25519),
makeParams(2, 5, 10, 7, 1, valEd25519),
makeParams(1, 7, 10, 6, 1, valEd25519),
makeParams(9, 5, 10, 4, 1, valEd25519),
makeParams(7, 8, 10, 9, 1, valEd25519),
makeParams(4, 6, 10, 5, 1, valEd25519),
makeParams(4, 2, 3, 1, valEd25519),
makeParams(1, 4, 3, 1, valEd25519),
makeParams(1, 2, 4, 1, valEd25519),
makeParams(2, 5, 7, 1, valEd25519),
makeParams(1, 7, 6, 1, valEd25519),
makeParams(9, 5, 4, 1, valEd25519),
makeParams(7, 8, 9, 1, valEd25519),
makeParams(4, 6, 5, 1, valEd25519),
}
hashes := make([][]byte, len(params))
@@ -105,20 +101,20 @@ func TestConsensusParamsHash(t *testing.T) {
func TestConsensusParamsUpdate(t *testing.T) {
testCases := []struct {
params ConsensusParams
updates *abci.ConsensusParams
updates *tmproto.ConsensusParams
updatedParams ConsensusParams
}{
// empty updates
{
makeParams(1, 2, 10, 3, 0, valEd25519),
&abci.ConsensusParams{},
makeParams(1, 2, 10, 3, 0, valEd25519),
makeParams(1, 2, 3, 0, valEd25519),
&tmproto.ConsensusParams{},
makeParams(1, 2, 3, 0, valEd25519),
},
// fine updates
{
makeParams(1, 2, 10, 3, 0, valEd25519),
&abci.ConsensusParams{
Block: &abci.BlockParams{
makeParams(1, 2, 3, 0, valEd25519),
&tmproto.ConsensusParams{
Block: &tmproto.BlockParams{
MaxBytes: 100,
MaxGas: 200,
},
@@ -131,7 +127,7 @@ func TestConsensusParamsUpdate(t *testing.T) {
PubKeyTypes: valSecp256k1,
},
},
makeParams(100, 200, 10, 300, 50, valSecp256k1),
makeParams(100, 200, 300, 50, valSecp256k1),
},
}
for _, tc := range testCases {
@@ -140,26 +136,26 @@ func TestConsensusParamsUpdate(t *testing.T) {
}
func TestConsensusParamsUpdate_AppVersion(t *testing.T) {
params := makeParams(1, 2, 10, 3, 0, valEd25519)
params := makeParams(1, 2, 3, 0, valEd25519)
assert.EqualValues(t, 0, params.Version.AppVersion)
updated := params.UpdateConsensusParams(
&abci.ConsensusParams{Version: &tmproto.VersionParams{AppVersion: 1}})
&tmproto.ConsensusParams{Version: &tmproto.VersionParams{AppVersion: 1}})
assert.EqualValues(t, 1, updated.Version.AppVersion)
}
func TestProto(t *testing.T) {
params := []ConsensusParams{
makeParams(4, 2, 10, 3, 1, valEd25519),
makeParams(1, 4, 10, 3, 1, valEd25519),
makeParams(1, 2, 10, 4, 1, valEd25519),
makeParams(2, 5, 10, 7, 1, valEd25519),
makeParams(1, 7, 10, 6, 1, valEd25519),
makeParams(9, 5, 10, 4, 1, valEd25519),
makeParams(7, 8, 10, 9, 1, valEd25519),
makeParams(4, 6, 10, 5, 1, valEd25519),
makeParams(4, 2, 3, 1, valEd25519),
makeParams(1, 4, 3, 1, valEd25519),
makeParams(1, 2, 4, 1, valEd25519),
makeParams(2, 5, 7, 1, valEd25519),
makeParams(1, 7, 6, 1, valEd25519),
makeParams(9, 5, 4, 1, valEd25519),
makeParams(7, 8, 9, 1, valEd25519),
makeParams(4, 6, 5, 1, valEd25519),
}
for i := range params {
-20
View File
@@ -97,26 +97,6 @@ func (tm2pb) ValidatorUpdates(vals *ValidatorSet) []abci.ValidatorUpdate {
return validators
}
func (tm2pb) ConsensusParams(params *ConsensusParams) *abci.ConsensusParams {
return &abci.ConsensusParams{
Block: &abci.BlockParams{
MaxBytes: params.Block.MaxBytes,
MaxGas: params.Block.MaxGas,
},
Evidence: &tmproto.EvidenceParams{
MaxAgeNumBlocks: params.Evidence.MaxAgeNumBlocks,
MaxAgeDuration: params.Evidence.MaxAgeDuration,
MaxBytes: params.Evidence.MaxBytes,
},
Validator: &tmproto.ValidatorParams{
PubKeyTypes: params.Validator.PubKeyTypes,
},
Version: &tmproto.VersionParams{
AppVersion: params.Version.AppVersion,
},
}
}
// XXX: panics on nil or unknown pubkey type
func (tm2pb) NewValidatorUpdate(pubkey crypto.PubKey, power int64) abci.ValidatorUpdate {
pubkeyABCI, err := cryptoenc.PubKeyToProto(pubkey)
-8
View File
@@ -52,14 +52,6 @@ func TestABCIValidators(t *testing.T) {
assert.Equal(t, tmValExpected, tmVals[0])
}
func TestABCIConsensusParams(t *testing.T) {
cp := DefaultConsensusParams()
abciCP := TM2PB.ConsensusParams(cp)
cp2 := cp.UpdateConsensusParams(abciCP)
assert.Equal(t, *cp, cp2)
}
type pubKeyEddie struct{}
func (pubKeyEddie) Address() Address { return []byte{} }