fix: Panic if SetOrder* functions forgot modules (#10711)
<!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description fixes: #10708 Panic at startup if chain devs forgot to add some modules in SetOrder* functions. <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
This commit is contained in:
@@ -253,21 +253,25 @@ func NewManager(modules ...AppModule) *Manager {
|
||||
|
||||
// SetOrderInitGenesis sets the order of init genesis calls
|
||||
func (m *Manager) SetOrderInitGenesis(moduleNames ...string) {
|
||||
m.checkForgottenModules("SetOrderInitGenesis", moduleNames)
|
||||
m.OrderInitGenesis = moduleNames
|
||||
}
|
||||
|
||||
// SetOrderExportGenesis sets the order of export genesis calls
|
||||
func (m *Manager) SetOrderExportGenesis(moduleNames ...string) {
|
||||
m.checkForgottenModules("SetOrderExportGenesis", moduleNames)
|
||||
m.OrderExportGenesis = moduleNames
|
||||
}
|
||||
|
||||
// SetOrderBeginBlockers sets the order of set begin-blocker calls
|
||||
func (m *Manager) SetOrderBeginBlockers(moduleNames ...string) {
|
||||
m.checkForgottenModules("SetOrderBeginBlockers", moduleNames)
|
||||
m.OrderBeginBlockers = moduleNames
|
||||
}
|
||||
|
||||
// SetOrderEndBlockers sets the order of set end-blocker calls
|
||||
func (m *Manager) SetOrderEndBlockers(moduleNames ...string) {
|
||||
m.checkForgottenModules("SetOrderEndBlockers", moduleNames)
|
||||
m.OrderEndBlockers = moduleNames
|
||||
}
|
||||
|
||||
@@ -341,6 +345,19 @@ func (m *Manager) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) map[string
|
||||
return genesisData
|
||||
}
|
||||
|
||||
// checkForgottenModules checks that we didn't forget any modules in the
|
||||
// SetOrder* functions.
|
||||
func (m *Manager) checkForgottenModules(setOrderFnName string, moduleNames []string) {
|
||||
setOrderMap := map[string]struct{}{}
|
||||
for _, m := range moduleNames {
|
||||
setOrderMap[m] = struct{}{}
|
||||
}
|
||||
|
||||
if len(setOrderMap) != len(m.Modules) {
|
||||
panic(fmt.Sprintf("got %d modules in the module manager, but %d modules in %s", len(m.Modules), len(setOrderMap), setOrderFnName))
|
||||
}
|
||||
}
|
||||
|
||||
// MigrationHandler is the migration function that each module registers.
|
||||
type MigrationHandler func(sdk.Context) error
|
||||
|
||||
|
||||
Reference in New Issue
Block a user