refactor(baseapp): improve readability of preblock (#21179)

This commit is contained in:
Facundo Medica 2024-08-06 12:00:15 +02:00 committed by GitHub
parent 6d4097bfb7
commit ca8122c3f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 5 deletions

View File

@ -786,10 +786,11 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Finaliz
WithHeaderHash(req.Hash))
}
if err := app.preBlock(req); err != nil {
preblockEvents, err := app.preBlock(req)
if err != nil {
return nil, err
}
events = append(events, app.finalizeBlockState.ctx.EventManager().ABCIEvents()...)
events = append(events, preblockEvents...)
beginBlock, err := app.beginBlock(req)
if err != nil {

View File

@ -709,11 +709,12 @@ func (app *BaseApp) cacheTxContext(ctx sdk.Context, txBytes []byte) (sdk.Context
return ctx.WithMultiStore(msCache), msCache
}
func (app *BaseApp) preBlock(req *abci.FinalizeBlockRequest) error {
func (app *BaseApp) preBlock(req *abci.FinalizeBlockRequest) ([]abci.Event, error) {
var events []abci.Event
if app.preBlocker != nil {
ctx := app.finalizeBlockState.Context()
if err := app.preBlocker(ctx, req); err != nil {
return err
return nil, err
}
// ConsensusParams can change in preblocker, so we need to
// write the consensus parameters in store to context
@ -722,8 +723,9 @@ func (app *BaseApp) preBlock(req *abci.FinalizeBlockRequest) error {
gasMeter := app.getBlockGasMeter(ctx)
ctx = ctx.WithBlockGasMeter(gasMeter)
app.finalizeBlockState.SetContext(ctx)
events = ctx.EventManager().ABCIEvents()
}
return nil
return events, nil
}
func (app *BaseApp) beginBlock(_ *abci.FinalizeBlockRequest) (sdk.BeginBlock, error) {