Skip to content

Commit

Permalink
fix: add recover to InitChainer to diplay informative message when st…
Browse files Browse the repository at this point in the history
…arting a node from block 1 (#2925)

* add recover to InitChainer

* generate files

* add docs link to error message

* move InitChainErrorMessage to app.go

* Update app/app.go

Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>

* use const for message

---------

Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>
  • Loading branch information
kingpinXD and Francisco de Borja Aranda Castillejo authored Sep 30, 2024
1 parent 03435b4 commit ec64772
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io"
"net/http"
"os"
"runtime/debug"
"time"

cosmoserrors "cosmossdk.io/errors"
Expand Down Expand Up @@ -876,6 +877,26 @@ func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo

// InitChainer application update at chain initialization
func (app *App) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
// InitChainErrorMessage is the error message displayed when trying to sync testnet or mainnet from block 1 using the latest binary.
const InitChainErrorMessage = `
Unable to sync testnet or mainnet from block 1 using the latest version.
Please use a snapshot to sync your node.
Refer to the documentation for more information:
https://www.zetachain.com/docs/nodes/start-here/syncing/`

// The defer is used to catch panics during InitChain
// and display a more meaningful message for people trying to sync a node from block 1 using the latest binary.
// We exit the process after displaying the message as we do not need to start a node with empty state.

defer func() {
if r := recover(); r != nil {
ctx.Logger().Error("panic occurred during InitGenesis", "error", r)
ctx.Logger().Debug("stack trace", "stack", string(debug.Stack()))
ctx.Logger().
Info(InitChainErrorMessage)
os.Exit(1)
}
}()
var genesisState GenesisState
if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
* [2944](https://github.com/zeta-chain/node/pull/2844) - add tsspubkey to index for tss keygen voting
* [2842](https://github.com/zeta-chain/node/pull/2842) - fix: move interval assignment out of cctx loop in EVM outbound tx scheduler
* [2853](https://github.com/zeta-chain/node/pull/2853) - calling precompile through sc with sc state update
* [2925](https://github.com/zeta-chain/node/pull/2925) - add recover to init chainer to diplay informative message when starting a node from block 1

## v20.0.0

Expand Down

0 comments on commit ec64772

Please sign in to comment.