From b862e271a12b07907e9d804d78739d60222a1f4d Mon Sep 17 00:00:00 2001 From: Alexander Bezobchuk Date: Tue, 3 Dec 2019 04:24:12 -0500 Subject: [PATCH] Allow node to restart after halt config trigger (#5352) * Allow node to restart after halt config trigger * Update godoc * Update documentation on halt config --- CHANGELOG.md | 2 ++ baseapp/abci.go | 36 ++++++++++++++++++------------------ server/config/config.go | 6 ++---- server/config/toml.go | 6 ++---- 4 files changed, 24 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5ed05db7416..c7783efc23de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -196,6 +196,8 @@ to detail this new feature and how state transitions occur. * (keys) Fix ledger custom coin type support bug * (x/gov) [\#5107](https://github.com/cosmos/cosmos-sdk/pull/5107) Sum validator operator's all voting power when tally votes * (rest) [\#5212](https://github.com/cosmos/cosmos-sdk/issues/5212) Fix pagination in the `/gov/proposals` handler. +* (baseapp) [\#5350](https://github.com/cosmos/cosmos-sdk/issues/5350) Allow a node to restart successfully after a `halt-height` or `halt-time` + has been triggered. ## [v0.37.4] - 2019-11-04 diff --git a/baseapp/abci.go b/baseapp/abci.go index ef8c71d4222a..e93b7c56c2c9 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -215,24 +215,6 @@ func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) (res abci.ResponseDeliv func (app *BaseApp) Commit() (res abci.ResponseCommit) { header := app.deliverState.ctx.BlockHeader() - var halt bool - - switch { - case app.haltHeight > 0 && uint64(header.Height) >= app.haltHeight: - halt = true - - case app.haltTime > 0 && header.Time.Unix() >= int64(app.haltTime): - halt = true - } - - if halt { - app.halt() - - // Note: State is not actually committed when halted. Logs from Tendermint - // can be ignored. - return abci.ResponseCommit{} - } - // Write the DeliverTx state which is cache-wrapped and commit the MultiStore. // The write to the DeliverTx state writes all state transitions to the root // MultiStore (app.cms) so when Commit() is called is persists those values. @@ -249,6 +231,24 @@ func (app *BaseApp) Commit() (res abci.ResponseCommit) { // empty/reset the deliver state app.deliverState = nil + var halt bool + + switch { + case app.haltHeight > 0 && uint64(header.Height) >= app.haltHeight: + halt = true + + case app.haltTime > 0 && header.Time.Unix() >= int64(app.haltTime): + halt = true + } + + if halt { + // Halt the binary and allow Tendermint to receive the ResponseCommit + // response with the commit ID hash. This will allow the node to successfully + // restart and process blocks assuming the halt configuration has been + // reset or moved to a more distant value. + app.halt() + } + return abci.ResponseCommit{ Data: commitID.Hash, } diff --git a/server/config/config.go b/server/config/config.go index fc9ead54b466..9752ae85273a 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -22,16 +22,14 @@ type BaseConfig struct { // HaltHeight contains a non-zero block height at which a node will gracefully // halt and shutdown that can be used to assist upgrades and testing. // - // Note: State will not be committed on the corresponding height and any logs - // indicating such can be safely ignored. + // Note: Commitment of state will be attempted on the corresponding block. HaltHeight uint64 `mapstructure:"halt-height"` // HaltTime contains a non-zero minimum block time (in Unix seconds) at which // a node will gracefully halt and shutdown that can be used to assist // upgrades and testing. // - // Note: State will not be committed on the corresponding height and any logs - // indicating such can be safely ignored. + // Note: Commitment of state will be attempted on the corresponding block. HaltTime uint64 `mapstructure:"halt-time"` // InterBlockCache enables inter-block caching. diff --git a/server/config/toml.go b/server/config/toml.go index c0e27c69c809..0463d26a93fb 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -21,16 +21,14 @@ minimum-gas-prices = "{{ .BaseConfig.MinGasPrices }}" # HaltHeight contains a non-zero block height at which a node will gracefully # halt and shutdown that can be used to assist upgrades and testing. # -# Note: State will not be committed on the corresponding height and any logs -# indicating such can be safely ignored. +# Note: Commitment of state will be attempted on the corresponding block. halt-height = {{ .BaseConfig.HaltHeight }} # HaltTime contains a non-zero minimum block time (in Unix seconds) at which # a node will gracefully halt and shutdown that can be used to assist upgrades # and testing. # -# Note: State will not be committed on the corresponding height and any logs -# indicating such can be safely ignored. +# Note: Commitment of state will be attempted on the corresponding block. halt-time = {{ .BaseConfig.HaltTime }} # InterBlockCache enables inter-block caching.