From bc9b3c2e54031839431c33b3d2f8e22809077cf2 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 21 Feb 2024 19:04:24 -0600 Subject: [PATCH] fix: edge case in-place-testnet states (#531) (#532) * fix prometheus edge case * fix halt height edge cases * figured out sigterm case * revert load commit step (cherry picked from commit d60a4bf4edd168e7e62707520a77942219219a3c) Co-authored-by: Adam Tucker --- server/start.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/server/start.go b/server/start.go index 73c8eabc3c99..1f33f460b306 100644 --- a/server/start.go +++ b/server/start.go @@ -21,6 +21,7 @@ import ( db "github.com/cometbft/cometbft-db" "github.com/cometbft/cometbft/abci/server" tcmd "github.com/cometbft/cometbft/cmd/cometbft/commands" + cmtcfg "github.com/cometbft/cometbft/config" cmtjson "github.com/cometbft/cometbft/libs/json" "github.com/cometbft/cometbft/node" "github.com/cometbft/cometbft/p2p" @@ -742,7 +743,7 @@ func testnetify(ctx *Context, home string, testnetAppCreator types.AppCreator, d // Depending on how the node was stopped, the application height can differ from the blockStore height. // This height difference changes how we go about modifying the state. clientCreator := proxy.NewLocalClientCreator(testnetApp) - metrics := node.DefaultMetricsProvider(config.Instrumentation) + metrics := node.DefaultMetricsProvider(cmtcfg.DefaultConfig().Instrumentation) _, _, _, _, proxyMetrics := metrics(genDoc.ChainID) //nolint:dogsled proxyApp := proxy.NewAppConns(clientCreator, proxyMetrics) if err := proxyApp.Start(); err != nil { @@ -762,13 +763,21 @@ func testnetify(ctx *Context, home string, testnetAppCreator types.AppCreator, d var block *cmttypes.Block switch { case appHeight == blockStore.Height(): - // This state occurs when we stop the node with the halt height flag, and need to handle differently - state.LastBlockHeight++ block = blockStore.LoadBlock(blockStore.Height()) - block.AppHash = appHash - state.AppHash = appHash + // If the state's last blockstore height does not match the app and blockstore height, we likely stopped with the halt height flag. + if state.LastBlockHeight != appHeight { + state.LastBlockHeight = appHeight + block.AppHash = appHash + state.AppHash = appHash + } else { + // Node was likely stopped via SIGTERM, delete the next block's seen commit + err := blockStoreDB.Delete([]byte(fmt.Sprintf("SC:%v", blockStore.Height()+1))) + if err != nil { + return nil, err + } + } case blockStore.Height() > state.LastBlockHeight: - // This state occurs when we kill the node + // This state usually occurs when we gracefully stop the node. err = blockStore.DeleteLatestBlock() if err != nil { return nil, err