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

Co-authored-by: mmsqe <mavis@crypto.com>
Co-authored-by: aljo242 <alex@interchainlabs.io>
This commit is contained in:
mergify[bot] 2025-03-05 15:13:52 -05:00 committed by GitHub
parent 8903e43a9e
commit b0ee102cfa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 32 additions and 1219 deletions

View File

@ -51,6 +51,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Bug Fixes
* (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.
* (query) [#23883](https://github.com/cosmos/cosmos-sdk/pull/23883) Fix NPE in query pagination.
* (client) [#23860](https://github.com/cosmos/cosmos-sdk/pull/23860) Add missing `unordered` field for legacy amino signing of tx body.
* (x/bank) [#23836](https://github.com/cosmos/cosmos-sdk/pull/23836) Fix `DenomMetadata` rpc allow value with slashes.

File diff suppressed because it is too large Load Diff

View File

@ -855,6 +855,9 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Request
// where they adhere to the sdk.Tx interface.
func (app *BaseApp) FinalizeBlock(req *abci.RequestFinalizeBlock) (res *abci.ResponseFinalizeBlock, err error) {
defer func() {
if res == nil {
return
}
// 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 {

View File

@ -43,6 +43,18 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/signing"
)
type mockABCIListener struct {
ListenCommitFn func(context.Context, abci.ResponseCommit, []*storetypes.StoreKVPair) error
}
func (m mockABCIListener) ListenFinalizeBlock(_ context.Context, _ abci.RequestFinalizeBlock, _ abci.ResponseFinalizeBlock) error {
return nil
}
func (m *mockABCIListener) ListenCommit(ctx context.Context, commit abci.ResponseCommit, pairs []*storetypes.StoreKVPair) error {
return m.ListenCommitFn(ctx, commit, pairs)
}
func TestABCI_Info(t *testing.T) {
suite := NewBaseAppSuite(t)
@ -2493,3 +2505,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.RequestFinalizeBlock{
Height: 2,
})
require.Empty(t, res)
require.NotEmpty(t, err)
}

View File

@ -219,11 +219,7 @@ The Cosmos SDK handles two types of evidence inside the ABCI `BeginBlock`:
The evidence module handles these two evidence types the same way. First, the Cosmos SDK converts the CometBFT concrete evidence type to an SDK `Evidence` interface using `Equivocation` as the concrete type.
```protobuf reference
<<<<<<< HEAD
https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/evidence/v1beta1/evidence.proto#L12-L32
=======
https://github.com/cosmos/cosmos-sdk/tree/release/v0.50.x/proto/cosmos/evidence/v1beta1/evidence.proto#L12-L32
>>>>>>> 5411e73bb (docs: update version references (#23898))
```
For some `Equivocation` submitted in `block` to be valid, it must satisfy:
@ -247,11 +243,7 @@ validator to ever re-enter the validator set.
The `Equivocation` evidence is handled as follows:
```go reference
<<<<<<< HEAD
https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/x/evidence/keeper/infraction.go#L26-L140
=======
https://github.com/cosmos/cosmos-sdk/tree/release/v0.50.x/x/evidence/keeper/infraction.go#L26-L140
>>>>>>> 5411e73bb (docs: update version references (#23898))
```
**Note:** The slashing, jailing, and tombstoning calls are delegated through the `x/slashing` module