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
+3 -2
View File
@@ -204,9 +204,10 @@ func makeHeaderPartsResponsesParams(
) (types.Header, types.BlockID, *tmstate.ABCIResponses) {
block := makeBlock(state, state.LastBlockHeight+1)
pbParams := params.ToProto()
abciResponses := &tmstate.ABCIResponses{
BeginBlock: &abci.ResponseBeginBlock{},
EndBlock: &abci.ResponseEndBlock{ConsensusParamUpdates: types.TM2PB.ConsensusParams(params)},
EndBlock: &abci.ResponseEndBlock{ConsensusParamUpdates: &pbParams},
}
return block.Header, types.BlockID{Hash: block.Hash(), PartSetHeader: types.PartSetHeader{}}, abciResponses
}
@@ -286,7 +287,7 @@ func (app *testApp) BeginBlock(req abci.RequestBeginBlock) abci.ResponseBeginBlo
func (app *testApp) EndBlock(req abci.RequestEndBlock) abci.ResponseEndBlock {
return abci.ResponseEndBlock{
ValidatorUpdates: app.ValidatorUpdates,
ConsensusParamUpdates: &abci.ConsensusParams{
ConsensusParamUpdates: &tmproto.ConsensusParams{
Version: &tmproto.VersionParams{
AppVersion: 1}}}
}
+1 -1
View File
@@ -1,4 +1,4 @@
// Code generated by mockery v1.0.0. DO NOT EDIT.
// Code generated by mockery v2.5.1. DO NOT EDIT.
package mocks
+9 -11
View File
@@ -1,4 +1,4 @@
// Code generated by mockery v1.0.0. DO NOT EDIT.
// Code generated by mockery v2.5.1. DO NOT EDIT.
package mocks
@@ -8,9 +8,7 @@ import (
tendermintstate "github.com/tendermint/tendermint/proto/tendermint/state"
tenderminttypes "github.com/tendermint/tendermint/types"
types "github.com/tendermint/tendermint/proto/tendermint/types"
types "github.com/tendermint/tendermint/types"
)
// Store is an autogenerated mock type for the Store type
@@ -98,18 +96,18 @@ func (_m *Store) LoadConsensusParams(_a0 int64) (types.ConsensusParams, error) {
}
// LoadFromDBOrGenesisDoc provides a mock function with given fields: _a0
func (_m *Store) LoadFromDBOrGenesisDoc(_a0 *tenderminttypes.GenesisDoc) (state.State, error) {
func (_m *Store) LoadFromDBOrGenesisDoc(_a0 *types.GenesisDoc) (state.State, error) {
ret := _m.Called(_a0)
var r0 state.State
if rf, ok := ret.Get(0).(func(*tenderminttypes.GenesisDoc) state.State); ok {
if rf, ok := ret.Get(0).(func(*types.GenesisDoc) state.State); ok {
r0 = rf(_a0)
} else {
r0 = ret.Get(0).(state.State)
}
var r1 error
if rf, ok := ret.Get(1).(func(*tenderminttypes.GenesisDoc) error); ok {
if rf, ok := ret.Get(1).(func(*types.GenesisDoc) error); ok {
r1 = rf(_a0)
} else {
r1 = ret.Error(1)
@@ -140,15 +138,15 @@ func (_m *Store) LoadFromDBOrGenesisFile(_a0 string) (state.State, error) {
}
// LoadValidators provides a mock function with given fields: _a0
func (_m *Store) LoadValidators(_a0 int64) (*tenderminttypes.ValidatorSet, error) {
func (_m *Store) LoadValidators(_a0 int64) (*types.ValidatorSet, error) {
ret := _m.Called(_a0)
var r0 *tenderminttypes.ValidatorSet
if rf, ok := ret.Get(0).(func(int64) *tenderminttypes.ValidatorSet); ok {
var r0 *types.ValidatorSet
if rf, ok := ret.Get(0).(func(int64) *types.ValidatorSet); ok {
r0 = rf(_a0)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*tenderminttypes.ValidatorSet)
r0 = ret.Get(0).(*types.ValidatorSet)
}
}
+1 -1
View File
@@ -1002,7 +1002,6 @@ func TestConsensusParamsChangesSaveLoad(t *testing.T) {
for i := 1; i < N+1; i++ {
params[i] = *types.DefaultConsensusParams()
params[i].Block.MaxBytes += int64(i)
params[i].Block.TimeIotaMs = 10
}
// Build the params history by running updateState
@@ -1044,6 +1043,7 @@ func TestConsensusParamsChangesSaveLoad(t *testing.T) {
for _, testCase := range testCases {
p, err := stateStore.LoadConsensusParams(testCase.height)
assert.Nil(t, err, fmt.Sprintf("expected no err at height %d", testCase.height))
assert.EqualValues(t, testCase.params, p, fmt.Sprintf(`unexpected consensus params at
height %d`, testCase.height))
+10 -6
View File
@@ -76,7 +76,7 @@ type Store interface {
// LoadABCIResponses loads the abciResponse for a given height
LoadABCIResponses(int64) (*tmstate.ABCIResponses, error)
// LoadConsensusParams loads the consensus params for a given height
LoadConsensusParams(int64) (tmproto.ConsensusParams, error)
LoadConsensusParams(int64) (types.ConsensusParams, error)
// Save overwrites the previous state with the updated one
Save(State) error
// SaveABCIResponses saves ABCIResponses for a given height
@@ -567,16 +567,20 @@ func (store dbStore) saveValidatorsInfo(height, lastHeightChanged int64, valSet
// ConsensusParamsInfo represents the latest consensus params, or the last height it changed
// LoadConsensusParams loads the ConsensusParams for a given height.
func (store dbStore) LoadConsensusParams(height int64) (tmproto.ConsensusParams, error) {
empty := tmproto.ConsensusParams{}
// Allocate empty Consensus params at compile time to avoid multiple allocations during runtime
var (
empty = types.ConsensusParams{}
emptypb = tmproto.ConsensusParams{}
)
// LoadConsensusParams loads the ConsensusParams for a given height.
func (store dbStore) LoadConsensusParams(height int64) (types.ConsensusParams, error) {
paramsInfo, err := store.loadConsensusParamsInfo(height)
if err != nil {
return empty, fmt.Errorf("could not find consensus params for height #%d: %w", height, err)
}
if paramsInfo.ConsensusParams.Equal(&empty) {
if paramsInfo.ConsensusParams.Equal(&emptypb) {
paramsInfo2, err := store.loadConsensusParamsInfo(paramsInfo.LastHeightChanged)
if err != nil {
return empty, fmt.Errorf(
@@ -590,7 +594,7 @@ func (store dbStore) LoadConsensusParams(height int64) (tmproto.ConsensusParams,
paramsInfo = paramsInfo2
}
return paramsInfo.ConsensusParams, nil
return types.ConsensusParamsFromProto(paramsInfo.ConsensusParams), nil
}
func (store dbStore) loadConsensusParamsInfo(height int64) (*tmstate.ConsensusParamsInfo, error) {
+3 -6
View File
@@ -16,7 +16,6 @@ import (
"github.com/tendermint/tendermint/crypto/ed25519"
tmrand "github.com/tendermint/tendermint/libs/rand"
tmstate "github.com/tendermint/tendermint/proto/tendermint/state"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types"
)
@@ -142,9 +141,8 @@ func TestStoreLoadConsensusParams(t *testing.T) {
stateStore := sm.NewStore(stateDB)
err := stateStore.Save(makeRandomStateFromConsensusParams(types.DefaultConsensusParams(), 1, 1))
require.NoError(t, err)
pbParams, err := stateStore.LoadConsensusParams(1)
params, err := stateStore.LoadConsensusParams(1)
require.NoError(t, err)
params := types.ConsensusParamsFromProto(pbParams)
require.Equal(t, types.DefaultConsensusParams(), &params)
// we give the state store different params but say that the height hasn't changed, hence
@@ -153,8 +151,7 @@ func TestStoreLoadConsensusParams(t *testing.T) {
differentParams.Block.MaxBytes = 20000
err = stateStore.Save(makeRandomStateFromConsensusParams(differentParams, 10, 1))
require.NoError(t, err)
pbRes, err := stateStore.LoadConsensusParams(10)
res := types.ConsensusParamsFromProto(pbRes)
res, err := stateStore.LoadConsensusParams(10)
require.NoError(t, err)
require.Equal(t, res, params)
require.NotEqual(t, res, differentParams)
@@ -257,7 +254,7 @@ func TestPruneStates(t *testing.T) {
params, err := stateStore.LoadConsensusParams(h)
if expectParams[h] {
require.NoError(t, err, "params height %v", h)
require.False(t, params.Equal(&tmproto.ConsensusParams{}), "params should not be empty")
require.False(t, params.Equals(&types.ConsensusParams{}), "params should not be empty")
} else {
require.Error(t, err, "params height %v", h)
}