Skip to content

Commit

Permalink
fix(runtime): allow to properly register non app wiring modules (#17284)
Browse files Browse the repository at this point in the history
(cherry picked from commit 60198f0)

# Conflicts:
#	CHANGELOG.md
#	runtime/app.go
#	runtime/module.go
#	scripts/init-simapp.sh
  • Loading branch information
julienrbrt authored and mergify[bot] committed Aug 7, 2023
1 parent 4554776 commit ab54d9e
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

<<<<<<< HEAD
=======
* (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.
>>>>>>> 60198f077 (fix(runtime): allow to properly register non app wiring modules (#17284))
* (baseapp) [#17159](https://github.com/cosmos/cosmos-sdk/pull/17159) Validators can propose blocks that exceed the gas limit.
* (baseapp) [#16547](https://github.com/cosmos/cosmos-sdk/pull/16547) Ensure a transaction's gas limit cannot exceed the block gas limit.
* (x/gov,x/group) [#17220](https://github.com/cosmos/cosmos-sdk/pull/17220) Do not try validate `msgURL` as web URL in `draft-proposal` command.
Expand Down
25 changes: 25 additions & 0 deletions docs/docs/building-apps/01-app-go-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,31 @@ More information on how work `depinject.Configs` and `depinject.Supply` can be f
https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/simapp/app_v2.go#L186-L216
```

### Registering 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
// ....
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)
}
// ....
```

:::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
Expand Down
25 changes: 25 additions & 0 deletions runtime/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import (

runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1"
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
<<<<<<< HEAD

Check failure on line 12 in runtime/app.go

View workflow job for this annotation

GitHub Actions / golangci-lint

expected 'STRING', found '<<' (typecheck)

Check failure on line 12 in runtime/app.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected 'STRING', found '<<'

Check failure on line 12 in runtime/app.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected 'STRING', found '<<'

Check failure on line 12 in runtime/app.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected 'STRING', found '<<'

Check failure on line 12 in runtime/app.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected ';', found '<<'
=======
"cosmossdk.io/core/appmodule"
"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"
>>>>>>> 60198f077 (fix(runtime): allow to properly register non app wiring modules (#17284))

Check failure on line 17 in runtime/app.go

View workflow job for this annotation

GitHub Actions / golangci-lint

illegal character U+0023 '#' (typecheck)

Check failure on line 17 in runtime/app.go

View workflow job for this annotation

GitHub Actions / dependency-review

illegal character U+0023 '#'

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -72,7 +78,26 @@ func (a *App) RegisterModules(modules ...module.AppModule) error {
appModule.RegisterInterfaces(a.interfaceRegistry)
appModule.RegisterLegacyAminoCodec(a.amino)

if module, ok := appModule.(module.HasServices); ok {

Check failure on line 81 in runtime/app.go

View workflow job for this annotation

GitHub Actions / golangci-lint

expected 'STRING', found 'if' (typecheck)
module.RegisterServices(a.configurator)
} else if module, ok := appModule.(appmodule.HasServices); ok {

Check failure on line 83 in runtime/app.go

View workflow job for this annotation

GitHub Actions / golangci-lint

expected 'STRING', found 'if' (typecheck)
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 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...)

return nil
}

Expand Down
27 changes: 27 additions & 0 deletions runtime/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,33 @@ func SetupAppBuilder(inputs AppInputs) {
}
}

<<<<<<< HEAD
=======
func ProvideInterfaceRegistry(addressCodec address.Codec, validatorAddressCodec ValidatorAddressCodec, customGetSigners []signing.CustomGetSigner) (codectypes.InterfaceRegistry, error) {
signingOptions := signing.Options{
AddressCodec: addressCodec,
ValidatorAddressCodec: validatorAddressCodec,
}
for _, signer := range customGetSigners {
signingOptions.DefineCustomGetSigners(signer.MsgType, signer.Fn)
}

interfaceRegistry, err := codectypes.NewInterfaceRegistryWithOptions(codectypes.InterfaceRegistryOptions{
ProtoFiles: proto.HybridResolver,
SigningOptions: signingOptions,
})
if err != nil {
return nil, err
}

if err := interfaceRegistry.SigningContext().Validate(); err != nil {
return nil, err
}

return interfaceRegistry, nil
}

>>>>>>> 60198f077 (fix(runtime): allow to properly register non app wiring modules (#17284))
func registerStoreKey(wrapper *AppBuilder, key storetypes.StoreKey) {
wrapper.app.storeKeys = append(wrapper.app.storeKeys, key)
}
Expand Down
17 changes: 17 additions & 0 deletions scripts/init-simapp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

SIMD_BIN=${SIMD_BIN:=$(which simd 2>/dev/null)}

if [ -z "$SIMD_BIN" ]; then echo "SIMD_BIN is not set. Make sure to run make install before"; exit 1; fi
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
$SIMD_BIN genesis add-genesis-account alice 5000000000stake --keyring-backend test
$SIMD_BIN genesis add-genesis-account bob 5000000000stake --keyring-backend test
$SIMD_BIN genesis gentx alice 1000000stake --chain-id demo
$SIMD_BIN genesis collect-gentxs

0 comments on commit ab54d9e

Please sign in to comment.