Skip to content

Commit

Permalink
chore: loosen assertions in SetOrderInitGenesis and `SetOrderExport…
Browse files Browse the repository at this point in the history
…Genesis` (cosmos#14457)
  • Loading branch information
julienrbrt authored Jan 2, 2023
1 parent 88623ed commit 461cf87
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 49 deletions.
11 changes: 9 additions & 2 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ This guide provides instructions for upgrading to specific versions of Cosmos SD

### Database configuration

Cleveldb, Boltdb and BadgerDB are not supported anymore. To migrate from a unsupported database to a supported database please use the database migration tool
ClevelDB, BoltDB and BadgerDB are not supported anymore. To migrate from a unsupported database to a supported database please use the database migration tool.

<!-- TODO: write data base migration tool -->
<!-- TODO: write database migration tool -->

### Protobuf

Expand All @@ -19,6 +19,13 @@ The SDK is in the process of removing all `gogoproto` annotations.
The `gogoproto.goproto_stringer = false` annotation has been removed from most proto files. This means that the `String()` method is being generated for types that previously had this annotation. The generated `String()` method uses `proto.CompactTextString` for _stringifying_ structs.
[Verify](https://github.com/cosmos/cosmos-sdk/pull/13850#issuecomment-1328889651) the usage of the modified `String()` methods and double-check that they are not used in state-machine code.

### SimApp

#### Module Assertions

Previously, all modules were required to be set in `OrderBeginBlockers`, `OrderEndBlockers` and `OrderInitGenesis / OrderExportGenesis` in `app.go` / `app_config.go`.
This is no longer the case, the assertion has been loosened to only require modules implementing, respectively, the `module.BeginBlockAppModule`, `module.EndBlockAppModule` and `module.HasGenesis` interfaces.

## [v0.47.x](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.47.0)

### Simulation
Expand Down
2 changes: 1 addition & 1 deletion client/v2/autocli/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func TestNotFoundErrors(t *testing.T) {
Service: testpb.Query_ServiceDesc.ServiceName,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{{RpcMethod: "bar"}},
})
assert.ErrorContains(t, err, "rpc method bar not found")
assert.ErrorContains(t, err, "rpc method \"bar\" not found")

// bad positional field
_, err = b.BuildModuleQueryCommand("test", &autocliv1.ServiceCommandDescriptor{
Expand Down
47 changes: 29 additions & 18 deletions simapp/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,6 @@ import (
)

var (

// NOTE: The genutils module must occur after staking so that pools are
// properly initialized with tokens from genesis accounts.
// NOTE: The genutils module must also occur after auth so that it can access the params from auth.
// 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.
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, consensustypes.ModuleName, runtime.ModuleName,
}

// module account permissions
moduleAccPerms = []*authmodulev1.ModuleAccountPermission{
{Account: authtypes.FeeCollectorName},
Expand Down Expand Up @@ -126,12 +111,38 @@ var (
KvStoreKey: "acc",
},
},
InitGenesis: genesisModuleOrder,
// NOTE: The genutils module must occur after staking so that pools are
// properly initialized with tokens from genesis accounts.
// NOTE: The genutils module must also occur after auth so that it can access the params from auth.
// 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.
InitGenesis: []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,
consensustypes.ModuleName,
},
// When ExportGenesis is not specified, the export genesis module order
// is equal to the init genesis order
// ExportGenesis: genesisModuleOrder,
// ExportGenesis: []string{},
// Uncomment if you want to set a custom migration order here.
// OrderMigrations: nil,
// OrderMigrations: []string{},
}),
},
{
Expand Down
3 changes: 1 addition & 2 deletions testutil/configurator/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,9 @@ func NewAppConfig(opts ...ModuleOption) depinject.Config {
opt(cfg)
}

// always add runtime module
beginBlockers := make([]string, 0)
endBlockers := make([]string, 0)
initGenesis := []string{"runtime"}
initGenesis := make([]string, 0)
overrides := make([]*runtimev1alpha1.StoreKeyConfig, 0)

for _, s := range beginBlockOrder {
Expand Down
12 changes: 10 additions & 2 deletions types/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,21 @@ 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, nil)
m.assertNoForgottenModules("SetOrderInitGenesis", moduleNames, func(moduleName string) bool {
module := m.Modules[moduleName]
_, hasGenesis := module.(HasGenesis)
return !hasGenesis
})
m.OrderInitGenesis = moduleNames
}

// SetOrderExportGenesis sets the order of export genesis calls
func (m *Manager) SetOrderExportGenesis(moduleNames ...string) {
m.assertNoForgottenModules("SetOrderExportGenesis", moduleNames, nil)
m.assertNoForgottenModules("SetOrderExportGenesis", moduleNames, func(moduleName string) bool {
module := m.Modules[moduleName]
_, hasGenesis := module.(HasGenesis)
return !hasGenesis
})
m.OrderExportGenesis = moduleNames
}

Expand Down
2 changes: 0 additions & 2 deletions x/auth/testutil/app_config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package testutil

import (
"github.com/cosmos/cosmos-sdk/runtime"
_ "github.com/cosmos/cosmos-sdk/x/auth" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/auth/vesting" // import as blank for app wiring
Expand Down Expand Up @@ -61,7 +60,6 @@ var AppConfig = appconfig.Compose(&appv1alpha1.Config{
paramstypes.ModuleName,
consensustypes.ModuleName,
vestingtypes.ModuleName,
runtime.ModuleName,
},
}),
},
Expand Down
2 changes: 0 additions & 2 deletions x/authz/testutil/app_config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package testutil

import (
"github.com/cosmos/cosmos-sdk/runtime"
_ "github.com/cosmos/cosmos-sdk/x/auth" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/authz/module" // import as blank for app wiring
Expand Down Expand Up @@ -62,7 +61,6 @@ var AppConfig = appconfig.Compose(&appv1alpha1.Config{
authz.ModuleName,
paramstypes.ModuleName,
consensustypes.ModuleName,
runtime.ModuleName,
},
}),
},
Expand Down
2 changes: 0 additions & 2 deletions x/capability/testutil/app_config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package testutil

import (
"github.com/cosmos/cosmos-sdk/runtime"
_ "github.com/cosmos/cosmos-sdk/x/auth" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/bank" // import as blank for app wiring
Expand Down Expand Up @@ -55,7 +54,6 @@ var AppConfig = appconfig.Compose(&appv1alpha1.Config{
genutiltypes.ModuleName,
paramstypes.ModuleName,
consensustypes.ModuleName,
runtime.ModuleName,
},
}),
},
Expand Down
2 changes: 0 additions & 2 deletions x/distribution/testutil/app_config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package testutil

import (
"github.com/cosmos/cosmos-sdk/runtime"
_ "github.com/cosmos/cosmos-sdk/x/auth" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/bank" // import as blank for app wiring
Expand Down Expand Up @@ -60,7 +59,6 @@ var AppConfig = appconfig.Compose(&appv1alpha1.Config{
genutiltypes.ModuleName,
paramstypes.ModuleName,
consensustypes.ModuleName,
runtime.ModuleName,
},
}),
},
Expand Down
2 changes: 0 additions & 2 deletions x/evidence/testutil/app_config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package testutil

import (
"github.com/cosmos/cosmos-sdk/runtime"
_ "github.com/cosmos/cosmos-sdk/x/auth" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/bank" // import as blank for app wiring
Expand Down Expand Up @@ -61,7 +60,6 @@ var AppConfig = appconfig.Compose(&appv1alpha1.Config{
evidencetypes.ModuleName,
paramstypes.ModuleName,
consensustypes.ModuleName,
runtime.ModuleName,
},
}),
},
Expand Down
2 changes: 0 additions & 2 deletions x/feegrant/testutil/app_config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package testutil

import (
"github.com/cosmos/cosmos-sdk/runtime"
_ "github.com/cosmos/cosmos-sdk/x/auth" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/auth/vesting" // import as blank for app wiring
Expand Down Expand Up @@ -62,7 +61,6 @@ var AppConfig = appconfig.Compose(&appv1alpha1.Config{
paramstypes.ModuleName,
vestingtypes.ModuleName,
consensustypes.ModuleName,
runtime.ModuleName,
},
}),
},
Expand Down
2 changes: 0 additions & 2 deletions x/group/testutil/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"google.golang.org/protobuf/types/known/durationpb"

"github.com/cosmos/cosmos-sdk/runtime"
_ "github.com/cosmos/cosmos-sdk/x/auth" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/authz" // import as blank for app wiring
Expand Down Expand Up @@ -64,7 +63,6 @@ var AppConfig = appconfig.Compose(&appv1alpha1.Config{
group.ModuleName,
paramstypes.ModuleName,
consensustypes.ModuleName,
runtime.ModuleName,
},
}),
},
Expand Down
2 changes: 0 additions & 2 deletions x/mint/testutil/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package testutil

import (
"cosmossdk.io/core/appconfig"
"github.com/cosmos/cosmos-sdk/runtime"
_ "github.com/cosmos/cosmos-sdk/x/auth" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/bank" // import as blank for app wiring
Expand Down Expand Up @@ -55,7 +54,6 @@ var AppConfig = appconfig.Compose(&appv1alpha1.Config{
genutiltypes.ModuleName,
paramstypes.ModuleName,
consensustypes.ModuleName,
runtime.ModuleName,
},
}),
},
Expand Down
2 changes: 0 additions & 2 deletions x/nft/testutil/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package testutil

import (
"cosmossdk.io/core/appconfig"
"github.com/cosmos/cosmos-sdk/runtime"
_ "github.com/cosmos/cosmos-sdk/x/auth" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/bank" // import as blank for app wiring
Expand Down Expand Up @@ -59,7 +58,6 @@ var AppConfig = appconfig.Compose(&appv1alpha1.Config{
nft.ModuleName,
paramstypes.ModuleName,
consensustypes.ModuleName,
runtime.ModuleName,
},
}),
},
Expand Down
2 changes: 0 additions & 2 deletions x/params/testutil/app_config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package testutil

import (
"github.com/cosmos/cosmos-sdk/runtime"
_ "github.com/cosmos/cosmos-sdk/x/auth" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/bank" // import as blank for app wiring
Expand Down Expand Up @@ -50,7 +49,6 @@ var AppConfig = appconfig.Compose(&appv1alpha1.Config{
genutiltypes.ModuleName,
paramstypes.ModuleName,
consensustypes.ModuleName,
runtime.ModuleName,
},
}),
},
Expand Down
2 changes: 0 additions & 2 deletions x/slashing/testutil/app_config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package testutil

import (
"github.com/cosmos/cosmos-sdk/runtime"
_ "github.com/cosmos/cosmos-sdk/x/auth" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/bank" // import as blank for app wiring
Expand Down Expand Up @@ -65,7 +64,6 @@ var AppConfig = appconfig.Compose(&appv1alpha1.Config{
genutiltypes.ModuleName,
paramstypes.ModuleName,
consensustypes.ModuleName,
runtime.ModuleName,
},
}),
},
Expand Down
2 changes: 0 additions & 2 deletions x/staking/testutil/app_config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package testutil

import (
"github.com/cosmos/cosmos-sdk/runtime"
_ "github.com/cosmos/cosmos-sdk/x/auth" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring
_ "github.com/cosmos/cosmos-sdk/x/bank" // import as blank for app wiring
Expand Down Expand Up @@ -65,7 +64,6 @@ var AppConfig = appconfig.Compose(&appv1alpha1.Config{
genutiltypes.ModuleName,
paramstypes.ModuleName,
consensustypes.ModuleName,
runtime.ModuleName,
},
}),
},
Expand Down

0 comments on commit 461cf87

Please sign in to comment.