Co-authored-by: Facundo Medica <14063057+facundomedica@users.noreply.github.com> Co-authored-by: marbar3778 <marbar3778@yahoo.com> Co-authored-by: Facundo <facundomedica@gmail.com>
This commit is contained in:
parent
3fc80745ee
commit
3f6796fba4
@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
* (baseapp) [#21159](https://github.com/cosmos/cosmos-sdk/pull/21159) Return PreBlocker events in FinalizeBlockResponse.
|
||||
* [#20939](https://github.com/cosmos/cosmos-sdk/pull/20939) Fix collection reverse iterator to include `pagination.key` in the result.
|
||||
* (client/grpc) [#20969](https://github.com/cosmos/cosmos-sdk/pull/20969) Fix `node.NewQueryServer` method not setting `cfg`.
|
||||
* (testutil/integration) [#21006](https://github.com/cosmos/cosmos-sdk/pull/21006) Fix `NewIntegrationApp` method not writing default genesis to state
|
||||
|
||||
@ -753,10 +753,13 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Request
|
||||
WithHeaderHash(req.Hash))
|
||||
}
|
||||
|
||||
if err := app.preBlock(req); err != nil {
|
||||
preblockEvents, err := app.preBlock(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
events = append(events, preblockEvents...)
|
||||
|
||||
beginBlock, err := app.beginBlock(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@ -2029,22 +2029,24 @@ func TestBaseApp_PreBlocker(t *testing.T) {
|
||||
wasHookCalled := false
|
||||
app.SetPreBlocker(func(ctx sdk.Context, req *abci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) {
|
||||
wasHookCalled = true
|
||||
return &sdk.ResponsePreBlock{
|
||||
ConsensusParamsChanged: true,
|
||||
}, nil
|
||||
|
||||
ctx.EventManager().EmitEvent(sdk.NewEvent("preblockertest", sdk.NewAttribute("height", fmt.Sprintf("%d", req.Height))))
|
||||
return &sdk.ResponsePreBlock{ConsensusParamsChanged: false}, nil
|
||||
})
|
||||
app.Seal()
|
||||
|
||||
_, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 1})
|
||||
res, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 1})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, true, wasHookCalled)
|
||||
require.Len(t, res.Events, 1)
|
||||
require.Equal(t, "preblockertest", res.Events[0].Type)
|
||||
|
||||
// Now try erroring
|
||||
app = baseapp.NewBaseApp(name, logger, db, nil)
|
||||
_, err = app.InitChain(&abci.RequestInitChain{})
|
||||
require.NoError(t, err)
|
||||
|
||||
app.SetPreBlocker(func(ctx sdk.Context, req *abci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) {
|
||||
app.SetPreBlocker(func(_ sdk.Context, req *abci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) {
|
||||
return nil, errors.New("some error")
|
||||
})
|
||||
app.Seal()
|
||||
|
||||
@ -704,12 +704,13 @@ func (app *BaseApp) cacheTxContext(ctx sdk.Context, txBytes []byte) (sdk.Context
|
||||
return ctx.WithMultiStore(msCache), msCache
|
||||
}
|
||||
|
||||
func (app *BaseApp) preBlock(req *abci.RequestFinalizeBlock) error {
|
||||
func (app *BaseApp) preBlock(req *abci.RequestFinalizeBlock) ([]abci.Event, error) {
|
||||
var events []abci.Event
|
||||
if app.preBlocker != nil {
|
||||
ctx := app.finalizeBlockState.Context()
|
||||
rsp, err := app.preBlocker(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
// rsp.ConsensusParamsChanged is true from preBlocker means ConsensusParams in store get changed
|
||||
// write the consensus parameters in store to context
|
||||
@ -720,8 +721,9 @@ func (app *BaseApp) preBlock(req *abci.RequestFinalizeBlock) error {
|
||||
ctx = ctx.WithBlockGasMeter(gasMeter)
|
||||
app.finalizeBlockState.SetContext(ctx)
|
||||
}
|
||||
events = ctx.EventManager().ABCIEvents()
|
||||
}
|
||||
return nil
|
||||
return events, nil
|
||||
}
|
||||
|
||||
func (app *BaseApp) beginBlock(_ *abci.RequestFinalizeBlock) (sdk.BeginBlock, error) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user