diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b2e54259ee6..19eedb234b52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +* (upgrade) [#12603](https://github.com/cosmos/cosmos-sdk/pull/12603) feat: Move AppModule.BeginBlock and AppModule.EndBlock to extension interfaces + +### Features + ## [v0.46.0-rc3](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.0-rc3) - 2022-07-18 ### Features diff --git a/types/module/module.go b/types/module/module.go index 81bd7b246913..bbf4abcadba7 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -169,9 +169,17 @@ type AppModule interface { // introduced by the module. To avoid wrong/empty versions, the initial version // should be set to 1. ConsensusVersion() uint64 +} - // ABCI +// BeginBlockAppModule is an extension interface that contains information about the AppModule and BeginBlock. +type BeginBlockAppModule interface { + AppModule BeginBlock(sdk.Context, abci.RequestBeginBlock) +} + +// EndBlockAppModule is an extension interface that contains information about the AppModule and EndBlock. +type EndBlockAppModule interface { + AppModule EndBlock(sdk.Context, abci.RequestEndBlock) []abci.ValidatorUpdate } @@ -468,7 +476,10 @@ func (m *Manager) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) abci.R ctx = ctx.WithEventManager(sdk.NewEventManager()) for _, moduleName := range m.OrderBeginBlockers { - m.Modules[moduleName].BeginBlock(ctx, req) + module, ok := m.Modules[moduleName].(BeginBlockAppModule) + if ok { + module.BeginBlock(ctx, req) + } } return abci.ResponseBeginBlock{ @@ -484,7 +495,11 @@ func (m *Manager) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo validatorUpdates := []abci.ValidatorUpdate{} for _, moduleName := range m.OrderEndBlockers { - moduleValUpdates := m.Modules[moduleName].EndBlock(ctx, req) + module, ok := m.Modules[moduleName].(EndBlockAppModule) + if !ok { + continue + } + moduleValUpdates := module.EndBlock(ctx, req) // use these validator updates if provided, the module manager assumes // only one module will update the validator set diff --git a/types/module/module_test.go b/types/module/module_test.go index 37bbf088cc70..926a4a4ab3f8 100644 --- a/types/module/module_test.go +++ b/types/module/module_test.go @@ -79,8 +79,6 @@ func TestGenesisOnlyAppModule(t *testing.T) { // no-op goam.RegisterInvariants(mockInvariantRegistry) - goam.BeginBlock(sdk.Context{}, abci.RequestBeginBlock{}) - require.Equal(t, []abci.ValidatorUpdate{}, goam.EndBlock(sdk.Context{}, abci.RequestEndBlock{})) } func TestManagerOrderSetters(t *testing.T) { diff --git a/x/auth/module.go b/x/auth/module.go index 3bb68ca7e71a..cd15593a7c76 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -155,15 +155,6 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 3 } -// BeginBlock returns the begin blocker for the auth module. -func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} - -// EndBlock returns the end blocker for the auth module. It returns no validator -// updates. -func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} - // AppModuleSimulation functions // GenerateGenesisState creates a randomized GenState of the auth module diff --git a/x/auth/vesting/module.go b/x/auth/vesting/module.go index 49925dd61f2c..06f9b8d995ec 100644 --- a/x/auth/vesting/module.go +++ b/x/auth/vesting/module.go @@ -111,14 +111,6 @@ func (am AppModule) InitGenesis(_ sdk.Context, _ codec.JSONCodec, _ json.RawMess return []abci.ValidatorUpdate{} } -// BeginBlock performs a no-op. -func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} - -// EndBlock performs a no-op. -func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} - // ExportGenesis is always empty, as InitGenesis does nothing either. func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONCodec) json.RawMessage { return am.DefaultGenesis(cdc) diff --git a/x/authz/module/module.go b/x/authz/module/module.go index 7ff061c691f5..b92deb2e3e11 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -162,11 +162,6 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { BeginBlocker(ctx, am.keeper) } -// EndBlock does nothing -func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} - // ____________________________________________________________________________ // AppModuleSimulation functions diff --git a/x/bank/module.go b/x/bank/module.go index bfeee7eed6ba..1db195adb264 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -160,15 +160,6 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 3 } -// BeginBlock performs a no-op. -func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} - -// EndBlock returns the end blocker for the bank module. It returns no validator -// updates. -func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} - // AppModuleSimulation functions // GenerateGenesisState creates a randomized GenState of the bank module. diff --git a/x/capability/module.go b/x/capability/module.go index e2ac1709795c..8fba1eddb3ab 100644 --- a/x/capability/module.go +++ b/x/capability/module.go @@ -148,12 +148,6 @@ func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { am.keeper.InitMemStore(ctx) } -// EndBlock executes all ABCI EndBlock logic respective to the capability module. It -// returns no validator updates. -func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} - // GenerateGenesisState creates a randomized GenState of the capability module. func (AppModule) GenerateGenesisState(simState *module.SimulationState) { simulation.RandomizedGenState(simState) diff --git a/x/crisis/module.go b/x/crisis/module.go index 7c058a4f22e0..6538beec4eae 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -155,9 +155,6 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 } -// BeginBlock performs a no-op. -func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} - // EndBlock returns the end blocker for the crisis module. It returns no validator // updates. func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { diff --git a/x/distribution/module.go b/x/distribution/module.go index dc54a64a9b77..8a663f2ffcb8 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -163,12 +163,6 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { BeginBlocker(ctx, req, am.keeper) } -// EndBlock returns the end blocker for the distribution module. It returns no validator -// updates. -func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} - // AppModuleSimulation functions // GenerateGenesisState creates a randomized GenState of the distribution module. diff --git a/x/evidence/module.go b/x/evidence/module.go index 0dcf1ac3fac3..d160dd19767c 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -170,12 +170,6 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { BeginBlocker(ctx, req, am.keeper) } -// EndBlock executes all ABCI EndBlock logic respective to the evidence module. It -// returns no validator updates. -func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} - // AppModuleSimulation functions // GenerateGenesisState creates a randomized GenState of the evidence module. diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index 6752b16f2331..fe0c23ea53b1 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -176,9 +176,6 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 2 } -// BeginBlock returns the begin blocker for the feegrant module. -func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} - // EndBlock returns the end blocker for the feegrant module. It returns no validator // updates. func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { diff --git a/x/gov/module.go b/x/gov/module.go index b93dab8f1f0a..a495bfea2b0d 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -193,9 +193,6 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 3 } -// BeginBlock performs a no-op. -func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} - // EndBlock returns the end blocker for the gov module. It returns no validator // updates. func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { diff --git a/x/group/module/module.go b/x/group/module/module.go index 7b8baf8538bf..800292789a31 100644 --- a/x/group/module/module.go +++ b/x/group/module/module.go @@ -147,8 +147,6 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 } -func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {} - // EndBlock implements the group module's EndBlock. func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { EndBlocker(ctx, am.keeper) diff --git a/x/mint/module.go b/x/mint/module.go index 658d49ecd60e..3e6231053fb9 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -155,12 +155,6 @@ func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { BeginBlocker(ctx, am.keeper, am.inflationCalculator) } -// EndBlock returns the end blocker for the mint module. It returns no validator -// updates. -func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} - // AppModuleSimulation functions // GenerateGenesisState creates a randomized GenState of the mint module. diff --git a/x/nft/module/module.go b/x/nft/module/module.go index ab6fc9633cc9..63999d68157e 100644 --- a/x/nft/module/module.go +++ b/x/nft/module/module.go @@ -152,13 +152,6 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 } -func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {} - -// EndBlock does nothing -func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} - // ____________________________________________________________________________ // AppModuleSimulation functions diff --git a/x/params/module.go b/x/params/module.go index ddee65dc5823..ab8192d2a7f7 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -139,11 +139,3 @@ func (am AppModule) ExportGenesis(_ sdk.Context, _ codec.JSONCodec) json.RawMess // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 } - -// BeginBlock performs a no-op. -func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} - -// EndBlock performs a no-op. -func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} diff --git a/x/slashing/module.go b/x/slashing/module.go index 47f2aec83872..06b5b3ef6223 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -160,12 +160,6 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { BeginBlocker(ctx, req, am.keeper) } -// EndBlock returns the end blocker for the slashing module. It returns no validator -// updates. -func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} - // AppModuleSimulation functions // GenerateGenesisState creates a randomized GenState of the slashing module. diff --git a/x/upgrade/abci_test.go b/x/upgrade/abci_test.go index 8f3b8f52dbfd..aa38e8ab5dad 100644 --- a/x/upgrade/abci_test.go +++ b/x/upgrade/abci_test.go @@ -24,7 +24,7 @@ import ( ) type TestSuite struct { - module module.AppModule + module module.BeginBlockAppModule keeper keeper.Keeper querier sdk.Querier handler govtypes.Handler diff --git a/x/upgrade/module.go b/x/upgrade/module.go index e4e2ad5a006e..9a31d21241b4 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -133,8 +133,3 @@ func (AppModule) ConsensusVersion() uint64 { return consensusVersion } func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { BeginBlocker(am.keeper, ctx, req) } - -// EndBlock does nothing -func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -}