Skip to content
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

Fix Emission of Pre-Block Events #611

Open
wants to merge 2 commits into
base: release-pio/v0.50.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---

Expand Down
5 changes: 4 additions & 1 deletion baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions types/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type BeginBlock struct {

type ResponsePreBlock struct {
ConsensusParamsChanged bool
Events []abci.Event
}

func (r ResponsePreBlock) IsConsensusParamsChanged() bool {
Expand Down
1 change: 1 addition & 0 deletions types/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,7 @@ func (m *Manager) PreBlock(ctx sdk.Context) (*sdk.ResponsePreBlock, error) {
}
return &sdk.ResponsePreBlock{
ConsensusParamsChanged: paramsChanged,
Events: ctx.EventManager().ABCIEvents(),
}, nil
}

Expand Down