From 28232c5f97ed186f546c7d7011aa4418b020be1a Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 4 Aug 2023 01:35:24 +0200 Subject: [PATCH 1/4] fix(runtime): allow to properly register non app wiring modules --- docs/docs/building-apps/01-app-go-v2.md | 20 ++++++++++++++++++++ runtime/app.go | 19 +++++++++++++++++++ runtime/module.go | 3 +-- scripts/init-simapp.sh | 1 + 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/docs/docs/building-apps/01-app-go-v2.md b/docs/docs/building-apps/01-app-go-v2.md index 04754414826..572bc6a4ef7 100644 --- a/docs/docs/building-apps/01-app-go-v2.md +++ b/docs/docs/building-apps/01-app-go-v2.md @@ -118,6 +118,26 @@ More information on how work `depinject.Configs` and `depinject.Supply` can be f https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/app_v2.go#L114-L146 ``` +### Registering non app wiring modules + +Additionally, it is possible to mix app wiring enabled modules with non app wiring modules. +To do so, use the `app.RegisterModules` method to register the modules on your app, as well as `app.RegisterStores` for registering the extra stores needed. + +```go +// .... +app.App = appBuilder.Build(db, traceStore, baseAppOptions...) + +// register module manually +app.RegisterStores(storetypes.NewKVStoreKey(example.ModuleName)) +app.ExampleKeeper = examplekeeper.NewKeeper(app.appCodec, app.AccountKeeper.AddressCodec(), runtime.NewKVStoreService(app.GetKey(example.ModuleName)), authtypes.NewModuleAddress(govtypes.ModuleName).String()) +exampleAppModule := examplemodule.NewAppModule(app.ExampleKeeper) +if err := app.RegisterModules(&exampleAppModule); err != nil { + panic(err) +} + +// .... +``` + ### Complete `app_v2.go` :::tip diff --git a/runtime/app.go b/runtime/app.go index e1ed0da78c0..21fe6e53af5 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -9,6 +9,7 @@ import ( runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" + "cosmossdk.io/core/appmodule" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" @@ -75,7 +76,25 @@ func (a *App) RegisterModules(modules ...module.AppModule) error { appModule.RegisterInterfaces(a.interfaceRegistry) appModule.RegisterLegacyAminoCodec(a.amino) + if module, ok := appModule.(module.HasServices); ok { + module.RegisterServices(a.configurator) + } else if module, ok := appModule.(appmodule.HasServices); ok { + if err := module.RegisterServices(a.configurator); err != nil { + return err + } + } } + + return nil +} + +// RegisterStores registers the provided store keys. +// This method should only be used for integrating with +// modules which are not registered using the app config. +func (a *App) RegisterStores(keys ...storetypes.StoreKey) error { + a.storeKeys = append(a.storeKeys, keys...) + a.MountStores(keys...) + return nil } diff --git a/runtime/module.go b/runtime/module.go index b544167dc02..7b3a54fc784 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -176,8 +176,7 @@ func ProvideInterfaceRegistry(addressCodec address.Codec, validatorAddressCodec return nil, err } - err = interfaceRegistry.SigningContext().Validate() - if err != nil { + if err := interfaceRegistry.SigningContext().Validate(); err != nil { return nil, err } diff --git a/scripts/init-simapp.sh b/scripts/init-simapp.sh index 5db89d2c506..9225e9b1245 100755 --- a/scripts/init-simapp.sh +++ b/scripts/init-simapp.sh @@ -7,6 +7,7 @@ echo "using $SIMD_BIN" if [ -d "$($SIMD_BIN config home)" ]; then rm -r $($SIMD_BIN config home); fi $SIMD_BIN config set client chain-id demo $SIMD_BIN config set client keyring-backend test +$SIMD_BIN config set app api.enable true $SIMD_BIN keys add alice $SIMD_BIN keys add bob $SIMD_BIN init test --chain-id demo From 409cacd3a49221c72d5a1febdd6ce9582fc4feb3 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 4 Aug 2023 01:38:32 +0200 Subject: [PATCH 2/4] changelog --- CHANGELOG.md | 1 + runtime/app.go | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a44429c8dba..fcbac58cd17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +* (runtime) [#17284](https://github.com/cosmos/cosmos-sdk/pull/17284) Properly allow to combine depinject-enabled modules and non-depinject-enabled modules in app v2. * (baseapp) [#17251](https://github.com/cosmos/cosmos-sdk/pull/17251) VerifyVoteExtensions and ExtendVote initialize their own contexts/states, allowing VerifyVoteExtensions being called without ExtendVote. * (x/auth) [#17209](https://github.com/cosmos/cosmos-sdk/pull/17209) Internal error on AccountInfo when account's public key is not set. * (baseapp) [#17159](https://github.com/cosmos/cosmos-sdk/pull/17159) Validators can propose blocks that exceed the gas limit. diff --git a/runtime/app.go b/runtime/app.go index 21fe6e53af5..620b058a118 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -89,8 +89,9 @@ func (a *App) RegisterModules(modules ...module.AppModule) error { } // RegisterStores registers the provided store keys. -// This method should only be used for integrating with -// modules which are not registered using the app config. +// This method should only be used for registering extra stores +// wiich is necessary for modules that not registered using the app config. +// To be used in combination of RegisterModules. func (a *App) RegisterStores(keys ...storetypes.StoreKey) error { a.storeKeys = append(a.storeKeys, keys...) a.MountStores(keys...) From bbd126c05ea37a254d4aad6b564896c57eba39f6 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 4 Aug 2023 01:39:52 +0200 Subject: [PATCH 3/4] word --- docs/docs/building-apps/01-app-go-v2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/building-apps/01-app-go-v2.md b/docs/docs/building-apps/01-app-go-v2.md index 572bc6a4ef7..39556532e14 100644 --- a/docs/docs/building-apps/01-app-go-v2.md +++ b/docs/docs/building-apps/01-app-go-v2.md @@ -120,7 +120,7 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/app_v2.go#L114- ### Registering non app wiring modules -Additionally, it is possible to mix app wiring enabled modules with non app wiring modules. +It is possible to combine app wiring / depinject enabled modules with non app wiring modules. To do so, use the `app.RegisterModules` method to register the modules on your app, as well as `app.RegisterStores` for registering the extra stores needed. ```go From 65b0eb5455eab6517fc1f9eeabe09f648d6b1da3 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 4 Aug 2023 01:45:57 +0200 Subject: [PATCH 4/4] add autocli disclaimer --- docs/docs/building-apps/01-app-go-v2.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/docs/building-apps/01-app-go-v2.md b/docs/docs/building-apps/01-app-go-v2.md index 39556532e14..00b69247181 100644 --- a/docs/docs/building-apps/01-app-go-v2.md +++ b/docs/docs/building-apps/01-app-go-v2.md @@ -138,6 +138,11 @@ if err := app.RegisterModules(&exampleAppModule); err != nil { // .... ``` +:::warning +When using AutoCLI and combining app wiring and non app wiring modules. The AutoCLI options should be manually constructed instead of injected. +Otherwise it will miss the non depinject modules and not register their CLI. +::: + ### Complete `app_v2.go` :::tip