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

fix: in-place-testnet edgecases #19516

Merged
merged 3 commits into from
Feb 22, 2024
Merged
Changes from 1 commit
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
50 changes: 35 additions & 15 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@
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 {
Expand All @@ -797,16 +797,30 @@
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)
Fixed Show fixed Hide fixed
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
Expand Down Expand Up @@ -849,15 +863,21 @@
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
}
Expand Down
Loading