From ee19e81afa57752b78844b7a58715b007edd10ed Mon Sep 17 00:00:00 2001 From: HuangYi Date: Tue, 4 Jul 2023 15:00:43 +0800 Subject: [PATCH 1/2] Problem: halt-height is not deterministic Solution: - port the fix from sdk: https://github.com/cosmos/cosmos-sdk/pull/16639 --- CHANGELOG.md | 1 + app/app.go | 32 ++++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d93ad6806..142b090ae 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. +- [#]() 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()) } From a6c8c6c5aa51f42e826db1fb989b22d1f566b3c4 Mon Sep 17 00:00:00 2001 From: yihuang Date: Tue, 4 Jul 2023 15:02:13 +0800 Subject: [PATCH 2/2] Update CHANGELOG.md Signed-off-by: yihuang --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 142b090ae..dcb0b64b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +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. -- [#]() Port halt-height fix from sdk +- [#998](https://github.com/crypto-org-chain/chain-main/pull/998) Port halt-height fix from sdk ### Bug Fixes