fix(baseapp): ensure finalize block response is not empty (#23879)

This commit is contained in:
mmsqe 2025-03-06 01:59:07 +08:00 committed by GitHub
parent 77af49c1d4
commit 05df209fa4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 0 deletions

View File

@ -53,6 +53,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
### Bug Fixes
* (x/auth) [#23741](https://github.com/cosmos/cosmos-sdk/pull/23741) Support legacy global AccountNumber.
* (baseapp) [#23879](https://github.com/cosmos/cosmos-sdk/pull/23879) Ensure finalize block response is not empty in the defer check of FinalizeBlock to avoid panic by nil pointer.
* (types/query) [#23880](https://github.com/cosmos/cosmos-sdk/pull/23880) Fix NPE in query pagination.
### Removed

View File

@ -903,6 +903,9 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Finaliz
// where they adhere to the sdk.Tx interface.
func (app *BaseApp) FinalizeBlock(req *abci.FinalizeBlockRequest) (res *abci.FinalizeBlockResponse, err error) {
defer func() {
if res == nil {
return
}
// call the streaming service hooks with the FinalizeBlock messages
for _, streamingListener := range app.streamingManager.ABCIListeners {
if streamErr := streamingListener.ListenFinalizeBlock(app.finalizeBlockState.Context(), *req, *res); streamErr != nil {

View File

@ -2779,3 +2779,18 @@ func TestABCI_Proposal_FailReCheckTx(t *testing.T) {
require.NotEmpty(t, res.TxResults[0].Events)
require.True(t, res.TxResults[0].IsOK(), fmt.Sprintf("%v", res))
}
func TestFinalizeBlockDeferResponseHandle(t *testing.T) {
suite := NewBaseAppSuite(t, baseapp.SetHaltHeight(1))
suite.baseApp.SetStreamingManager(storetypes.StreamingManager{
ABCIListeners: []storetypes.ABCIListener{
&mockABCIListener{},
},
})
res, err := suite.baseApp.FinalizeBlock(&abci.FinalizeBlockRequest{
Height: 2,
})
require.Empty(t, res)
require.NotEmpty(t, err)
}