From 607f02915d1dc4f4196842e74371f5f2dd314613 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Thu, 22 Feb 2024 07:21:58 -0600 Subject: [PATCH] fix: in-place-testnet edgecases (#19516) (cherry picked from commit 35fe6c4ccd2764325bb1421ee98f107649bc0dd8) --- server/start.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/server/start.go b/server/start.go index 3b7388a36c9d..71874cd4269f 100644 --- a/server/start.go +++ b/server/start.go @@ -788,7 +788,7 @@ func testnetify(ctx *Context, home string, testnetAppCreator types.AppCreator, d cmtApp := NewCometABCIWrapper(testnetApp) _, context := getCtx(ctx, true) clientCreator := proxy.NewLocalClientCreator(cmtApp) - metrics := node.DefaultMetricsProvider(config.Instrumentation) + metrics := node.DefaultMetricsProvider(cmtcfg.DefaultConfig().Instrumentation) _, _, _, _, proxyMetrics, _, _ := metrics(genDoc.ChainID) proxyApp := proxy.NewAppConns(clientCreator, proxyMetrics) if err := proxyApp.Start(); err != nil { @@ -808,13 +808,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