From cc777b98b567983d99382db815e43952effa0079 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 21 Feb 2024 15:06:09 -0700 Subject: [PATCH 1/3] fix in-place-testnet edgecases --- server/start.go | 50 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/server/start.go b/server/start.go index d972ed3e5413..3c28f35af656 100644 --- a/server/start.go +++ b/server/start.go @@ -780,7 +780,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 { @@ -797,16 +797,30 @@ func testnetify(ctx *Context, home string, testnetAppCreator types.AppCreator, d appHash := res.LastBlockAppHash appHeight := res.LastBlockHeight + // Delete the walDir and recreate the folder. + // These write ahead logs cause edge cases and serve no purpose for the testnet. + walDir := fmt.Sprintf("%s/cs.wal", config.DBDir()) + err = os.RemoveAll(walDir) + if err != nil { + return nil, err + } + err = os.MkdirAll(walDir, 0o755) + if err != nil { + return nil, err + } + 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++ + block.AppHash = appHash + state.AppHash = appHash + } case blockStore.Height() > state.LastBlockHeight: - // This state occurs when we kill the node + // This state usually occurs when we sig kill the node. err = blockStore.DeleteLatestBlock() if err != nil { return nil, err @@ -849,15 +863,21 @@ func testnetify(ctx *Context, home string, testnetAppCreator types.AppCreator, d block.LastCommit.Signatures[0].Signature = vote.Signature block.LastCommit.Signatures = []cmttypes.CommitSig{block.LastCommit.Signatures[0]} - // Load the seenCommit of the lastBlockHeight and modify it to be signed from our validator - seenCommit := blockStore.LoadSeenCommit(state.LastBlockHeight) - seenCommit.BlockID = state.LastBlockID - seenCommit.Round = vote.Round - seenCommit.Signatures[0].Signature = vote.Signature - seenCommit.Signatures[0].ValidatorAddress = validatorAddress - seenCommit.Signatures[0].Timestamp = vote.Timestamp - seenCommit.Signatures = []cmttypes.CommitSig{seenCommit.Signatures[0]} - err = blockStore.SaveSeenCommit(state.LastBlockHeight, seenCommit) + // Create a commit signed from our validator and save it + seenCommit := cmttypes.Commit{ + Height: state.LastBlockHeight, + Round: vote.Round, + BlockID: state.LastBlockID, + Signatures: []cmttypes.CommitSig{ + { + BlockIDFlag: cmttypes.BlockIDFlagCommit, + Signature: vote.Signature, + ValidatorAddress: validatorAddress, + Timestamp: vote.Timestamp, + }, + }, + } + err = blockStore.SaveSeenCommit(state.LastBlockHeight, &seenCommit) if err != nil { return nil, err } From c534ee2e14aa788b59364b95489d1a540f359253 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 21 Feb 2024 17:12:51 -0700 Subject: [PATCH 2/3] figure out sigterm case --- server/start.go | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/server/start.go b/server/start.go index 3c28f35af656..635766a6096c 100644 --- a/server/start.go +++ b/server/start.go @@ -797,30 +797,24 @@ func testnetify(ctx *Context, home string, testnetAppCreator types.AppCreator, d appHash := res.LastBlockAppHash appHeight := res.LastBlockHeight - // Delete the walDir and recreate the folder. - // These write ahead logs cause edge cases and serve no purpose for the testnet. - walDir := fmt.Sprintf("%s/cs.wal", config.DBDir()) - err = os.RemoveAll(walDir) - if err != nil { - return nil, err - } - err = os.MkdirAll(walDir, 0o755) - if err != nil { - return nil, err - } - var block *cmttypes.Block switch { case appHeight == blockStore.Height(): block = blockStore.LoadBlock(blockStore.Height()) // 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++ + 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 usually occurs when we sig kill the node. + // This state usually occurs when we gracefully stop the node. err = blockStore.DeleteLatestBlock() if err != nil { return nil, err From a4f070a39835e916ed37d58955a05fd0949fbacf Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 21 Feb 2024 17:17:04 -0700 Subject: [PATCH 3/3] revert load commit step --- server/start.go | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/server/start.go b/server/start.go index 635766a6096c..1c39d78c5c1d 100644 --- a/server/start.go +++ b/server/start.go @@ -857,21 +857,15 @@ func testnetify(ctx *Context, home string, testnetAppCreator types.AppCreator, d block.LastCommit.Signatures[0].Signature = vote.Signature block.LastCommit.Signatures = []cmttypes.CommitSig{block.LastCommit.Signatures[0]} - // Create a commit signed from our validator and save it - seenCommit := cmttypes.Commit{ - Height: state.LastBlockHeight, - Round: vote.Round, - BlockID: state.LastBlockID, - Signatures: []cmttypes.CommitSig{ - { - BlockIDFlag: cmttypes.BlockIDFlagCommit, - Signature: vote.Signature, - ValidatorAddress: validatorAddress, - Timestamp: vote.Timestamp, - }, - }, - } - err = blockStore.SaveSeenCommit(state.LastBlockHeight, &seenCommit) + // Load the seenCommit of the lastBlockHeight and modify it to be signed from our validator + seenCommit := blockStore.LoadSeenCommit(state.LastBlockHeight) + seenCommit.BlockID = state.LastBlockID + seenCommit.Round = vote.Round + seenCommit.Signatures[0].Signature = vote.Signature + seenCommit.Signatures[0].ValidatorAddress = validatorAddress + seenCommit.Signatures[0].Timestamp = vote.Timestamp + seenCommit.Signatures = []cmttypes.CommitSig{seenCommit.Signatures[0]} + err = blockStore.SaveSeenCommit(state.LastBlockHeight, seenCommit) if err != nil { return nil, err }