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 @@
"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 @@

// 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 @@
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 @@

// 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 Error

Potential integer overflow by integer type conversion
halt = true

Check warning on line 743 in app/app.go

View check run for this annotation

Codecov / codecov/patch

app/app.go#L742-L743

Added lines #L742 - L743 were not covered by tests

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

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion Error

Potential integer overflow by integer type conversion
halt = true

Check warning on line 746 in app/app.go

View check run for this annotation

Codecov / codecov/patch

app/app.go#L745-L746

Added lines #L745 - L746 were not covered by tests
}

if halt {
app.Logger().Info("halting node per configuration", "height", app.haltHeight, "time", app.haltTime)

Check failure on line 750 in app/app.go

View workflow job for this annotation

GitHub Actions / check

github.com/crypto-org-chain/chain-main/v4/app.ChainApp.BeginBlocker calls github.com/tendermint/tendermint/libs/log.tmLogger.Info, which eventually calls runtime.Func.FileLine

Check failure on line 750 in app/app.go

View workflow job for this annotation

GitHub Actions / check

github.com/crypto-org-chain/chain-main/v4/app.ChainApp.BeginBlocker calls github.com/tendermint/tendermint/libs/log.tmLogger.Info, which eventually calls runtime.ReadMemStats
if err := app.Close(); err != nil {
app.Logger().Info("close application failed", "error", err)
}
panic("halt application")

Check warning on line 754 in app/app.go

View check run for this annotation

Codecov / codecov/patch

app/app.go#L750-L754

Added lines #L750 - L754 were not covered by tests

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

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 @@

// 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()

Check warning on line 967 in app/app.go

View check run for this annotation

Codecov / codecov/patch

app/app.go#L967

Added line #L967 was not covered by tests
}

return err
return errors.Join(err, app.BaseApp.Close())
}
Loading