Skip to content

Commit

Permalink
fix: restart node for chain that starts on v2 (#3477)
Browse files Browse the repository at this point in the history
Closes #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
```
  • Loading branch information
rootulp authored May 14, 2024
1 parent 7828e6c commit d444b8f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d444b8f

Please sign in to comment.