Skip to content

Commit b5c77d6

Browse files
authored
fix(types): add fallbacks for CoreAppModuleBasicAdaptor (#16010)
1 parent 1705615 commit b5c77d6

File tree

6 files changed

+40
-15
lines changed

6 files changed

+40
-15
lines changed

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4040

4141
### Features
4242

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

6970
### Improvements
7071

72+
* (simapp) [#15958](https://github.com/cosmos/cosmos-sdk/pull/15958) Refactor SimApp for removing the global basic manager.
7173
* (gov) [#15979](https://github.com/cosmos/cosmos-sdk/pull/15979) Improve gov error message when failing to convert v1 proposal to v1beta1.
7274
* (crypto) [#3129](https://github.com/cosmos/cosmos-sdk/pull/3129) New armor and keyring key derivation uses aead and encryption uses chacha20poly
7375
* (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.
@@ -201,8 +203,9 @@ Ref: https://keepachangelog.com/en/1.0.0/
201203

202204
### Bug Fixes
203205

206+
* (types) [#16010](https://github.com/cosmos/cosmos-sdk/pull/16010) Let `module.CoreAppModuleBasicAdaptor` fallback to legacy genesis handling.
204207
* (x/group) [#16017](https://github.com/cosmos/cosmos-sdk/pull/16017) Correctly apply account number in group v2 migration.
205-
* (types) [#15691](https://github.com/cosmos/cosmos-sdk/pull/15691) Make Coin.Validate() check that .Amount is not nil
208+
* (types) [#15691](https://github.com/cosmos/cosmos-sdk/pull/15691) Make `Coin.Validate()` check that `.Amount` is not nil.
206209
* (x/auth) [#15059](https://github.com/cosmos/cosmos-sdk/pull/15059) `ante.CountSubKeys` returns 0 when passing a nil `Pubkey`.
207210
* (x/capability) [#15030](https://github.com/cosmos/cosmos-sdk/pull/15030) Prevent `x/capability` from consuming `GasMeter` gas during `InitMemStore`
208211
* (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

errors/CHANGELOG.md

-5
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ Ref: https://keepachangelog.com/en/1.0.0/
3434
### Features
3535

3636
* [#15989](https://github.com/cosmos/cosmos-sdk/pull/15989) Add `ErrStopIterating` for modules to use for breaking out of iteration.
37-
38-
## v1.0.0
39-
40-
### Features
41-
4237
* [#10779](https://github.com/cosmos/cosmos-sdk/pull/10779) Import code from the `github.com/cosmos/cosmos-sdk/types/errors` package.
4338
* [#11274](https://github.com/cosmos/cosmos-sdk/pull/11274) Add `RegisterWithGRPCCode` function to associate a gRPC error code with errors.
4439

orm/model/ormdb/module.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@ type ModuleDB interface {
2929
// GenesisHandler returns an implementation of appmodule.HasGenesis
3030
// to be embedded in or called from app module implementations.
3131
// Ex:
32-
// type Keeper struct {
32+
// type AppModule struct {
3333
// appmodule.HasGenesis
3434
// }
3535
//
3636
// func NewKeeper(db ModuleDB) *Keeper {
37-
// return &Keeper{HasGenesis: db.GenesisHandler()}
37+
// return &Keeper{genesisHandler: db.GenesisHandler()}
3838
// }
39+
//
40+
// func NewAppModule(keeper keeper.Keeper) AppModule {
41+
// return AppModule{HasGenesis: keeper.GenesisHandler()}
42+
// }
3943
GenesisHandler() appmodule.HasGenesis
4044

4145
private()

runtime/module.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,10 @@ func SetupAppBuilder(inputs AppInputs) {
164164
continue
165165
}
166166

167-
if basicMod, ok := mod.(module.AppModuleBasic); ok {
168-
app.basicManager[name] = basicMod
169-
basicMod.RegisterInterfaces(inputs.InterfaceRegistry)
170-
basicMod.RegisterLegacyAminoCodec(inputs.LegacyAmino)
171-
}
167+
coreAppModuleBasic := module.CoreAppModuleBasicAdaptor(name, mod)
168+
app.basicManager[name] = coreAppModuleBasic
169+
coreAppModuleBasic.RegisterInterfaces(inputs.InterfaceRegistry)
170+
coreAppModuleBasic.RegisterLegacyAminoCodec(inputs.LegacyAmino)
172171
}
173172
}
174173

types/module/core_module.go

+21-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type coreAppModuleBasicAdapator struct {
3838
}
3939

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

5454
return res
5555
}
56+
57+
if mod, ok := c.module.(HasGenesisBasics); ok {
58+
return mod.DefaultGenesis(cdc)
59+
}
60+
5661
return nil
5762
}
5863

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

77+
if mod, ok := c.module.(HasGenesisBasics); ok {
78+
return mod.ValidateGenesis(cdc, txConfig, bz)
79+
}
80+
7281
return nil
7382
}
7483

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

9099
return rawJSON
91100
}
101+
102+
if mod, ok := c.module.(HasGenesis); ok {
103+
return mod.ExportGenesis(ctx, cdc)
104+
}
105+
92106
return nil
93107
}
94108

95109
// InitGenesis implements HasGenesis
96-
func (c coreAppModuleBasicAdapator) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, bz json.RawMessage) []abci.ValidatorUpdate {
110+
func (c coreAppModuleBasicAdapator) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.RawMessage) []abci.ValidatorUpdate {
97111
if module, ok := c.module.(appmodule.HasGenesis); ok {
98112
// core API genesis
99113
source, err := genesis.SourceFromRawJSON(bz)
@@ -106,6 +120,11 @@ func (c coreAppModuleBasicAdapator) InitGenesis(ctx sdk.Context, _ codec.JSONCod
106120
panic(err)
107121
}
108122
}
123+
124+
if mod, ok := c.module.(HasGenesis); ok {
125+
return mod.InitGenesis(ctx, cdc, bz)
126+
}
127+
109128
return nil
110129
}
111130

types/module/module.go

+5
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ func NewBasicManagerFromManager(manager *Manager, customModuleBasics map[string]
101101
continue
102102
}
103103

104+
if appModule, ok := module.(appmodule.AppModule); ok {
105+
moduleMap[name] = CoreAppModuleBasicAdaptor(name, appModule)
106+
continue
107+
}
108+
104109
if basicMod, ok := module.(AppModuleBasic); ok {
105110
moduleMap[name] = basicMod
106111
}

0 commit comments

Comments
 (0)