Skip to content

Commit

Permalink
make setting the app version optional
Browse files Browse the repository at this point in the history
  • Loading branch information
cmwaters committed Mar 12, 2024
1 parent eefd419 commit 250b665
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ const (
func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitChain) {
// On a new chain, we consider the init chain block height as 0, even though
// req.InitialHeight is 1 by default.
initHeader := tmproto.Header{
ChainID: req.ChainId,
Time: req.Time,
Version: tmversion.Consensus{App: req.ConsensusParams.Version.AppVersion},
initHeader := tmproto.Header{ChainID: req.ChainId, Time: req.Time}
if req.ConsensusParams != nil && req.ConsensusParams.Version != nil {
initHeader.Version = tmversion.Consensus{App: req.ConsensusParams.Version.AppVersion}
}

// If req.InitialHeight is > 1, then we set the initial version in the
Expand All @@ -63,8 +62,12 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC
// Store the consensus params in the BaseApp's paramstore. Note, this must be
// done after the deliver state and context have been set as it's persisted
// to state.
app.StoreConsensusParams(app.deliverState.ctx, req.ConsensusParams)
app.appVersion = req.ConsensusParams.Version.AppVersion
if req.ConsensusParams != nil {
app.StoreConsensusParams(app.deliverState.ctx, req.ConsensusParams)
if req.ConsensusParams.Version != nil {
app.appVersion = req.ConsensusParams.Version.AppVersion
}
}

if app.initChainer == nil {
return res
Expand Down
4 changes: 2 additions & 2 deletions x/upgrade/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,15 @@ func (s *KeeperTestSuite) TestSetUpgradedClient() {
// Test that the protocol version successfully increments after an
// upgrade and is successfully set on BaseApp's appVersion.
func (s *KeeperTestSuite) TestIncrementProtocolVersion() {
oldProtocolVersion := s.app.BaseApp.AppVersion(s.ctx)
oldProtocolVersion := s.app.BaseApp.AppVersion()
s.app.UpgradeKeeper.SetUpgradeHandler("dummy", func(_ sdk.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { return vm, nil })
dummyPlan := types.Plan{
Name: "dummy",
Info: "some text here",
Height: 100,
}
s.app.UpgradeKeeper.ApplyUpgrade(s.ctx, dummyPlan)
upgradedProtocolVersion := s.app.BaseApp.AppVersion(s.ctx)
upgradedProtocolVersion := s.app.BaseApp.AppVersion()

s.Require().Equal(oldProtocolVersion+1, upgradedProtocolVersion)
}
Expand Down

0 comments on commit 250b665

Please sign in to comment.