Skip to content

Commit

Permalink
fix(types): add fallbacks for CoreAppModuleBasicAdaptor (#16010)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored May 3, 2023
1 parent 1705615 commit b5c77d6
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 15 deletions.
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 @@ -201,8 +203,9 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* (types) [#16010](https://github.com/cosmos/cosmos-sdk/pull/16010) Let `module.CoreAppModuleBasicAdaptor` fallback to legacy genesis handling.
* (x/group) [#16017](https://github.com/cosmos/cosmos-sdk/pull/16017) Correctly apply account number in group v2 migration.
* (types) [#15691](https://github.com/cosmos/cosmos-sdk/pull/15691) Make Coin.Validate() check that .Amount is not nil
* (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 {
// 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 @@ -164,11 +164,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

0 comments on commit b5c77d6

Please sign in to comment.