Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: halt-height is not deterministic #998

Merged
merged 2 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
32 changes: 28 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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:

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion

Potential integer overflow by integer type conversion
halt = true

case app.haltTime > 0 && req.Header.Time.Unix() > int64(app.haltTime):

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion

Potential integer overflow by integer type conversion
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")

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
}

return app.mm.BeginBlock(ctx, req)
}

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