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

feat: Implement BeginBlock EndBlock for Core API modules #14819

Merged
merged 12 commits into from
Feb 1, 2023
39 changes: 25 additions & 14 deletions types/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,14 @@ func (m *Manager) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) abci.R
ctx = ctx.WithEventManager(sdk.NewEventManager())

for _, moduleName := range m.OrderBeginBlockers {
module, ok := m.Modules[moduleName].(BeginBlockAppModule)
if ok {
if module, ok := m.Modules[moduleName].(BeginBlockAppModule); ok {
module.BeginBlock(ctx, req)
} else if module, ok := m.Modules[moduleName].(appmodule.HasBeginBlocker); ok {
err := module.BeginBlock(ctx)
if err != nil {
// TODO: Handle error
facundomedica marked this conversation as resolved.
Show resolved Hide resolved
panic(err)
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
}
}
}

Expand All @@ -603,20 +608,26 @@ func (m *Manager) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo
validatorUpdates := []abci.ValidatorUpdate{}

for _, moduleName := range m.OrderEndBlockers {
module, ok := m.Modules[moduleName].(EndBlockAppModule)
if !ok {
continue
}
moduleValUpdates := module.EndBlock(ctx, req)
if module, ok := m.Modules[moduleName].(EndBlockAppModule); ok {
moduleValUpdates := module.EndBlock(ctx, req)

// use these validator updates if provided, the module manager assumes
// only one module will update the validator set
if len(moduleValUpdates) > 0 {
if len(validatorUpdates) > 0 {
panic("validator EndBlock updates already set by a previous module")
}
// use these validator updates if provided, the module manager assumes
// only one module will update the validator set
if len(moduleValUpdates) > 0 {
if len(validatorUpdates) > 0 {
panic("validator EndBlock updates already set by a previous module")
Fixed Show fixed Hide fixed
}

validatorUpdates = moduleValUpdates
validatorUpdates = moduleValUpdates
}
} else if module, ok := m.Modules[moduleName].(appmodule.HasEndBlocker); ok {
err := module.EndBlock(ctx)
// TODO: Handle error
if err != nil {
panic(err)
Fixed Show fixed Hide fixed
}
} else {
continue
}
}

Expand Down