Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add app version in the context in InitChain #376

Merged
merged 3 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/gogo/protobuf/proto"
abci "github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmversion "github.com/tendermint/tendermint/proto/tendermint/version"
"google.golang.org/grpc/codes"
grpcstatus "google.golang.org/grpc/status"

Expand All @@ -38,12 +39,15 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC
// 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}
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
// stores.
if req.InitialHeight > 1 {
app.initialHeight = req.InitialHeight
initHeader = tmproto.Header{ChainID: req.ChainId, Height: req.InitialHeight, Time: req.Time}
initHeader.Height = req.InitialHeight
err := app.cms.SetInitialVersion(req.InitialHeight)
if err != nil {
panic(err)
Expand Down Expand Up @@ -131,8 +135,8 @@ func (app *BaseApp) Info(req abci.RequestInfo) abci.ResponseInfo {
if err != nil {
panic(err)
}
// get and set the app version
_ = app.AppVersion(ctx)
// initialise the app version by checking if it is already in state
app.InitAppVersion(ctx)
}
return abci.ResponseInfo{
Data: app.name,
Expand Down
8 changes: 5 additions & 3 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,17 @@ func (app *BaseApp) Name() string {
return app.name
}

// AppVersion returns the application's protocol version.
func (app *BaseApp) AppVersion(ctx sdk.Context) uint64 {
func (app *BaseApp) InitAppVersion(ctx sdk.Context) {
if app.appVersion == 0 && app.paramStore.Has(ctx, ParamStoreKeyVersionParams) {
var vp tmproto.VersionParams

app.paramStore.Get(ctx, ParamStoreKeyVersionParams, &vp)
// set the app version
app.appVersion = vp.AppVersion
}
}

// AppVersion returns the application's protocol version.
func (app *BaseApp) AppVersion() uint64 {
return app.appVersion
}

Expand Down
4 changes: 1 addition & 3 deletions baseapp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ func (app *BaseApp) SetVersion(v string) {

// SetAppVersion sets the application's protocol version
func (app *BaseApp) SetAppVersion(ctx sdk.Context, version uint64) {
// TODO: could make this less hacky in the future since the SDK
// shouldn't have to know about the app versioning scheme
if version >= 2 {
if app.paramStore.Has(ctx, ParamStoreKeyVersionParams) {
vp := &tmproto.VersionParams{AppVersion: version}
app.paramStore.Set(ctx, ParamStoreKeyVersionParams, vp)
}
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
Loading