From 4e2196fcc3aea0adbdd8e5aee5e5bc855779de0e Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 8 Dec 2022 23:08:40 +0100 Subject: [PATCH] fix: app config and simapp (v1,v2) fixes (#14209) --- client/grpc_query_test.go | 2 +- client/v2/go.mod | 2 +- client/v2/go.sum | 4 +- core/go.mod | 2 +- core/go.sum | 4 +- go.mod | 2 +- go.sum | 4 +- orm/go.mod | 2 +- orm/go.sum | 4 +- runtime/app.go | 25 ++++++++--- runtime/builder.go | 9 ++-- runtime/module.go | 3 +- simapp/app.go | 28 ++++++++++-- simapp/app_config.go | 21 +++++++++ simapp/app_v2.go | 86 ++++++++++-------------------------- simapp/genesis.go | 7 --- simapp/go.mod | 2 +- simapp/go.sum | 4 +- simapp/state.go | 3 +- simapp/test_helpers.go | 8 ++-- tests/go.mod | 2 +- tests/go.sum | 4 +- testutil/sims/app_helpers.go | 2 +- tools/rosetta/go.mod | 2 +- tools/rosetta/go.sum | 4 +- tx/go.mod | 2 +- tx/go.sum | 4 +- 27 files changed, 129 insertions(+), 113 deletions(-) diff --git a/client/grpc_query_test.go b/client/grpc_query_test.go index b0b2b0afbc..bc0dbeab1e 100644 --- a/client/grpc_query_test.go +++ b/client/grpc_query_test.go @@ -70,7 +70,7 @@ func (s *IntegrationTestSuite) SetupSuite() { Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(s.genesisAccountBalance))), } - genesisState, err := sims.GenesisStateWithValSet(cdc, appBuilder.DefaultGenesis(), valSet, []authtypes.GenesisAccount{acc}, balance) + genesisState, err := sims.GenesisStateWithValSet(cdc, app.DefaultGenesis(), valSet, []authtypes.GenesisAccount{acc}, balance) s.NoError(err) stateBytes, err := tmjson.MarshalIndent(genesisState, "", " ") diff --git a/client/v2/go.mod b/client/v2/go.mod index 528585f194..a93e9bb609 100644 --- a/client/v2/go.mod +++ b/client/v2/go.mod @@ -3,7 +3,7 @@ module cosmossdk.io/client/v2 go 1.19 require ( - cosmossdk.io/api v0.2.5 + cosmossdk.io/api v0.2.6 cosmossdk.io/core v0.3.2 github.com/cosmos/cosmos-proto v1.0.0-beta.1 github.com/iancoleman/strcase v0.2.0 diff --git a/client/v2/go.sum b/client/v2/go.sum index d4c908ebcd..56dceb9d43 100644 --- a/client/v2/go.sum +++ b/client/v2/go.sum @@ -1,5 +1,5 @@ -cosmossdk.io/api v0.2.5 h1:XKq7CAxTWs7JObceQKkjdI9J+aLB8ofXDGBEaPcPsks= -cosmossdk.io/api v0.2.5/go.mod h1:vxhlMTeKWgQUaanTHPq7/vR3dkhhJ6pOgXK0EIBrBYw= +cosmossdk.io/api v0.2.6 h1:AoNwaLLapcLsphhMK6+o0kZl+D6MMUaHVqSdwinASGU= +cosmossdk.io/api v0.2.6/go.mod h1:u/d+GAxil0nWpl1XnQL8nkziQDIWuBDhv8VnDm/s6dI= cosmossdk.io/core v0.3.2 h1:KlQIufpJHJvOs7YLGTZsZcCo1WlkencDXepsr8STKZQ= cosmossdk.io/core v0.3.2/go.mod h1:CO7vbe+evrBvHc0setFHL/u7nlY7HJGzdRSBkT/sirc= cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z+zfw= diff --git a/core/go.mod b/core/go.mod index c85a4b1486..c8842ba30a 100644 --- a/core/go.mod +++ b/core/go.mod @@ -3,7 +3,7 @@ module cosmossdk.io/core go 1.19 require ( - cosmossdk.io/api v0.2.5 + cosmossdk.io/api v0.2.6 cosmossdk.io/depinject v1.0.0-alpha.3 cosmossdk.io/math v1.0.0-beta.4 github.com/cosmos/cosmos-proto v1.0.0-beta.1 diff --git a/core/go.sum b/core/go.sum index 279b87f604..29c3fa11bf 100644 --- a/core/go.sum +++ b/core/go.sum @@ -1,5 +1,5 @@ -cosmossdk.io/api v0.2.5 h1:XKq7CAxTWs7JObceQKkjdI9J+aLB8ofXDGBEaPcPsks= -cosmossdk.io/api v0.2.5/go.mod h1:vxhlMTeKWgQUaanTHPq7/vR3dkhhJ6pOgXK0EIBrBYw= +cosmossdk.io/api v0.2.6 h1:AoNwaLLapcLsphhMK6+o0kZl+D6MMUaHVqSdwinASGU= +cosmossdk.io/api v0.2.6/go.mod h1:u/d+GAxil0nWpl1XnQL8nkziQDIWuBDhv8VnDm/s6dI= cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z+zfw= cosmossdk.io/depinject v1.0.0-alpha.3/go.mod h1:eRbcdQ7MRpIPEM5YUJh8k97nxHpYbc3sMUnEtt8HPWU= cosmossdk.io/math v1.0.0-beta.4 h1:JtKedVLGzA0vv84xjYmZ75RKG35Kf2WwcFu8IjRkIIw= diff --git a/go.mod b/go.mod index d3fe05f275..1d474e7e49 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ go 1.19 module github.com/cosmos/cosmos-sdk require ( - cosmossdk.io/api v0.2.5 + cosmossdk.io/api v0.2.6 cosmossdk.io/core v0.3.2 cosmossdk.io/depinject v1.0.0-alpha.3 cosmossdk.io/errors v1.0.0-beta.7 diff --git a/go.sum b/go.sum index c0817bf62a..dcae9daf7f 100644 --- a/go.sum +++ b/go.sum @@ -46,8 +46,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= cloud.google.com/go/storage v1.27.0 h1:YOO045NZI9RKfCj1c5A/ZtuuENUc8OAW+gHdGnDgyMQ= cloud.google.com/go/storage v1.27.0/go.mod h1:x9DOL8TK/ygDUMieqwfhdpQryTeEkhGKMi80i/iqR2s= -cosmossdk.io/api v0.2.5 h1:XKq7CAxTWs7JObceQKkjdI9J+aLB8ofXDGBEaPcPsks= -cosmossdk.io/api v0.2.5/go.mod h1:vxhlMTeKWgQUaanTHPq7/vR3dkhhJ6pOgXK0EIBrBYw= +cosmossdk.io/api v0.2.6 h1:AoNwaLLapcLsphhMK6+o0kZl+D6MMUaHVqSdwinASGU= +cosmossdk.io/api v0.2.6/go.mod h1:u/d+GAxil0nWpl1XnQL8nkziQDIWuBDhv8VnDm/s6dI= cosmossdk.io/core v0.3.2 h1:KlQIufpJHJvOs7YLGTZsZcCo1WlkencDXepsr8STKZQ= cosmossdk.io/core v0.3.2/go.mod h1:CO7vbe+evrBvHc0setFHL/u7nlY7HJGzdRSBkT/sirc= cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z+zfw= diff --git a/orm/go.mod b/orm/go.mod index b27963c345..6129761ae0 100644 --- a/orm/go.mod +++ b/orm/go.mod @@ -3,7 +3,7 @@ module github.com/cosmos/cosmos-sdk/orm go 1.19 require ( - cosmossdk.io/api v0.2.5 + cosmossdk.io/api v0.2.6 cosmossdk.io/errors v1.0.0-beta.7 github.com/cosmos/cosmos-proto v1.0.0-beta.1 github.com/golang/mock v1.6.0 diff --git a/orm/go.sum b/orm/go.sum index 229812d74c..5e28372a1e 100644 --- a/orm/go.sum +++ b/orm/go.sum @@ -1,5 +1,5 @@ -cosmossdk.io/api v0.2.5 h1:XKq7CAxTWs7JObceQKkjdI9J+aLB8ofXDGBEaPcPsks= -cosmossdk.io/api v0.2.5/go.mod h1:vxhlMTeKWgQUaanTHPq7/vR3dkhhJ6pOgXK0EIBrBYw= +cosmossdk.io/api v0.2.6 h1:AoNwaLLapcLsphhMK6+o0kZl+D6MMUaHVqSdwinASGU= +cosmossdk.io/api v0.2.6/go.mod h1:u/d+GAxil0nWpl1XnQL8nkziQDIWuBDhv8VnDm/s6dI= cosmossdk.io/errors v1.0.0-beta.7 h1:gypHW76pTQGVnHKo6QBkb4yFOJjC+sUGRc5Al3Odj1w= cosmossdk.io/errors v1.0.0-beta.7/go.mod h1:mz6FQMJRku4bY7aqS/Gwfcmr/ue91roMEKAmDUDpBfE= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= diff --git a/runtime/app.go b/runtime/app.go index 75e412744b..5dc45eb9c4 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -76,14 +76,10 @@ func (a *App) RegisterModules(modules ...module.AppModule) error { // Load finishes all initialization operations and loads the app. func (a *App) Load(loadLatest bool) error { // register runtime module services - err := a.registerRuntimeServices() - if err != nil { + if err := a.registerRuntimeServices(); err != nil { return err } - a.configurator = module.NewConfigurator(a.cdc, a.MsgServiceRouter(), a.GRPCQueryRouter()) - a.ModuleManager.RegisterServices(a.configurator) - if len(a.config.InitGenesis) != 0 { a.ModuleManager.SetOrderInitGenesis(a.config.InitGenesis...) a.SetInitChainer(a.InitChainer) @@ -105,6 +101,10 @@ func (a *App) Load(loadLatest bool) error { a.SetEndBlocker(a.EndBlocker) } + if len(a.config.OrderMigrations) != 0 { + a.ModuleManager.SetOrderMigrations(a.config.OrderMigrations...) + } + if loadLatest { if err := a.LoadLatestVersion(); err != nil { return err @@ -173,6 +173,21 @@ func (a *App) Configurator() module.Configurator { return a.configurator } +// LoadHeight loads a particular height +func (a *App) LoadHeight(height int64) error { + return a.LoadVersion(height) +} + +// DefaultGenesis returns a default genesis from the registered AppModuleBasic's. +func (a *App) DefaultGenesis() map[string]json.RawMessage { + return a.basicManager.DefaultGenesis(a.cdc) +} + +// GetStoreKeys returns all the keys stored store keys. +func (a *App) GetStoreKeys() []storetypes.StoreKey { + return a.storeKeys +} + // UnsafeFindStoreKey fetches a registered StoreKey from the App in linear time. // // NOTE: This should only be used in testing. diff --git a/runtime/builder.go b/runtime/builder.go index f73805c17c..85e4545497 100644 --- a/runtime/builder.go +++ b/runtime/builder.go @@ -8,6 +8,7 @@ import ( dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/version" ) @@ -18,10 +19,9 @@ type AppBuilder struct { app *App } -// DefaultGenesis returns a default genesis from the registered -// AppModuleBasic's. +// DefaultGenesis returns a default genesis from the registered AppModuleBasic's. func (a *AppBuilder) DefaultGenesis() map[string]json.RawMessage { - return a.app.basicManager.DefaultGenesis(a.app.cdc) + return a.app.DefaultGenesis() } // Build builds an *App instance. @@ -43,5 +43,8 @@ func (a *AppBuilder) Build( bApp.MountStores(a.app.storeKeys...) a.app.BaseApp = bApp + a.app.configurator = module.NewConfigurator(a.app.cdc, a.app.MsgServiceRouter(), a.app.GRPCQueryRouter()) + a.app.ModuleManager.RegisterServices(a.app.configurator) + return a.app } diff --git a/runtime/module.go b/runtime/module.go index d19f8df801..dac1065337 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -81,11 +81,10 @@ type AppInputs struct { } func SetupAppBuilder(inputs AppInputs) { - mm := module.NewManagerFromMap(inputs.Modules) app := inputs.AppBuilder.app app.baseAppOptions = inputs.BaseAppOptions app.config = inputs.Config - app.ModuleManager = mm + app.ModuleManager = module.NewManagerFromMap(inputs.Modules) app.appConfig = inputs.AppConfig for name, mod := range inputs.Modules { diff --git a/simapp/app.go b/simapp/app.go index d8b04f4d75..40374b46bd 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -228,6 +228,22 @@ func NewSimApp( interfaceRegistry := encodingConfig.InterfaceRegistry txConfig := encodingConfig.TxConfig + // Below we could construct and set an application specific mempool and ABCI 1.0 Prepare and Process Proposal + // handlers. These defaults are already set in the SDK's BaseApp, this shows an example of how to override + // them. + // + // nonceMempool := mempool.NewSenderNonceMempool() + // mempoolOpt := baseapp.SetMempool(nonceMempool) + // prepareOpt := func(app *baseapp.BaseApp) { + // app.SetPrepareProposal(app.DefaultPrepareProposal()) + // } + // processOpt := func(app *baseapp.BaseApp) { + // app.SetProcessProposal(app.DefaultProcessProposal()) + // } + // + // Further down we'd set the options in the AppBuilder like below. + // baseAppOptions = append(baseAppOptions, mempoolOpt, prepareOpt, processOpt) + bApp := baseapp.NewBaseApp(appName, logger, db, txConfig.TxDecoder(), baseAppOptions...) bApp.SetCommitMultiStoreTracer(traceStore) bApp.SetVersion(version.Version) @@ -353,9 +369,6 @@ func NewSimApp( // Set legacy router for backwards compatibility with gov v1beta1 govKeeper.SetLegacyRouter(govRouter) - // RegisterUpgradeHandlers is used for registering any on-chain upgrades. - app.RegisterUpgradeHandlers() - app.NFTKeeper = nftkeeper.NewKeeper(keys[nftkeeper.StoreKey], appCodec, app.AccountKeeper, app.BankKeeper) // create evidence keeper with router @@ -442,6 +455,10 @@ func NewSimApp( app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter()) app.ModuleManager.RegisterServices(app.configurator) + // RegisterUpgradeHandlers is used for registering any on-chain upgrades. + // Make sure it's called after `app.ModuleManager` and `app.configurator` are set. + app.RegisterUpgradeHandlers() + autocliv1.RegisterQueryServer(app.GRPCQueryRouter(), runtimeservices.NewAutoCLIQueryService(app.ModuleManager.Modules)) reflectionSvc, err := runtimeservices.NewReflectionService() @@ -591,6 +608,11 @@ func (app *SimApp) TxConfig() client.TxConfig { return app.txConfig } +// DefaultGenesis returns a default genesis from the registered AppModuleBasic's. +func (a *SimApp) DefaultGenesis() map[string]json.RawMessage { + return ModuleBasics.DefaultGenesis(a.appCodec) +} + // GetKey returns the KVStoreKey for the provided store key. // // NOTE: This is solely to be used for testing purposes. diff --git a/simapp/app_config.go b/simapp/app_config.go index e3c1c261d8..2508335585 100644 --- a/simapp/app_config.go +++ b/simapp/app_config.go @@ -50,6 +50,21 @@ 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, + } + // module account permissions moduleAccPerms = []*authmodulev1.ModuleAccountPermission{ {Account: authtypes.FeeCollectorName}, @@ -133,6 +148,12 @@ var ( KvStoreKey: "acc", }, }, + // InitGenesis: genesisModuleOrder, + // When ExportGenesis is not specified, the export genesis module order + // is equal to the init genesis order + // ExportGenesis: genesisModuleOrder, + // Uncomment if you want to set a custom migration order here. + // OrderMigrations: nil, }), }, { diff --git a/simapp/app_v2.go b/simapp/app_v2.go index 9dcba3bb85..14d4cdac98 100644 --- a/simapp/app_v2.go +++ b/simapp/app_v2.go @@ -35,29 +35,20 @@ import ( _ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import for side-effects 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" consensus "github.com/cosmos/cosmos-sdk/x/consensus" consensuskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" - consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" "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" distr "github.com/cosmos/cosmos-sdk/x/distribution" distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" - distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" "github.com/cosmos/cosmos-sdk/x/evidence" evidencekeeper "github.com/cosmos/cosmos-sdk/x/evidence/keeper" - evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" - "github.com/cosmos/cosmos-sdk/x/feegrant" feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module" "github.com/cosmos/cosmos-sdk/x/genutil" @@ -65,14 +56,10 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov" govclient "github.com/cosmos/cosmos-sdk/x/gov/client" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/cosmos/cosmos-sdk/x/group" groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper" groupmodule "github.com/cosmos/cosmos-sdk/x/group/module" "github.com/cosmos/cosmos-sdk/x/mint" mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" - minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - "github.com/cosmos/cosmos-sdk/x/nft" nftkeeper "github.com/cosmos/cosmos-sdk/x/nft/keeper" nftmodule "github.com/cosmos/cosmos-sdk/x/nft/module" "github.com/cosmos/cosmos-sdk/x/params" @@ -81,14 +68,11 @@ import ( paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cosmos/cosmos-sdk/x/slashing" slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" - slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/cosmos/cosmos-sdk/x/upgrade" upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) var ( @@ -142,9 +126,6 @@ type SimApp struct { txConfig client.TxConfig interfaceRegistry codectypes.InterfaceRegistry - // keys to access the substores - keys map[string]*storetypes.KVStoreKey - // keepers AccountKeeper authkeeper.AccountKeeper BankKeeper bankkeeper.Keeper @@ -190,20 +171,20 @@ func NewSimApp( app = &SimApp{} appBuilder *runtime.AppBuilder // Below we could construct and set an application specific mempool and ABCI 1.0 Prepare and Process Proposal - // handlers. These defaults are already set in the SDK's BaseApp, this shows an example of how to override + // handlers. These defaults are already set in the SDK's BaseApp, this shows an example of how to override // them. // - //nonceMempool = mempool.NewNonceMempool() - //mempoolOpt = baseapp.SetMempool(nonceMempool) - //prepareOpt = func(app *baseapp.BaseApp) { - // app.SetPrepareProposal(app.DefaultPrepareProposal()) - //} - //processOpt = func(app *baseapp.BaseApp) { - // app.SetProcessProposal(app.DefaultProcessProposal()) - //} + // nonceMempool = mempool.NewSenderNonceMempool() + // mempoolOpt = baseapp.SetMempool(nonceMempool) + // prepareOpt = func(app *baseapp.BaseApp) { + // app.SetPrepareProposal(app.DefaultPrepareProposal()) + // } + // processOpt = func(app *baseapp.BaseApp) { + // app.SetProcessProposal(app.DefaultProcessProposal()) + // } // // Further down we'd set the options in the AppBuilder like below. - //baseAppOptions = append(baseAppOptions, mempoolOpt, prepareOpt, processOpt) + // baseAppOptions = append(baseAppOptions, mempoolOpt, prepareOpt, processOpt) // merge the AppConfig and other configuration in one config appConfig = depinject.Configs( @@ -268,39 +249,22 @@ func NewSimApp( app.App = appBuilder.Build(logger, db, traceStore, baseAppOptions...) // load state streaming if enabled - if _, _, err := streaming.LoadStreamingServices(app.App.BaseApp, appOpts, app.appCodec, logger, app.keys); err != nil { + if _, _, err := streaming.LoadStreamingServices(app.App.BaseApp, appOpts, app.appCodec, logger, app.kvStoreKeys()); err != nil { fmt.Printf("failed to load state streaming: %s", err) os.Exit(1) } /**** Module Options ****/ - // Sets the version setter for the upgrade module + // Set upgrade module options app.UpgradeKeeper.SetVersionSetter(app.BaseApp) - // 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, - } app.ModuleManager.SetOrderInitGenesis(genesisModuleOrder...) app.ModuleManager.SetOrderExportGenesis(genesisModuleOrder...) - // Uncomment if you want to set a custom migration order here. - // app.ModuleManager.SetOrderMigrations(custom order) - app.ModuleManager.RegisterInvariants(app.CrisisKeeper) // RegisterUpgradeHandlers is used for registering any on-chain upgrades. - // Make sure it's called after `app.ModuleManager` and `app.configurator` are set. app.RegisterUpgradeHandlers() // add test gRPC service for testing gRPC queries in isolation @@ -317,9 +281,6 @@ func NewSimApp( app.sm.RegisterStoreDecoders() - // initialize stores - app.MountKVStores(app.keys) - // initialize BaseApp app.SetInitChainer(app.InitChainer) @@ -339,11 +300,6 @@ func (app *SimApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci. return app.App.InitChainer(ctx, req) } -// LoadHeight loads a particular height -func (app *SimApp) LoadHeight(height int64) error { - return app.LoadVersion(height) -} - // LegacyAmino returns SimApp's amino codec. // // NOTE: This is solely to be used for testing purposes as it may be desirable @@ -374,11 +330,6 @@ func (app *SimApp) TxConfig() client.TxConfig { // // NOTE: This is solely to be used for testing purposes. func (app *SimApp) GetKey(storeKey string) *storetypes.KVStoreKey { - kvsk := app.keys[storeKey] - if kvsk != nil { - return kvsk - } - sk := app.UnsafeFindStoreKey(storeKey) kvStoreKey, ok := sk.(*storetypes.KVStoreKey) if !ok { @@ -387,6 +338,17 @@ func (app *SimApp) GetKey(storeKey string) *storetypes.KVStoreKey { return kvStoreKey } +func (app *SimApp) kvStoreKeys() map[string]*storetypes.KVStoreKey { + keys := make(map[string]*storetypes.KVStoreKey) + for _, k := range app.GetStoreKeys() { + if kv, ok := k.(*storetypes.KVStoreKey); ok { + keys[kv.Name()] = kv + } + } + + return keys +} + // GetSubspace returns a param subspace for a given module name. // // NOTE: This is solely to be used for testing purposes. @@ -404,7 +366,7 @@ func (app *SimApp) SimulationManager() *module.SimulationManager { // API server. func (app *SimApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) { app.App.RegisterAPIRoutes(apiSvr, apiConfig) - // register swagger API from root so that other applications can override easily + // register swagger API in app.go so that other applications can override easily if err := server.RegisterSwaggerAPI(apiSvr.ClientCtx, apiSvr.Router, apiConfig.Swagger); err != nil { panic(err) } diff --git a/simapp/genesis.go b/simapp/genesis.go index a002aead9a..69fa46b90e 100644 --- a/simapp/genesis.go +++ b/simapp/genesis.go @@ -2,8 +2,6 @@ package simapp import ( "encoding/json" - - "github.com/cosmos/cosmos-sdk/codec" ) // GenesisState of the blockchain is represented here as a map of raw json @@ -14,8 +12,3 @@ import ( // the ModuleBasicManager which populates json from each BasicModule // object provided to it during init. type GenesisState map[string]json.RawMessage - -// NewDefaultGenesisState generates the default state for the application. -func NewDefaultGenesisState(cdc codec.JSONCodec) GenesisState { - return ModuleBasics.DefaultGenesis(cdc) -} diff --git a/simapp/go.mod b/simapp/go.mod index 26a2732f82..504e9c28a1 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -3,7 +3,7 @@ module cosmossdk.io/simapp go 1.19 require ( - cosmossdk.io/api v0.2.5 + cosmossdk.io/api v0.2.6 cosmossdk.io/core v0.3.2 cosmossdk.io/depinject v1.0.0-alpha.3 cosmossdk.io/math v1.0.0-beta.4 diff --git a/simapp/go.sum b/simapp/go.sum index 5428b83a93..70630103c4 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -46,8 +46,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= cloud.google.com/go/storage v1.27.0 h1:YOO045NZI9RKfCj1c5A/ZtuuENUc8OAW+gHdGnDgyMQ= cloud.google.com/go/storage v1.27.0/go.mod h1:x9DOL8TK/ygDUMieqwfhdpQryTeEkhGKMi80i/iqR2s= -cosmossdk.io/api v0.2.5 h1:XKq7CAxTWs7JObceQKkjdI9J+aLB8ofXDGBEaPcPsks= -cosmossdk.io/api v0.2.5/go.mod h1:vxhlMTeKWgQUaanTHPq7/vR3dkhhJ6pOgXK0EIBrBYw= +cosmossdk.io/api v0.2.6 h1:AoNwaLLapcLsphhMK6+o0kZl+D6MMUaHVqSdwinASGU= +cosmossdk.io/api v0.2.6/go.mod h1:u/d+GAxil0nWpl1XnQL8nkziQDIWuBDhv8VnDm/s6dI= cosmossdk.io/core v0.3.2 h1:KlQIufpJHJvOs7YLGTZsZcCo1WlkencDXepsr8STKZQ= cosmossdk.io/core v0.3.2/go.mod h1:CO7vbe+evrBvHc0setFHL/u7nlY7HJGzdRSBkT/sirc= cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z+zfw= diff --git a/simapp/state.go b/simapp/state.go index 29b3259ffe..f872b9c22a 100644 --- a/simapp/state.go +++ b/simapp/state.go @@ -144,7 +144,8 @@ func AppStateRandomizedFn( accs []simtypes.Account, genesisTimestamp time.Time, appParams simtypes.AppParams, ) (json.RawMessage, []simtypes.Account) { numAccs := int64(len(accs)) - genesisState := NewDefaultGenesisState(cdc) + // TODO - in case runtime.RegisterModules(...) is used, the genesis state of the module won't be reflected here + genesisState := ModuleBasics.DefaultGenesis(cdc) // generate a random amount of initial stake coins and a random initial // number of bonded accounts diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 402e8c014f..3016d57e7f 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -50,7 +50,7 @@ func setup(withGenesis bool, invCheckPeriod uint) (*SimApp, GenesisState) { app := NewSimApp(log.NewNopLogger(), db, nil, true, appOptions) if withGenesis { - return app, NewDefaultGenesisState(app.AppCodec()) + return app, app.DefaultGenesis() } return app, GenesisState{} } @@ -75,7 +75,7 @@ func NewSimappWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOptio } app := NewSimApp(options.Logger, options.DB, nil, true, options.AppOpts) - genesisState := NewDefaultGenesisState(app.appCodec) + genesisState := app.DefaultGenesis() genesisState, err = simtestutil.GenesisStateWithValSet(app.AppCodec(), genesisState, valSet, []authtypes.GenesisAccount{acc}, balance) require.NoError(t, err) @@ -180,7 +180,7 @@ func GenesisStateWithSingleValidator(t *testing.T, app *SimApp) GenesisState { }, } - genesisState := NewDefaultGenesisState(app.appCodec) + genesisState := app.DefaultGenesis() genesisState, err = simtestutil.GenesisStateWithValSet(app.AppCodec(), genesisState, valSet, []authtypes.GenesisAccount{acc}, balances...) require.NoError(t, err) @@ -250,7 +250,7 @@ func NewTestNetworkFixture() network.TestFixture { return network.TestFixture{ AppConstructor: appCtr, - GenesisState: ModuleBasics.DefaultGenesis(app.AppCodec()), + GenesisState: app.DefaultGenesis(), EncodingConfig: testutil.TestEncodingConfig{ InterfaceRegistry: app.InterfaceRegistry(), Codec: app.AppCodec(), diff --git a/tests/go.mod b/tests/go.mod index 478e6a8412..ec4bcc97ff 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -3,7 +3,7 @@ module github.com/cosmos/cosmos-sdk/tests go 1.19 require ( - cosmossdk.io/api v0.2.5 + cosmossdk.io/api v0.2.6 cosmossdk.io/depinject v1.0.0-alpha.3 cosmossdk.io/math v1.0.0-beta.4 cosmossdk.io/simapp v0.0.0-00010101000000-000000000000 diff --git a/tests/go.sum b/tests/go.sum index c952b3ab6e..0c40f6dd75 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -46,8 +46,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= cloud.google.com/go/storage v1.27.0 h1:YOO045NZI9RKfCj1c5A/ZtuuENUc8OAW+gHdGnDgyMQ= cloud.google.com/go/storage v1.27.0/go.mod h1:x9DOL8TK/ygDUMieqwfhdpQryTeEkhGKMi80i/iqR2s= -cosmossdk.io/api v0.2.5 h1:XKq7CAxTWs7JObceQKkjdI9J+aLB8ofXDGBEaPcPsks= -cosmossdk.io/api v0.2.5/go.mod h1:vxhlMTeKWgQUaanTHPq7/vR3dkhhJ6pOgXK0EIBrBYw= +cosmossdk.io/api v0.2.6 h1:AoNwaLLapcLsphhMK6+o0kZl+D6MMUaHVqSdwinASGU= +cosmossdk.io/api v0.2.6/go.mod h1:u/d+GAxil0nWpl1XnQL8nkziQDIWuBDhv8VnDm/s6dI= cosmossdk.io/core v0.3.2 h1:KlQIufpJHJvOs7YLGTZsZcCo1WlkencDXepsr8STKZQ= cosmossdk.io/core v0.3.2/go.mod h1:CO7vbe+evrBvHc0setFHL/u7nlY7HJGzdRSBkT/sirc= cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z+zfw= diff --git a/testutil/sims/app_helpers.go b/testutil/sims/app_helpers.go index d73477af72..7bfdc7be59 100644 --- a/testutil/sims/app_helpers.go +++ b/testutil/sims/app_helpers.go @@ -148,7 +148,7 @@ func SetupWithConfiguration(appConfig depinject.Config, startupConfig StartupCon balances = append(balances, banktypes.Balance{Address: ga.GenesisAccount.GetAddress().String(), Coins: ga.Coins}) } - genesisState, err := GenesisStateWithValSet(codec, appBuilder.DefaultGenesis(), valSet, genAccounts, balances...) + genesisState, err := GenesisStateWithValSet(codec, app.DefaultGenesis(), valSet, genAccounts, balances...) if err != nil { return nil, fmt.Errorf("failed to create genesis state: %w", err) } diff --git a/tools/rosetta/go.mod b/tools/rosetta/go.mod index 9e34ff9548..425026b16f 100644 --- a/tools/rosetta/go.mod +++ b/tools/rosetta/go.mod @@ -16,7 +16,7 @@ require ( ) require ( - cosmossdk.io/api v0.2.5 // indirect + cosmossdk.io/api v0.2.6 // indirect cosmossdk.io/core v0.3.2 // indirect cosmossdk.io/depinject v1.0.0-alpha.3 // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect diff --git a/tools/rosetta/go.sum b/tools/rosetta/go.sum index a21b2afd88..95dc5620a2 100644 --- a/tools/rosetta/go.sum +++ b/tools/rosetta/go.sum @@ -35,8 +35,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= -cosmossdk.io/api v0.2.5 h1:XKq7CAxTWs7JObceQKkjdI9J+aLB8ofXDGBEaPcPsks= -cosmossdk.io/api v0.2.5/go.mod h1:vxhlMTeKWgQUaanTHPq7/vR3dkhhJ6pOgXK0EIBrBYw= +cosmossdk.io/api v0.2.6 h1:AoNwaLLapcLsphhMK6+o0kZl+D6MMUaHVqSdwinASGU= +cosmossdk.io/api v0.2.6/go.mod h1:u/d+GAxil0nWpl1XnQL8nkziQDIWuBDhv8VnDm/s6dI= cosmossdk.io/core v0.3.2 h1:KlQIufpJHJvOs7YLGTZsZcCo1WlkencDXepsr8STKZQ= cosmossdk.io/core v0.3.2/go.mod h1:CO7vbe+evrBvHc0setFHL/u7nlY7HJGzdRSBkT/sirc= cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z+zfw= diff --git a/tx/go.mod b/tx/go.mod index 1198506364..d29a3a6615 100644 --- a/tx/go.mod +++ b/tx/go.mod @@ -3,7 +3,7 @@ module cosmossdk.io/tx go 1.19 require ( - cosmossdk.io/api v0.2.5 + cosmossdk.io/api v0.2.6 cosmossdk.io/core v0.3.2 cosmossdk.io/math v1.0.0-beta.4 github.com/cosmos/cosmos-proto v1.0.0-beta.1 diff --git a/tx/go.sum b/tx/go.sum index 92f57df195..774c48d25d 100644 --- a/tx/go.sum +++ b/tx/go.sum @@ -1,5 +1,5 @@ -cosmossdk.io/api v0.2.5 h1:XKq7CAxTWs7JObceQKkjdI9J+aLB8ofXDGBEaPcPsks= -cosmossdk.io/api v0.2.5/go.mod h1:vxhlMTeKWgQUaanTHPq7/vR3dkhhJ6pOgXK0EIBrBYw= +cosmossdk.io/api v0.2.6 h1:AoNwaLLapcLsphhMK6+o0kZl+D6MMUaHVqSdwinASGU= +cosmossdk.io/api v0.2.6/go.mod h1:u/d+GAxil0nWpl1XnQL8nkziQDIWuBDhv8VnDm/s6dI= cosmossdk.io/math v1.0.0-beta.4 h1:JtKedVLGzA0vv84xjYmZ75RKG35Kf2WwcFu8IjRkIIw= cosmossdk.io/math v1.0.0-beta.4/go.mod h1:An0MllWJY6PxibUpnwGk8jOm+a/qIxlKmL5Zyp9NnaM= github.com/cosmos/cosmos-proto v1.0.0-beta.1 h1:iDL5qh++NoXxG8hSy93FdYJut4XfgbShIocllGaXx/0=