mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-20 06:54:41 +00:00
types: add AppVersion to ConsensusParams (#5031)
Co-authored-by: JamesRay <66258875@qq.com> making it possible to change app version via EndBlock
This commit is contained in:
co-authored by
JamesRay
parent
0b13059216
commit
ceac02b891
+3
-1
@@ -431,11 +431,13 @@ func updateState(
|
||||
if err != nil {
|
||||
return state, fmt.Errorf("error updating consensus params: %v", err)
|
||||
}
|
||||
|
||||
state.Version.Consensus.App = nextParams.Version.AppVersion
|
||||
|
||||
// Change results from this height but only applies to the next height.
|
||||
lastHeightParamsChanged = header.Height + 1
|
||||
}
|
||||
|
||||
// TODO: allow app to upgrade version
|
||||
nextVersion := state.Version
|
||||
|
||||
// NOTE: the AppHash has not been populated.
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/tendermint/tendermint/abci/example/kvstore"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
cryptoenc "github.com/tendermint/tendermint/crypto/encoding"
|
||||
@@ -28,8 +27,7 @@ var (
|
||||
)
|
||||
|
||||
func TestApplyBlock(t *testing.T) {
|
||||
app := kvstore.NewApplication()
|
||||
app.RetainBlocks = 1
|
||||
app := &testApp{}
|
||||
cc := proxy.NewLocalClientCreator(app)
|
||||
proxyApp := proxy.NewAppConns(cc)
|
||||
err := proxyApp.Start()
|
||||
@@ -44,11 +42,12 @@ func TestApplyBlock(t *testing.T) {
|
||||
block := makeBlock(state, 1)
|
||||
blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: block.MakePartSet(testPartSize).Header()}
|
||||
|
||||
_, retainHeight, err := blockExec.ApplyBlock(state, blockID, block)
|
||||
state, retainHeight, err := blockExec.ApplyBlock(state, blockID, block)
|
||||
require.Nil(t, err)
|
||||
assert.EqualValues(t, retainHeight, 1)
|
||||
|
||||
// TODO check state and mempool
|
||||
assert.EqualValues(t, 1, state.Version.Consensus.App, "App version wasn't updated")
|
||||
}
|
||||
|
||||
// TestBeginBlockValidators ensures we send absent validators list.
|
||||
@@ -402,5 +401,4 @@ func TestEndBlockValidatorUpdatesResultingInEmptySet(t *testing.T) {
|
||||
assert.NotPanics(t, func() { state, _, err = blockExec.ApplyBlock(state, blockID, block) })
|
||||
assert.NotNil(t, err)
|
||||
assert.NotEmpty(t, state.NextValidators.Validators)
|
||||
|
||||
}
|
||||
|
||||
+6
-22
@@ -145,26 +145,6 @@ func genValSet(size int) *types.ValidatorSet {
|
||||
return types.NewValidatorSet(vals)
|
||||
}
|
||||
|
||||
func makeConsensusParams(
|
||||
blockBytes, blockGas int64,
|
||||
blockTimeIotaMs int64,
|
||||
evidenceAge int64,
|
||||
maxNumEvidence uint32,
|
||||
) tmproto.ConsensusParams {
|
||||
return tmproto.ConsensusParams{
|
||||
Block: tmproto.BlockParams{
|
||||
MaxBytes: blockBytes,
|
||||
MaxGas: blockGas,
|
||||
TimeIotaMs: blockTimeIotaMs,
|
||||
},
|
||||
Evidence: tmproto.EvidenceParams{
|
||||
MaxAgeNumBlocks: evidenceAge,
|
||||
MaxAgeDuration: time.Duration(evidenceAge),
|
||||
MaxNum: maxNumEvidence,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func makeHeaderPartsResponsesValPubKeyChange(
|
||||
state sm.State,
|
||||
pubkey crypto.PubKey,
|
||||
@@ -266,7 +246,11 @@ func (app *testApp) BeginBlock(req abci.RequestBeginBlock) abci.ResponseBeginBlo
|
||||
}
|
||||
|
||||
func (app *testApp) EndBlock(req abci.RequestEndBlock) abci.ResponseEndBlock {
|
||||
return abci.ResponseEndBlock{ValidatorUpdates: app.ValidatorUpdates}
|
||||
return abci.ResponseEndBlock{
|
||||
ValidatorUpdates: app.ValidatorUpdates,
|
||||
ConsensusParamUpdates: &abci.ConsensusParams{
|
||||
Version: &tmproto.VersionParams{
|
||||
AppVersion: 1}}}
|
||||
}
|
||||
|
||||
func (app *testApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx {
|
||||
@@ -278,7 +262,7 @@ func (app *testApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx {
|
||||
}
|
||||
|
||||
func (app *testApp) Commit() abci.ResponseCommit {
|
||||
return abci.ResponseCommit{}
|
||||
return abci.ResponseCommit{RetainHeight: 1}
|
||||
}
|
||||
|
||||
func (app *testApp) Query(reqQuery abci.RequestQuery) (resQuery abci.ResponseQuery) {
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"math/big"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -1029,41 +1028,6 @@ func TestConsensusParamsChangesSaveLoad(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyUpdates(t *testing.T) {
|
||||
initParams := makeConsensusParams(1, 2, 3, 4, 5)
|
||||
const maxAge int64 = 66
|
||||
cases := [...]struct {
|
||||
init tmproto.ConsensusParams
|
||||
updates abci.ConsensusParams
|
||||
expected tmproto.ConsensusParams
|
||||
}{
|
||||
0: {initParams, abci.ConsensusParams{}, initParams},
|
||||
1: {initParams, abci.ConsensusParams{}, initParams},
|
||||
2: {initParams,
|
||||
abci.ConsensusParams{
|
||||
Block: &abci.BlockParams{
|
||||
MaxBytes: 44,
|
||||
MaxGas: 55,
|
||||
},
|
||||
},
|
||||
makeConsensusParams(44, 55, 3, 4, 5)},
|
||||
3: {initParams,
|
||||
abci.ConsensusParams{
|
||||
Evidence: &tmproto.EvidenceParams{
|
||||
MaxAgeNumBlocks: maxAge,
|
||||
MaxAgeDuration: time.Duration(maxAge),
|
||||
MaxNum: 10,
|
||||
},
|
||||
},
|
||||
makeConsensusParams(1, 2, 3, maxAge, 10)},
|
||||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
res := types.UpdateConsensusParams(tc.init, &(tc.updates))
|
||||
assert.Equal(t, tc.expected, res, "case %d", i)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStateProto(t *testing.T) {
|
||||
tearDown, _, state := setupTestCase(t)
|
||||
defer tearDown(t)
|
||||
|
||||
@@ -46,9 +46,9 @@ func TestValidateBlockHeader(t *testing.T) {
|
||||
// some bad values
|
||||
wrongHash := tmhash.Sum([]byte("this hash is wrong"))
|
||||
wrongVersion1 := state.Version.Consensus
|
||||
wrongVersion1.Block++
|
||||
wrongVersion1.Block += 2
|
||||
wrongVersion2 := state.Version.Consensus
|
||||
wrongVersion2.App++
|
||||
wrongVersion2.App += 2
|
||||
|
||||
// Manipulation of any header field causes failure.
|
||||
testCases := []struct {
|
||||
|
||||
Reference in New Issue
Block a user