From 8efa00c6d81923aee799d43f6406c067f305d406 Mon Sep 17 00:00:00 2001 From: stackman27 Date: Sun, 17 Jul 2022 00:30:03 -0700 Subject: [PATCH 1/5] moved begin and end block to its own interface --- types/module/module.go | 14 +++++++++++--- x/auth/module.go | 9 --------- x/auth/vesting/module.go | 8 -------- x/authz/module/module.go | 5 ----- x/bank/module.go | 9 --------- x/capability/module.go | 6 ------ x/crisis/module.go | 3 --- x/distribution/module.go | 6 ------ x/evidence/module.go | 6 ------ x/feegrant/module/module.go | 3 --- x/gov/module.go | 3 --- x/group/module/module.go | 2 -- x/mint/module.go | 6 ------ x/nft/module/module.go | 7 ------- x/params/module.go | 8 -------- x/slashing/module.go | 6 ------ x/upgrade/module.go | 5 ----- 17 files changed, 11 insertions(+), 95 deletions(-) diff --git a/types/module/module.go b/types/module/module.go index 81bd7b246913..d99d4b268f1c 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,7 @@ 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) + m.Modules[moduleName].(BeginBlockAppModule).BeginBlock(ctx, req) } return abci.ResponseBeginBlock{ @@ -484,7 +492,7 @@ 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) + moduleValUpdates := m.Modules[moduleName].(EndBlockAppModule).EndBlock(ctx, req) // use these validator updates if provided, the module manager assumes // only one module will update the validator set diff --git a/x/auth/module.go b/x/auth/module.go index 5eb6b0f9e308..52052b362a83 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -171,15 +171,6 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } -// 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 4484e0a34be2..b893e160c6fa 100644 --- a/x/auth/vesting/module.go +++ b/x/auth/vesting/module.go @@ -116,14 +116,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 6f1e2431bde2..29c12c7a5bc3 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -169,11 +169,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{} -} - func init() { appmodule.Register( &modulev1.Module{}, diff --git a/x/bank/module.go b/x/bank/module.go index 4a31f85cc9e9..1e8b1c094e8d 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -172,15 +172,6 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 4 } -// 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 a4c3f5e818ad..959df84dfc31 100644 --- a/x/capability/module.go +++ b/x/capability/module.go @@ -160,12 +160,6 @@ func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { } } -// 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 ca66890b9c5f..ee3fec22194d 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -179,9 +179,6 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } -// 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 2d1f16c0a31b..d9a9b1b813f0 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -186,12 +186,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 1b9759c34a69..009807e88166 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -176,12 +176,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 77aa839f49ad..d2b50f410d7e 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -182,9 +182,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 ad54cdd9f696..dd95f7e18896 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -294,9 +294,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 3adaff5d0155..915b24970aba 100644 --- a/x/group/module/module.go +++ b/x/group/module/module.go @@ -153,8 +153,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 7945b4abee73..dbd91bac8cfd 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -188,12 +188,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 51f08ff123e5..51537ed7379d 100644 --- a/x/nft/module/module.go +++ b/x/nft/module/module.go @@ -157,13 +157,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 bcff2504f2cc..7d851f6fec09 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -149,14 +149,6 @@ 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{} -} - // // New App Wiring Setup // diff --git a/x/slashing/module.go b/x/slashing/module.go index 239465983b1b..773b920f55f9 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -184,12 +184,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{} -} - // _____________________________________________________________________________________ func init() { diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 6589b63343b8..011885f0eec9 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -151,11 +151,6 @@ 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{} -} - // // New App Wiring Setup // From cae186c6c85f2847a7afa1611a15e18b59c8795c Mon Sep 17 00:00:00 2001 From: stackman27 Date: Sun, 17 Jul 2022 14:17:19 -0700 Subject: [PATCH 2/5] fixed typecasting and tests --- core/appconfig/debug_container.dot | 3 +++ types/module/module.go | 12 ++++++++++-- types/module/module_test.go | 2 -- x/upgrade/abci_test.go | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 core/appconfig/debug_container.dot diff --git a/core/appconfig/debug_container.dot b/core/appconfig/debug_container.dot new file mode 100644 index 000000000000..f246d9aba416 --- /dev/null +++ b/core/appconfig/debug_container.dot @@ -0,0 +1,3 @@ +digraph "" { +} + diff --git a/types/module/module.go b/types/module/module.go index d99d4b268f1c..64035733fded 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -476,7 +476,11 @@ 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].(BeginBlockAppModule).BeginBlock(ctx, req) + module, ok := m.Modules[moduleName].(BeginBlockAppModule) + if !ok { + return abci.ResponseBeginBlock{} + } + module.BeginBlock(ctx, req) } return abci.ResponseBeginBlock{ @@ -492,7 +496,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].(EndBlockAppModule).EndBlock(ctx, req) + module, ok := m.Modules[moduleName].(EndBlockAppModule) + if !ok { + return abci.ResponseEndBlock{} + } + 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/upgrade/abci_test.go b/x/upgrade/abci_test.go index b76185452b09..e7e3b0b6803a 100644 --- a/x/upgrade/abci_test.go +++ b/x/upgrade/abci_test.go @@ -28,7 +28,7 @@ import ( ) type TestSuite struct { - module module.AppModule + module module.BeginBlockAppModule keeper keeper.Keeper querier sdk.Querier handler govtypes.Handler From c6e8f7620248a31bdf3379015b3ce6faaefcb3c6 Mon Sep 17 00:00:00 2001 From: stackman27 Date: Sun, 17 Jul 2022 22:00:19 -0700 Subject: [PATCH 3/5] dev and bez comments --- types/module/module.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/types/module/module.go b/types/module/module.go index 64035733fded..bbf4abcadba7 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -171,13 +171,13 @@ type AppModule interface { ConsensusVersion() uint64 } -// BeginBlockAppModule is an extension interface that contains information about the AppModule and BeginBlock +// 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 +// EndBlockAppModule is an extension interface that contains information about the AppModule and EndBlock. type EndBlockAppModule interface { AppModule EndBlock(sdk.Context, abci.RequestEndBlock) []abci.ValidatorUpdate @@ -477,10 +477,9 @@ func (m *Manager) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) abci.R for _, moduleName := range m.OrderBeginBlockers { module, ok := m.Modules[moduleName].(BeginBlockAppModule) - if !ok { - return abci.ResponseBeginBlock{} + if ok { + module.BeginBlock(ctx, req) } - module.BeginBlock(ctx, req) } return abci.ResponseBeginBlock{ @@ -498,7 +497,7 @@ func (m *Manager) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo for _, moduleName := range m.OrderEndBlockers { module, ok := m.Modules[moduleName].(EndBlockAppModule) if !ok { - return abci.ResponseEndBlock{} + continue } moduleValUpdates := module.EndBlock(ctx, req) From ab96b873f5cfa33a0707894bd2c670bdf37dbe44 Mon Sep 17 00:00:00 2001 From: stackman27 Date: Sun, 17 Jul 2022 22:01:32 -0700 Subject: [PATCH 4/5] removed unnecessary file --- core/appconfig/debug_container.dot | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 core/appconfig/debug_container.dot diff --git a/core/appconfig/debug_container.dot b/core/appconfig/debug_container.dot deleted file mode 100644 index f246d9aba416..000000000000 --- a/core/appconfig/debug_container.dot +++ /dev/null @@ -1,3 +0,0 @@ -digraph "" { -} - From 81f7fbfac0f0287855885fa073c58470bdc21adf Mon Sep 17 00:00:00 2001 From: stackman27 Date: Mon, 18 Jul 2022 20:56:53 -0700 Subject: [PATCH 5/5] added changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e6677cd6c08..cf848506e06c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (query) [#12253](https://github.com/cosmos/cosmos-sdk/pull/12253) Add `GenericFilteredPaginate` to the `query` package to improve UX. * (telemetry) [#12405](https://github.com/cosmos/cosmos-sdk/pull/12405) Add _query_ calls metric to telemetry. * (sdk.Coins) [#12627](https://github.com/cosmos/cosmos-sdk/pull/12627) Make a Denoms method on sdk.Coins. +* (upgrade) [#12603](https://github.com/cosmos/cosmos-sdk/pull/12603) feat: Move AppModule.BeginBlock and AppModule.EndBlock to extension interfaces ### Improvements