From 9034100eaff23b10a5f94f531289918d38a4198f Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Wed, 13 Mar 2024 13:37:52 +0100 Subject: [PATCH] fix: allow the application to set the initial app version in the consensus params (#377) --- baseapp/baseapp.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 04274f31ecf2..a97a03773eea 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -493,6 +493,8 @@ func (app *BaseApp) GetConsensusParams(ctx sdk.Context) *abci.ConsensusParams { app.paramStore.Get(ctx, ParamStoreKeyVersionParams, &vp) cp.Version = &vp + } else if app.appVersion != 0 { + cp.Version = &tmproto.VersionParams{AppVersion: app.appVersion} } return cp @@ -518,12 +520,19 @@ func (app *BaseApp) StoreConsensusParams(ctx sdk.Context, cp *abci.ConsensusPara app.paramStore.Set(ctx, ParamStoreKeyBlockParams, cp.Block) app.paramStore.Set(ctx, ParamStoreKeyEvidenceParams, cp.Evidence) app.paramStore.Set(ctx, ParamStoreKeyValidatorParams, cp.Validator) - // NOTE: we only persist the app version from v2 onwards - if cp.Version != nil && cp.Version.AppVersion >= 2 { + if app.paramStore.Has(ctx, ParamStoreKeyVersionParams) { app.paramStore.Set(ctx, ParamStoreKeyVersionParams, cp.Version) } } +// SetInitialAppVersionInConsensusParams sets the initial app version +// in the consensus params if it has not yet been set. +func (app *BaseApp) SetInitialAppVersionInConsensusParams(ctx sdk.Context, version uint64) { + if !app.paramStore.Has(ctx, ParamStoreKeyVersionParams) { + app.paramStore.Set(ctx, ParamStoreKeyVersionParams, &tmproto.VersionParams{AppVersion: version}) + } +} + // getMaximumBlockGas gets the maximum gas from the consensus params. It panics // if maximum block gas is less than negative one and returns zero if negative // one.