From d444b8f27e73bf3f293254c1b05f22d4e3abe3cf Mon Sep 17 00:00:00 2001 From: Rootul P Date: Tue, 14 May 2024 13:50:52 -0400 Subject: [PATCH] fix: restart node for chain that starts on v2 (#3477) Closes https://github.com/celestiaorg/celestia-app/issues/3462 Previously, `InitChain` for a genesis with app version 2 wouldn't save the app version to consensus params. This means that if the node stopped and started up again, it would fetch `0` from consensus params and default to using app version 1 because of [these lines](https://github.com/rootulp/celestia-app/blob/dd6b188c0553d7cdd81161c62558db88a353d173/app/app.go#L520-L525). The fix in this PR is to save app version 2 and above to consensus params in `InitGenesis`. ## Testing ```shell ./scripts/single-node.sh # wait a block then stop the node with CTRL + C celestia-appd start # works and doesn't panic ``` --- app/app.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/app.go b/app/app.go index 7866687e13..37a941f38e 100644 --- a/app/app.go +++ b/app/app.go @@ -87,6 +87,7 @@ import ( tmjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/libs/log" tmos "github.com/tendermint/tendermint/libs/os" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" ) @@ -547,13 +548,21 @@ func (app *App) InitChain(req abci.RequestInitChain) (res abci.ResponseInitChain if req.ConsensusParams.Version.AppVersion == 0 { panic("app version 0 is not accepted. Please set an app version in the genesis") } + appVersion := req.ConsensusParams.Version.AppVersion // mount the stores for the provided app version if it has not already been mounted if app.AppVersion() == 0 && !app.IsSealed() { - app.mountKeysAndInit(req.ConsensusParams.Version.AppVersion) + app.mountKeysAndInit(appVersion) } - return app.BaseApp.InitChain(req) + res = app.BaseApp.InitChain(req) + + ctx := app.NewContext(false, tmproto.Header{}) + if appVersion != v1 { + app.SetInitialAppVersionInConsensusParams(ctx, appVersion) + app.SetAppVersion(ctx, appVersion) + } + return res } // mountKeysAndInit mounts the keys for the provided app version and then