From 86a3d3f8f8119e54d859e5a6b4024fb32ca7d7aa Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Sat, 27 Jul 2024 11:01:24 -0600 Subject: [PATCH 1/2] initial impl of appending events --- baseapp/abci.go | 5 ++++- baseapp/baseapp.go | 8 +++++--- types/abci.go | 1 + types/module/module.go | 1 + 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 2bef4642ba41..06db4e59dd55 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -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 diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index a73d87f7caf7..81789c2d06e5 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -705,12 +705,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 @@ -721,8 +722,9 @@ func (app *BaseApp) preBlock(req *abci.RequestFinalizeBlock) error { ctx = ctx.WithBlockGasMeter(gasMeter) app.finalizeBlockState.SetContext(ctx) } + events = rsp.Events } - return nil + return events, nil } func (app *BaseApp) beginBlock(_ *abci.RequestFinalizeBlock) (sdk.BeginBlock, error) { diff --git a/types/abci.go b/types/abci.go index 8325f5dadf0c..fe9d29313556 100644 --- a/types/abci.go +++ b/types/abci.go @@ -69,6 +69,7 @@ type BeginBlock struct { type ResponsePreBlock struct { ConsensusParamsChanged bool + Events []abci.Event } func (r ResponsePreBlock) IsConsensusParamsChanged() bool { diff --git a/types/module/module.go b/types/module/module.go index cdc40dcb60f7..1b13ca868279 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -766,6 +766,7 @@ func (m *Manager) PreBlock(ctx sdk.Context) (*sdk.ResponsePreBlock, error) { } return &sdk.ResponsePreBlock{ ConsensusParamsChanged: paramsChanged, + Events: ctx.EventManager().ABCIEvents(), }, nil } From 2b26e5b8da545f33bbd6617e9eba11d6a4c0d213 Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Wed, 28 Aug 2024 07:49:57 -0600 Subject: [PATCH 2/2] add change log --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8c02d1bc54f..ea52afb2b3e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,7 +38,9 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased Provenance] -* nothing +### Improvements + +* [#611](https://github.com/provenance-io/cosmos-sdk/pull/611) Provenance: Fix emission of pre-block events. ---