Skip to content

Commit

Permalink
fix: call SetOrderExportGenesis from SimApp (#12048)
Browse files Browse the repository at this point in the history
## Description

This was causing sim failures like: 

```
exporting genesis...
2022-05-25T10:36:38-05:00 INFO asserting crisis invariants inv=0/12 module=x/crisis name=gov/module-account
2022-05-25T10:36:38-05:00 INFO asserting crisis invariants inv=1/12 module=x/crisis name=bank/nonnegative-outstanding
2022-05-25T10:36:38-05:00 INFO asserting crisis invariants inv=2/12 module=x/crisis name=bank/total-supply
2022-05-25T10:36:38-05:00 INFO asserting crisis invariants inv=3/12 module=x/crisis name=group/Group-TotalWeight
2022-05-25T10:36:38-05:00 INFO asserting crisis invariants inv=4/12 module=x/crisis name=distribution/nonnegative-outstanding
2022-05-25T10:36:38-05:00 INFO asserting crisis invariants inv=5/12 module=x/crisis name=distribution/can-withdraw
2022-05-25T10:36:38-05:00 INFO asserting crisis invariants inv=6/12 module=x/crisis name=distribution/reference-count
2022-05-25T10:36:38-05:00 INFO asserting crisis invariants inv=7/12 module=x/crisis name=distribution/module-account
2022-05-25T10:36:38-05:00 INFO asserting crisis invariants inv=8/12 module=x/crisis name=staking/module-accounts
2022-05-25T10:36:38-05:00 INFO asserting crisis invariants inv=9/12 module=x/crisis name=staking/nonnegative-power
2022-05-25T10:36:38-05:00 INFO asserting crisis invariants inv=10/12 module=x/crisis name=staking/positive-delegation
2022-05-25T10:36:38-05:00 INFO asserting crisis invariants inv=11/12 module=x/crisis name=staking/delegator-shares
2022-05-25T10:36:39-05:00 INFO asserted all invariants duration=1194.381198 height=50 module=x/crisis
importing genesis...
--- FAIL: TestAppSimulationAfterImport (20.98s)
panic: validator set is empty after InitGenesis, please ensure at least one validator is initialized with a delegation greater than or equal to the DefaultPowerReduction ({824635701280}) [recovered]
	panic: validator set is empty after InitGenesis, please ensure at least one validator is initialized with a delegation greater than or equal to the DefaultPowerReduction ({824635701280})

goroutine 76 [running]:
testing.tRunner.func1.2({0x1b88020, 0xc0035d70b0})
	/home/mkoco/sdk/go1.18.2/src/testing/testing.go:1389 +0x24e
testing.tRunner.func1()
	/home/mkoco/sdk/go1.18.2/src/testing/testing.go:1392 +0x39f
panic({0x1b88020, 0xc0035d70b0})
	/home/mkoco/sdk/go1.18.2/src/runtime/panic.go:838 +0x207
github.com/cosmos/cosmos-sdk/types/module.(*Manager).InitGenesis(_, {{0x28b5990, 0xc0001b2000}, {0x28c2da0, 0xc002494600}, {{0x0, 0x0}, {0x0, 0x0}, 0x0, ...}, ...}, ...)
	/home/mkoco/dev/regen/cosmos-sdk/types/module/module.go:329 +0x4fd
github.com/cosmos/cosmos-sdk/runtime.(*App).InitChainer(_, {{0x28b5990, 0xc0001b2000}, {0x28c2da0, 0xc002494600}, {{0x0, 0x0}, {0x0, 0x0}, 0x0, ...}, ...}, ...)
	/home/mkoco/dev/regen/cosmos-sdk/runtime/app.go:121 +0x12e
github.com/cosmos/cosmos-sdk/simapp.(*SimApp).InitChainer(_, {{0x28b5990, 0xc0001b2000}, {0x28c2da0, 0xc002494600}, {{0x0, 0x0}, {0x0, 0x0}, 0x0, ...}, ...}, ...)
	/home/mkoco/dev/regen/cosmos-sdk/simapp/app.go:504 +0x178
github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).InitChain(0xc000fb1340, {{0x0, 0x0, 0x0}, {0x0, 0x0}, 0x0, {0x0, 0x0, 0x0}, ...})
	/home/mkoco/dev/regen/cosmos-sdk/baseapp/abci.go:69 +0x3f5
github.com/cosmos/cosmos-sdk/simapp.TestAppSimulationAfterImport(0xc000abf520)
	/home/mkoco/dev/regen/cosmos-sdk/simapp/sim_test.go:269 +0xd67
testing.tRunner(0xc000abf520, 0x2590ac0)
	/home/mkoco/sdk/go1.18.2/src/testing/testing.go:1439 +0x102
created by testing.(*T).Run
	/home/mkoco/sdk/go1.18.2/src/testing/testing.go:1486 +0x35f
FAIL	github.com/cosmos/cosmos-sdk/simapp	21.018s
FAIL
```

### Root cause

Prior to merge of #11924, SimApp calls [module/NewManager](https://github.com/cosmos/cosmos-sdk/blob/2b549b807c13f66dca68965206163ca400d0dbe0/simapp/app.go#L344), which implicitly sets sane default values of [OrderExportGenesis](https://github.com/cosmos/cosmos-sdk/blob/2b549b807c13f66dca68965206163ca400d0dbe0/types/module/module.go#L239) from the modules passed as parameters.  Since this usage was deprecated in favor of [RegisterModules](https://github.com/cosmos/cosmos-sdk/blob/823d2a7f28f10a360b543748a6e90e01bb5d3c23/simapp/app.go#L354) in the app wiring work, `OrderExportGenesis` was now `nil`, resulting in empty `genesisData` in [ExportGenesis](https://github.com/cosmos/cosmos-sdk/blob/823d2a7f28f10a360b543748a6e90e01bb5d3c23/types/module/module.go#L339)



### Fix

Explicitly set `OrderExportGenesis` with same module order as `OrderInitGenesis` from `SimApp`.

---

### 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...

- [x] 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/main/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/main/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/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)
  • Loading branch information
kocubinski committed May 25, 2022
1 parent 823d2a7 commit b363e01
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 33 deletions.
182 changes: 159 additions & 23 deletions api/cosmos/app/runtime/v1alpha1/module.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/cosmos/base/abci/v1beta1/abci.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions proto/cosmos/app/runtime/v1alpha1/module.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ message Module {
// to call in the order in which they should be called. If this is left empty
// no init genesis function will be registered.
repeated string init_genesis = 4;

// export_genesis specifies the order in which to export module genesis data.
// If this is left empty, the init_genesis order will be used for export genesis
// if it is specified.
repeated string export_genesis = 5;
}
6 changes: 6 additions & 0 deletions runtime/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ func (a *App) Load(loadLatest bool) error {
a.SetInitChainer(a.InitChainer)
}

if len(a.config.ExportGenesis) != 0 {
a.ModuleManager.SetOrderExportGenesis(a.config.ExportGenesis...)
} else if len(a.config.InitGenesis) != 0 {
a.ModuleManager.SetOrderExportGenesis(a.config.InitGenesis...)
}

if len(a.config.BeginBlockers) != 0 {
a.ModuleManager.SetOrderBeginBlockers(a.config.BeginBlockers...)
a.SetBeginBlocker(a.BeginBlocker)
Expand Down
16 changes: 8 additions & 8 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func NewSimApp(

app.GovKeeper = *govKeeper.SetHooks(
govtypes.NewMultiGovHooks(
// register the governance hooks
// register the governance hooks
),
)
// set the governance module account as the authority for conducting upgrades
Expand Down Expand Up @@ -383,13 +383,13 @@ func NewSimApp(
// NOTE: Capability module must occur first so that it can initialize any capabilities
// so that other modules that want to create or claim capabilities afterwards in InitChain
// can do so safely.
app.ModuleManager.SetOrderInitGenesis(
capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName,
slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName,
genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName,
feegrant.ModuleName, nft.ModuleName, group.ModuleName,
paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName,
)
genesisModuleOrder := []string{capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName,
distrtypes.ModuleName, stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName,
minttypes.ModuleName, crisistypes.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName,
feegrant.ModuleName, nft.ModuleName, group.ModuleName, paramstypes.ModuleName, upgradetypes.ModuleName,
vestingtypes.ModuleName}
app.ModuleManager.SetOrderInitGenesis(genesisModuleOrder...)
app.ModuleManager.SetOrderExportGenesis(genesisModuleOrder...)

// Uncomment if you want to set a custom migration order here.
// app.mm.SetOrderMigrations(custom order)
Expand Down
2 changes: 1 addition & 1 deletion types/abci.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b363e01

Please sign in to comment.