diff --git a/CHANGELOG.md b/CHANGELOG.md index f67ba87572e..e89d3b848b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* (module)[#14415](https://github.com/cosmos/cosmos-sdk/pull/14415) Loosen assertions in SetOrderBeginBlockers() and SetOrderEndBlockers() * (context)[#14384](https://github.com/cosmos/cosmos-sdk/pull/14384) refactor(context): Pass EventManager to the context as an interface. * (types) [#14354](https://github.com/cosmos/cosmos-sdk/pull/14354) - improve performance on Context.KVStore and Context.TransientStore by 40% * (crypto/keyring) [#14151](https://github.com/cosmos/cosmos-sdk/pull/14151) Move keys presentation from `crypto/keyring` to `client/keys` diff --git a/simapp/app.go b/simapp/app.go index 2ce596655a8..c965f29b42f 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -415,19 +415,23 @@ func NewSimApp( // NOTE: staking module is required if HistoricalEntries param > 0 // NOTE: capability module's beginblocker must come before any modules using capabilities (e.g. IBC) app.ModuleManager.SetOrderBeginBlockers( - upgradetypes.ModuleName, capabilitytypes.ModuleName, minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName, - evidencetypes.ModuleName, stakingtypes.ModuleName, - authtypes.ModuleName, banktypes.ModuleName, govtypes.ModuleName, crisistypes.ModuleName, genutiltypes.ModuleName, - authz.ModuleName, feegrant.ModuleName, nft.ModuleName, group.ModuleName, - paramstypes.ModuleName, vestingtypes.ModuleName, consensusparamtypes.ModuleName, + upgradetypes.ModuleName, + capabilitytypes.ModuleName, + minttypes.ModuleName, + distrtypes.ModuleName, + slashingtypes.ModuleName, + evidencetypes.ModuleName, + stakingtypes.ModuleName, + genutiltypes.ModuleName, + authz.ModuleName, ) app.ModuleManager.SetOrderEndBlockers( - crisistypes.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName, - capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, - slashingtypes.ModuleName, minttypes.ModuleName, - genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName, - feegrant.ModuleName, nft.ModuleName, group.ModuleName, - paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, consensusparamtypes.ModuleName, + crisistypes.ModuleName, + govtypes.ModuleName, + stakingtypes.ModuleName, + genutiltypes.ModuleName, + feegrant.ModuleName, + group.ModuleName, ) // NOTE: The genutils module must occur after staking so that pools are diff --git a/simapp/app_config.go b/simapp/app_config.go index 914be6588ec..ecf7692ce50 100644 --- a/simapp/app_config.go +++ b/simapp/app_config.go @@ -108,39 +108,16 @@ var ( slashingtypes.ModuleName, evidencetypes.ModuleName, stakingtypes.ModuleName, - authtypes.ModuleName, - banktypes.ModuleName, - govtypes.ModuleName, - crisistypes.ModuleName, genutiltypes.ModuleName, authz.ModuleName, - feegrant.ModuleName, - nft.ModuleName, - group.ModuleName, - paramstypes.ModuleName, - vestingtypes.ModuleName, - consensustypes.ModuleName, }, EndBlockers: []string{ crisistypes.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName, - capabilitytypes.ModuleName, - authtypes.ModuleName, - banktypes.ModuleName, - distrtypes.ModuleName, - slashingtypes.ModuleName, - minttypes.ModuleName, genutiltypes.ModuleName, - evidencetypes.ModuleName, - authz.ModuleName, feegrant.ModuleName, - nft.ModuleName, group.ModuleName, - paramstypes.ModuleName, - consensustypes.ModuleName, - upgradetypes.ModuleName, - vestingtypes.ModuleName, }, OverrideStoreKeys: []*runtimev1alpha1.StoreKeyConfig{ { diff --git a/types/module/module.go b/types/module/module.go index f0e9193998f..8d27f3dbdfb 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -293,32 +293,42 @@ func NewManagerFromMap(moduleMap map[string]appmodule.AppModule) *Manager { // SetOrderInitGenesis sets the order of init genesis calls func (m *Manager) SetOrderInitGenesis(moduleNames ...string) { - m.assertNoForgottenModules("SetOrderInitGenesis", moduleNames) + m.assertNoForgottenModules("SetOrderInitGenesis", moduleNames, nil) m.OrderInitGenesis = moduleNames } // SetOrderExportGenesis sets the order of export genesis calls func (m *Manager) SetOrderExportGenesis(moduleNames ...string) { - m.assertNoForgottenModules("SetOrderExportGenesis", moduleNames) + m.assertNoForgottenModules("SetOrderExportGenesis", moduleNames, nil) m.OrderExportGenesis = moduleNames } // SetOrderBeginBlockers sets the order of set begin-blocker calls func (m *Manager) SetOrderBeginBlockers(moduleNames ...string) { - m.assertNoForgottenModules("SetOrderBeginBlockers", moduleNames) + m.assertNoForgottenModules("SetOrderBeginBlockers", moduleNames, + func(moduleName string) bool { + module := m.Modules[moduleName] + _, hasBeginBlock := module.(BeginBlockAppModule) + return !hasBeginBlock + }) m.OrderBeginBlockers = moduleNames } // SetOrderEndBlockers sets the order of set end-blocker calls func (m *Manager) SetOrderEndBlockers(moduleNames ...string) { - m.assertNoForgottenModules("SetOrderEndBlockers", moduleNames) + m.assertNoForgottenModules("SetOrderEndBlockers", moduleNames, + func(moduleName string) bool { + module := m.Modules[moduleName] + _, hasEndBlock := module.(EndBlockAppModule) + return !hasEndBlock + }) m.OrderEndBlockers = moduleNames } // SetOrderMigrations sets the order of migrations to be run. If not set // then migrations will be run with an order defined in `DefaultMigrationsOrder`. func (m *Manager) SetOrderMigrations(moduleNames ...string) { - m.assertNoForgottenModules("SetOrderMigrations", moduleNames) + m.assertNoForgottenModules("SetOrderMigrations", moduleNames, nil) m.OrderMigrations = moduleNames } @@ -425,13 +435,19 @@ func (m *Manager) checkModulesExists(moduleName []string) error { // assertNoForgottenModules checks that we didn't forget any modules in the // SetOrder* functions. -func (m *Manager) assertNoForgottenModules(setOrderFnName string, moduleNames []string) { +// `pass` is a closure which allows one to omit modules from `moduleNames`. If you provide non-nil `pass` and it returns true, the module would not be subject of the assertion. +func (m *Manager) assertNoForgottenModules(setOrderFnName string, moduleNames []string, pass func(moduleName string) bool) { ms := make(map[string]bool) for _, m := range moduleNames { ms[m] = true } var missing []string for m := range m.Modules { + m := m + if pass != nil && pass(m) { + continue + } + if !ms[m] { missing = append(missing, m) } @@ -439,7 +455,7 @@ func (m *Manager) assertNoForgottenModules(setOrderFnName string, moduleNames [] if len(missing) != 0 { sort.Strings(missing) panic(fmt.Sprintf( - "%s: all modules must be defined when setting %s, missing: %v", setOrderFnName, setOrderFnName, missing)) + "all modules must be defined when setting %s, missing: %v", setOrderFnName, missing)) } } diff --git a/types/module/module_int_test.go b/types/module/module_int_test.go index c4a421027f5..afdb4322ef2 100644 --- a/types/module/module_int_test.go +++ b/types/module/module_int_test.go @@ -23,16 +23,19 @@ func (s TestSuite) TestAssertNoForgottenModules() { //nolint:govet name string positive bool modules []string + pass func(string) bool }{ - {"same modules", true, []string{"a", "b"}}, - {"more modules", true, []string{"a", "b", "c"}}, + {"less modules", false, []string{"a"}, nil}, + {"same modules", true, []string{"a", "b"}, nil}, + {"more modules", true, []string{"a", "b", "c"}, nil}, + {"pass module b", true, []string{"a"}, func(moduleName string) bool { return moduleName == "b" }}, } for _, tc := range tcs { if tc.positive { - m.assertNoForgottenModules("x", tc.modules) + m.assertNoForgottenModules("x", tc.modules, tc.pass) } else { - s.Panics(func() { m.assertNoForgottenModules("x", tc.modules) }) + s.Panics(func() { m.assertNoForgottenModules("x", tc.modules, tc.pass) }) } } }