* 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)
(cherry picked from commit d3a8e1e953
)
# Conflicts:
# CHANGELOG.md
# simapp/app.go
* fix conflicss
* Fix build
Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com>
This commit is contained in:
parent
44d3f4d5f9
commit
a0503e5595
|
@ -54,6 +54,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
|||
to reduce the RAM usage, CPU time usage, and garbage collection pressure from clearing maps,
|
||||
instead of allocating new maps.
|
||||
* (store) [\#10741](https://github.com/cosmos/cosmos-sdk/pull/10741) Significantly speedup iterator creation after delete heavy workloads. Significantly improves IBC migration times.
|
||||
* (module) [\#10711](https://github.com/cosmos/cosmos-sdk/pull/10711) Panic at startup if the app developer forgot to add modules in the `SetOrder{BeginBlocker, EndBlocker, InitGenesis, ExportGenesis}` functions. This means that all modules, even those who have empty implementations for those methods, need to be added to `SetOrder*`.
|
||||
* (types) [\#10076](https://github.com/cosmos/cosmos-sdk/pull/10076) Significantly speedup and lower allocations for `Coins.String()`.
|
||||
|
||||
### Bug Fixes
|
||||
|
|
|
@ -37,16 +37,16 @@ import (
|
|||
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
|
||||
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/authz"
|
||||
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
|
||||
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/capability"
|
||||
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
|
||||
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/x/authz"
|
||||
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
|
||||
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
|
||||
"github.com/cosmos/cosmos-sdk/x/crisis"
|
||||
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
|
||||
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
|
||||
|
@ -332,8 +332,18 @@ func NewSimApp(
|
|||
app.mm.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,
|
||||
paramstypes.ModuleName, vestingtypes.ModuleName,
|
||||
)
|
||||
app.mm.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,
|
||||
paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName,
|
||||
)
|
||||
app.mm.SetOrderEndBlockers(crisistypes.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName)
|
||||
|
||||
// NOTE: The genutils module must occur after staking so that pools are
|
||||
// properly initialized with tokens from genesis accounts.
|
||||
|
@ -345,6 +355,7 @@ func NewSimApp(
|
|||
slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName,
|
||||
genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName,
|
||||
feegrant.ModuleName,
|
||||
paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName,
|
||||
)
|
||||
|
||||
app.mm.RegisterInvariants(&app.CrisisKeeper)
|
||||
|
|
|
@ -30,6 +30,7 @@ package module
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
|
@ -252,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
|
||||
}
|
||||
|
||||
|
@ -331,6 +336,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
|
||||
|
||||
|
|
Loading…
Reference in New Issue