-
Notifications
You must be signed in to change notification settings - Fork 4.1k
fix(baseapp): ensure ABCI listeners always run in FinalizeBlock #19202
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -871,18 +871,28 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Request | |
| // skipped. This is to support compatibility with proposers injecting vote | ||
| // extensions into the proposal, which should not themselves be executed in cases | ||
| // where they adhere to the sdk.Tx interface. | ||
| func (app *BaseApp) FinalizeBlock(req *abci.RequestFinalizeBlock) (*abci.ResponseFinalizeBlock, error) { | ||
| func (app *BaseApp) FinalizeBlock(req *abci.RequestFinalizeBlock) (res *abci.ResponseFinalizeBlock, err error) { | ||
| defer func() { | ||
| // call the streaming service hooks with the FinalizeBlock messages | ||
| for _, streamingListener := range app.streamingManager.ABCIListeners { | ||
| if err := streamingListener.ListenFinalizeBlock(app.finalizeBlockState.Context(), *req, *res); err != nil { | ||
| app.logger.Error("ListenFinalizeBlock listening hook failed", "height", req.Height, "err", err) | ||
| } | ||
| } | ||
| }() | ||
|
|
||
| if app.optimisticExec.Initialized() { | ||
| // check if the hash we got is the same as the one we are executing | ||
| aborted := app.optimisticExec.AbortIfNeeded(req.Hash) | ||
| // Wait for the OE to finish, regardless of whether it was aborted or not | ||
| res, err := app.optimisticExec.WaitResult() | ||
| res, err = app.optimisticExec.WaitResult() | ||
|
|
||
| // only return if we are not aborting | ||
| if !aborted { | ||
| if res != nil { | ||
| res.AppHash = app.workingHash() | ||
| } | ||
|
|
||
| return res, err | ||
| } | ||
|
|
||
|
Comment on lines
871
to
898
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Overall, the changes made to the |
||
|
|
@@ -892,18 +902,11 @@ func (app *BaseApp) FinalizeBlock(req *abci.RequestFinalizeBlock) (*abci.Respons | |
| } | ||
|
|
||
| // if no OE is running, just run the block (this is either a block replay or a OE that got aborted) | ||
| res, err := app.internalFinalizeBlock(context.Background(), req) | ||
| res, err = app.internalFinalizeBlock(context.Background(), req) | ||
| if res != nil { | ||
| res.AppHash = app.workingHash() | ||
| } | ||
|
|
||
| // call the streaming service hooks with the FinalizeBlock messages | ||
| for _, streamingListener := range app.streamingManager.ABCIListeners { | ||
| if err := streamingListener.ListenFinalizeBlock(app.finalizeBlockState.Context(), *req, *res); err != nil { | ||
| app.logger.Error("ListenFinalizeBlock listening hook failed", "height", req.Height, "err", err) | ||
| } | ||
| } | ||
|
|
||
| return res, err | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic to handle optimistic execution (OE) seems to be correctly checking if the OE was initialized and aborting if necessary. However, the
WaitResultmethod is called without checking iferris not nil after the OE is aborted. This could potentially lead to a situation where an error from the OE is ignored, and the block execution continues with an invalid state.if app.optimisticExec.Initialized() { aborted := app.optimisticExec.AbortIfNeeded(req.Hash) // Wait for the OE to finish, regardless of whether it was aborted or not res, err = app.optimisticExec.WaitResult() // only return if we are not aborting if !aborted { if res != nil { res.AppHash = app.workingHash() } return res, err } // if it was aborted, we need to reset the state app.finalizeBlockState = nil app.optimisticExec.Reset() }Committable suggestion