Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): add fallbacks for CoreAppModuleBasicAdaptor #16010

Merged
merged 4 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

* (types) [#15958](https://github.com/cosmos/cosmos-sdk/pull/15958) Add `module.NewBasicManagerFromManager` for creating a basic module manager from a module manager.
* (runtime) [#15818](https://github.com/cosmos/cosmos-sdk/pull/15818) Provide logger through `depinject` instead of appBuilder.
* (client) [#15597](https://github.com/cosmos/cosmos-sdk/pull/15597) Add status endpoint for clients.
* (testutil/integration) [#15556](https://github.com/cosmos/cosmos-sdk/pull/15556) Introduce `testutil/integration` package for module integration testing.
Expand Down Expand Up @@ -68,6 +69,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* (simapp) [#15958](https://github.com/cosmos/cosmos-sdk/pull/15958) Refactor SimApp for removing the global basic manager.
* (gov) [#15979](https://github.com/cosmos/cosmos-sdk/pull/15979) Improve gov error message when failing to convert v1 proposal to v1beta1.
* (crypto) [#3129](https://github.com/cosmos/cosmos-sdk/pull/3129) New armor and keyring key derivation uses aead and encryption uses chacha20poly
* (x/slashing) [#15580](https://github.com/cosmos/cosmos-sdk/pull/15580) Refactor the validator's missed block signing window to be a chunked bitmap instead of a "logical" bitmap, significantly reducing the storage footprint.
Expand Down Expand Up @@ -200,7 +202,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* (types) [#15691](https://github.com/cosmos/cosmos-sdk/pull/15691) Make Coin.Validate() check that .Amount is not nil
* (types) [#16010](https://github.com/cosmos/cosmos-sdk/pull/16010) Let `module.CoreAppModuleBasicAdaptor` fallback to legacy genesis handling.
* (types) [#15691](https://github.com/cosmos/cosmos-sdk/pull/15691) Make `Coin.Validate()` check that `.Amount` is not nil.
* (x/auth) [#15059](https://github.com/cosmos/cosmos-sdk/pull/15059) `ante.CountSubKeys` returns 0 when passing a nil `Pubkey`.
* (x/capability) [#15030](https://github.com/cosmos/cosmos-sdk/pull/15030) Prevent `x/capability` from consuming `GasMeter` gas during `InitMemStore`
* (types/coin) [#14739](https://github.com/cosmos/cosmos-sdk/pull/14739) Deprecate the method `Coin.IsEqual` in favour of `Coin.Equal`. The difference between the two methods is that the first one results in a panic when denoms are not equal. This panic lead to unexpected behavior
Expand Down
5 changes: 0 additions & 5 deletions errors/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Features

* [#15989](https://github.com/cosmos/cosmos-sdk/pull/15989) Add `ErrStopIterating` for modules to use for breaking out of iteration.

## v1.0.0

### Features

* [#10779](https://github.com/cosmos/cosmos-sdk/pull/10779) Import code from the `github.com/cosmos/cosmos-sdk/types/errors` package.
* [#11274](https://github.com/cosmos/cosmos-sdk/pull/11274) Add `RegisterWithGRPCCode` function to associate a gRPC error code with errors.

Expand Down
8 changes: 6 additions & 2 deletions orm/model/ormdb/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ type ModuleDB interface {
// GenesisHandler returns an implementation of appmodule.HasGenesis
// to be embedded in or called from app module implementations.
// Ex:
// type Keeper struct {
// type AppModule struct {
Copy link
Member Author

@julienrbrt julienrbrt May 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When not doing like this, I was getting a depinject issue in #15304 (37d2d62)

// appmodule.HasGenesis
// }
//
// func NewKeeper(db ModuleDB) *Keeper {
// return &Keeper{HasGenesis: db.GenesisHandler()}
// return &Keeper{genesisHandler: db.GenesisHandler()}
// }
//
// func NewAppModule(keeper keeper.Keeper) AppModule {
// return AppModule{HasGenesis: keeper.GenesisHandler()}
// }
GenesisHandler() appmodule.HasGenesis

private()
Expand Down
9 changes: 4 additions & 5 deletions runtime/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,10 @@ func SetupAppBuilder(inputs AppInputs) {
continue
}

if basicMod, ok := mod.(module.AppModuleBasic); ok {
app.basicManager[name] = basicMod
basicMod.RegisterInterfaces(inputs.InterfaceRegistry)
basicMod.RegisterLegacyAminoCodec(inputs.LegacyAmino)
}
coreAppModuleBasic := module.CoreAppModuleBasicAdaptor(name, mod)
app.basicManager[name] = coreAppModuleBasic
coreAppModuleBasic.RegisterInterfaces(inputs.InterfaceRegistry)
coreAppModuleBasic.RegisterLegacyAminoCodec(inputs.LegacyAmino)
}
}

Expand Down
23 changes: 21 additions & 2 deletions types/module/core_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type coreAppModuleBasicAdapator struct {
}

// DefaultGenesis implements HasGenesis
func (c coreAppModuleBasicAdapator) DefaultGenesis(codec.JSONCodec) json.RawMessage {
func (c coreAppModuleBasicAdapator) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
if mod, ok := c.module.(appmodule.HasGenesis); ok {
target := genesis.RawJSONTarget{}
err := mod.DefaultGenesis(target.Target())
Expand All @@ -53,6 +53,11 @@ func (c coreAppModuleBasicAdapator) DefaultGenesis(codec.JSONCodec) json.RawMess

return res
}

if mod, ok := c.module.(HasGenesisBasics); ok {
return mod.DefaultGenesis(cdc)
}

return nil
}

Expand All @@ -69,6 +74,10 @@ func (c coreAppModuleBasicAdapator) ValidateGenesis(cdc codec.JSONCodec, txConfi
}
}

if mod, ok := c.module.(HasGenesisBasics); ok {
return mod.ValidateGenesis(cdc, txConfig, bz)
}

return nil
}

Expand All @@ -89,11 +98,16 @@ func (c coreAppModuleBasicAdapator) ExportGenesis(ctx sdk.Context, cdc codec.JSO

return rawJSON
}

if mod, ok := c.module.(HasGenesis); ok {
return mod.ExportGenesis(ctx, cdc)
}

return nil
}

// InitGenesis implements HasGenesis
func (c coreAppModuleBasicAdapator) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, bz json.RawMessage) []abci.ValidatorUpdate {
func (c coreAppModuleBasicAdapator) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.RawMessage) []abci.ValidatorUpdate {
if module, ok := c.module.(appmodule.HasGenesis); ok {
// core API genesis
source, err := genesis.SourceFromRawJSON(bz)
Expand All @@ -106,6 +120,11 @@ func (c coreAppModuleBasicAdapator) InitGenesis(ctx sdk.Context, _ codec.JSONCod
panic(err)
}
}

if mod, ok := c.module.(HasGenesis); ok {
return mod.InitGenesis(ctx, cdc, bz)
}

return nil
}

Expand Down
5 changes: 5 additions & 0 deletions types/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ func NewBasicManagerFromManager(manager *Manager, customModuleBasics map[string]
continue
}

if appModule, ok := module.(appmodule.AppModule); ok {
moduleMap[name] = CoreAppModuleBasicAdaptor(name, appModule)
continue
}

if basicMod, ok := module.(AppModuleBasic); ok {
moduleMap[name] = basicMod
}
Expand Down