Skip to content

Commit ca8122c

Browse files
refactor(baseapp): improve readability of preblock (#21179)
1 parent 6d4097b commit ca8122c

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

baseapp/abci.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,10 +786,11 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Finaliz
786786
WithHeaderHash(req.Hash))
787787
}
788788

789-
if err := app.preBlock(req); err != nil {
789+
preblockEvents, err := app.preBlock(req)
790+
if err != nil {
790791
return nil, err
791792
}
792-
events = append(events, app.finalizeBlockState.ctx.EventManager().ABCIEvents()...)
793+
events = append(events, preblockEvents...)
793794

794795
beginBlock, err := app.beginBlock(req)
795796
if err != nil {

baseapp/baseapp.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -709,11 +709,12 @@ func (app *BaseApp) cacheTxContext(ctx sdk.Context, txBytes []byte) (sdk.Context
709709
return ctx.WithMultiStore(msCache), msCache
710710
}
711711

712-
func (app *BaseApp) preBlock(req *abci.FinalizeBlockRequest) error {
712+
func (app *BaseApp) preBlock(req *abci.FinalizeBlockRequest) ([]abci.Event, error) {
713+
var events []abci.Event
713714
if app.preBlocker != nil {
714715
ctx := app.finalizeBlockState.Context()
715716
if err := app.preBlocker(ctx, req); err != nil {
716-
return err
717+
return nil, err
717718
}
718719
// ConsensusParams can change in preblocker, so we need to
719720
// write the consensus parameters in store to context
@@ -722,8 +723,9 @@ func (app *BaseApp) preBlock(req *abci.FinalizeBlockRequest) error {
722723
gasMeter := app.getBlockGasMeter(ctx)
723724
ctx = ctx.WithBlockGasMeter(gasMeter)
724725
app.finalizeBlockState.SetContext(ctx)
726+
events = ctx.EventManager().ABCIEvents()
725727
}
726-
return nil
728+
return events, nil
727729
}
728730

729731
func (app *BaseApp) beginBlock(_ *abci.FinalizeBlockRequest) (sdk.BeginBlock, error) {

0 commit comments

Comments
 (0)