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: initialize FinalizeBlock state in case of a crash/restart #16882

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
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
13 changes: 10 additions & 3 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,14 @@ func (app *BaseApp) FinalizeBlock(req *abci.RequestFinalizeBlock) (*abci.Respons
AppHash: app.LastCommitID().Hash,
}

// If the node crashed after ProcessProposal but before FinalizeBlock, then
// app.finalizeBlockState will be nil. In this case, we need to
// reinitialize the state. This also means that anything written to finalizeBlockState
// during ProcessProposal wasn't persisted and is now lost.
Comment on lines 677 to +683
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change potentially affects state.

Call sequence:

(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).FinalizeBlock (baseapp/abci.go:654)

if app.finalizeBlockState == nil {
app.setState(execModeFinalize, header)
}

// app.finalizeBlockState.ctx will already be initialized
// by InitChain or by ProcessProposal. Context is now updated with Header information.
app.finalizeBlockState.ctx = app.finalizeBlockState.ctx.
Expand All @@ -699,10 +707,9 @@ func (app *BaseApp) FinalizeBlock(req *abci.RequestFinalizeBlock) (*abci.Respons
LastCommit: req.DecidedLastCommit,
})

// GasMeter must be set after we get a context with updated consensus params.
gasMeter := app.getBlockGasMeter(app.finalizeBlockState.ctx)

app.finalizeBlockState.ctx = app.finalizeBlockState.ctx.
WithBlockGasMeter(gasMeter)
app.finalizeBlockState.ctx = app.finalizeBlockState.ctx.WithBlockGasMeter(gasMeter)

if app.checkState != nil {
app.checkState.ctx = app.checkState.ctx.
Expand Down