diff --git a/CHANGELOG.md b/CHANGELOG.md index d93ad6806..dcb0b64b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - [#991](https://github.com/crypto-org-chain/chain-main/pull/991) Update cometbft `v0.34.29` with several minor bug fixes and low-severity security-fixes. +- [#998](https://github.com/crypto-org-chain/chain-main/pull/998) Port halt-height fix from sdk ### Bug Fixes diff --git a/app/app.go b/app/app.go index 62c67a557..3a5298c72 100644 --- a/app/app.go +++ b/app/app.go @@ -29,6 +29,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/api" "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" @@ -270,6 +271,10 @@ type ChainApp struct { // the configurator configurator module.Configurator + + // duplicate the logic here because it's private in sdk + haltHeight uint64 + haltTime uint64 } func init() { @@ -334,6 +339,8 @@ func New( keys: keys, tkeys: tkeys, memKeys: memKeys, + haltHeight: cast.ToUint64(appOpts.Get(server.FlagHaltHeight)), + haltTime: cast.ToUint64(appOpts.Get(server.FlagHaltTime)), } app.ParamsKeeper = initParamsKeeper(appCodec, legacyAmino, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey]) @@ -729,6 +736,24 @@ func (app *ChainApp) Name() string { return app.BaseApp.Name() } // BeginBlocker application updates every begin block func (app *ChainApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock { + // backport: https://github.com/cosmos/cosmos-sdk/pull/16639 + var halt bool + switch { + case app.haltHeight > 0 && uint64(req.Header.Height) > app.haltHeight: + halt = true + + case app.haltTime > 0 && req.Header.Time.Unix() > int64(app.haltTime): + halt = true + } + + if halt { + app.Logger().Info("halting node per configuration", "height", app.haltHeight, "time", app.haltTime) + if err := app.Close(); err != nil { + app.Logger().Info("close application failed", "error", err) + } + panic("halt application") + } + return app.mm.BeginBlock(ctx, req) } @@ -937,11 +962,10 @@ func StoreKeys() ( // Close will be called in graceful shutdown in start cmd func (app *ChainApp) Close() error { - err := app.BaseApp.Close() - + var err error if cms, ok := app.CommitMultiStore().(io.Closer); ok { - return errors.Join(err, cms.Close()) + err = cms.Close() } - return err + return errors.Join(err, app.BaseApp.Close()) }