mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-21 06:36:19 +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
@@ -30,6 +30,7 @@ func DefaultConsensusParams() *tmproto.ConsensusParams {
|
||||
Block: DefaultBlockParams(),
|
||||
Evidence: DefaultEvidenceParams(),
|
||||
Validator: DefaultValidatorParams(),
|
||||
Version: DefaultVersionParams(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +61,12 @@ func DefaultValidatorParams() tmproto.ValidatorParams {
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultVersionParams() tmproto.VersionParams {
|
||||
return tmproto.VersionParams{
|
||||
AppVersion: 0,
|
||||
}
|
||||
}
|
||||
|
||||
func IsValidPubkeyType(params tmproto.ValidatorParams, pubkeyType string) bool {
|
||||
for i := 0; i < len(params.PubKeyTypes); i++ {
|
||||
if params.PubKeyTypes[i] == pubkeyType {
|
||||
@@ -182,5 +189,8 @@ func UpdateConsensusParams(params tmproto.ConsensusParams, params2 *abci.Consens
|
||||
// This avoids having to initialize the slice to 0 values, and then write to it again.
|
||||
res.Validator.PubKeyTypes = append([]string{}, params2.Validator.PubKeyTypes...)
|
||||
}
|
||||
if params2.Version != nil {
|
||||
res.Version.AppVersion = params2.Version.AppVersion
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -138,3 +138,14 @@ func TestConsensusParamsUpdate(t *testing.T) {
|
||||
assert.Equal(t, tc.updatedParams, UpdateConsensusParams(tc.params, tc.updates))
|
||||
}
|
||||
}
|
||||
|
||||
func TestConsensusParamsUpdate_AppVersion(t *testing.T) {
|
||||
params := makeParams(1, 2, 10, 3, 0, valEd25519)
|
||||
|
||||
assert.EqualValues(t, 0, params.Version.AppVersion)
|
||||
|
||||
updated := UpdateConsensusParams(params,
|
||||
&abci.ConsensusParams{Version: &tmproto.VersionParams{AppVersion: 1}})
|
||||
|
||||
assert.EqualValues(t, 1, updated.Version.AppVersion)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user