From 49ff5cee453c336c6ce907d63fd5810a726c93b8 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 7 Jun 2024 16:18:52 +0200 Subject: [PATCH 1/3] fix(templates): set init-chainer when custom modules --- .../app/files-consumer/app/app.go.plush | 20 +++++++++---------- .../app/files-minimal/app/app.go.plush | 1 - ignite/templates/app/files/app/app.go.plush | 20 +++++++++---------- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/ignite/templates/app/files-consumer/app/app.go.plush b/ignite/templates/app/files-consumer/app/app.go.plush index e42bbf3d45..8ec88b1633 100644 --- a/ignite/templates/app/files-consumer/app/app.go.plush +++ b/ignite/templates/app/files-consumer/app/app.go.plush @@ -14,7 +14,6 @@ import ( feegrantkeeper "cosmossdk.io/x/feegrant/keeper" upgradekeeper "cosmossdk.io/x/upgrade/keeper" _ "cosmossdk.io/api/cosmos/tx/config/v1" // import for side-effects - _ "github.com/cosmos/cosmos-sdk/x/auth" // import for side-effects _ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import for side-effects _ "github.com/cosmos/cosmos-sdk/x/bank" // import for side-effects _ "github.com/cosmos/cosmos-sdk/x/consensus" // import for side-effects @@ -34,6 +33,7 @@ import ( _ "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts" // import for side-effects _ "github.com/cosmos/ibc-go/v8/modules/apps/29-fee" // import for side-effects dbm "github.com/cosmos/cosmos-db" + abci "github.com/cometbft/cometbft/abci/types" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" @@ -42,6 +42,7 @@ import ( "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/api" "github.com/cosmos/cosmos-sdk/server/config" + sdk "github.com/cosmos/cosmos-sdk/types" servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth" @@ -332,16 +333,13 @@ func New( } app.SetAnteHandler(anteHandler) - // A custom InitChainer can be set if extra pre-init-genesis logic is required. - // By default, when using app wiring enabled module, this is not required. - // For instance, the upgrade module will set automatically the module version map in its init genesis thanks to app wiring. - // However, when registering a module manually (i.e. that does not support app wiring), the module version map - // must be set manually as follow. The upgrade module will de-duplicate the module version map. - // - // app.SetInitChainer(func(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) { - // app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()) - // return app.App.InitChainer(ctx, req) - // }) + // A custom InitChainer sets if extra pre-init-genesis logic is required. + // As we are registering modules manually (i.e. that does not support app wiring), + // the module version map must be set manually as follow. + app.SetInitChainer(func(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) { + app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()) + return app.App.InitChainer(ctx, req) + }) if err := app.Load(loadLatest); err != nil { return nil, err diff --git a/ignite/templates/app/files-minimal/app/app.go.plush b/ignite/templates/app/files-minimal/app/app.go.plush index 82ed491840..b1995d6e2e 100644 --- a/ignite/templates/app/files-minimal/app/app.go.plush +++ b/ignite/templates/app/files-minimal/app/app.go.plush @@ -28,7 +28,6 @@ import ( servertypes "github.com/cosmos/cosmos-sdk/server/types" testdata_pulsar "github.com/cosmos/cosmos-sdk/testutil/testdata/testpb" "github.com/cosmos/cosmos-sdk/types/module" - "github.com/cosmos/cosmos-sdk/x/auth" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" consensuskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" diff --git a/ignite/templates/app/files/app/app.go.plush b/ignite/templates/app/files/app/app.go.plush index a7b997459e..31f1fb806e 100644 --- a/ignite/templates/app/files/app/app.go.plush +++ b/ignite/templates/app/files/app/app.go.plush @@ -13,7 +13,6 @@ import ( feegrantkeeper "cosmossdk.io/x/feegrant/keeper" upgradekeeper "cosmossdk.io/x/upgrade/keeper" _ "cosmossdk.io/api/cosmos/tx/config/v1" // import for side-effects - _ "github.com/cosmos/cosmos-sdk/x/auth" // import for side-effects _ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import for side-effects _ "github.com/cosmos/cosmos-sdk/x/bank" // import for side-effects _ "github.com/cosmos/cosmos-sdk/x/consensus" // import for side-effects @@ -36,6 +35,7 @@ import ( _ "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts" // import for side-effects _ "github.com/cosmos/ibc-go/v8/modules/apps/29-fee" // import for side-effects dbm "github.com/cosmos/cosmos-db" + abci "github.com/cometbft/cometbft/abci/types" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" @@ -44,6 +44,7 @@ import ( "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/api" "github.com/cosmos/cosmos-sdk/server/config" + sdk "github.com/cosmos/cosmos-sdk/types" servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth" @@ -337,16 +338,13 @@ func New( app.sm = module.NewSimulationManagerFromAppModules(app.ModuleManager.Modules, overrideModules) app.sm.RegisterStoreDecoders() - // A custom InitChainer can be set if extra pre-init-genesis logic is required. - // By default, when using app wiring enabled module, this is not required. - // For instance, the upgrade module will set automatically the module version map in its init genesis thanks to app wiring. - // However, when registering a module manually (i.e. that does not support app wiring), the module version map - // must be set manually as follow. The upgrade module will de-duplicate the module version map. - // - // app.SetInitChainer(func(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) { - // app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()) - // return app.App.InitChainer(ctx, req) - // }) + // A custom InitChainer sets if extra pre-init-genesis logic is required. + // As we are registering modules manually (i.e. that does not support app wiring), + // the module version map must be set manually as follow. + app.SetInitChainer(func(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) { + app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()) + return app.App.InitChainer(ctx, req) + }) if err := app.Load(loadLatest); err != nil { return nil, err From 8f2d703bd84395a797339ec3c8f3b572e3c3a750 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 7 Jun 2024 16:19:47 +0200 Subject: [PATCH 2/3] updates --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index babb3ee568..abc64810d5 100644 --- a/changelog.md +++ b/changelog.md @@ -46,6 +46,7 @@ - [#4000](https://github.com/ignite/cli/pull/4000) Run all dry runners before the wet run in the `xgenny` pkg - [#4091](https://github.com/ignite/cli/pull/4091) Fix race conditions in the plugin logic - [#4128](https://github.com/ignite/cli/pull/4128) Check for duplicate proto fields in config +- [#4184](https://github.com/ignite/cli/pull/4184) Set custom `InitChainer` because of manually registered modules ## [`v28.4.0`](https://github.com/ignite/cli/releases/tag/v28.4.0) From 96fce43ee24a4c82897d6a075798f65a0fb482b4 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 13 Jun 2024 15:39:47 +0200 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Danny Co-authored-by: Danilo Pantani --- ignite/templates/app/files-consumer/app/app.go.plush | 9 ++++++--- ignite/templates/app/files/app/app.go.plush | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ignite/templates/app/files-consumer/app/app.go.plush b/ignite/templates/app/files-consumer/app/app.go.plush index 8ec88b1633..3fa6378731 100644 --- a/ignite/templates/app/files-consumer/app/app.go.plush +++ b/ignite/templates/app/files-consumer/app/app.go.plush @@ -334,10 +334,13 @@ func New( app.SetAnteHandler(anteHandler) // A custom InitChainer sets if extra pre-init-genesis logic is required. - // As we are registering modules manually (i.e. that does not support app wiring), - // the module version map must be set manually as follow. + // This is necessary for manually registered modules that do not support app wiring. + // Manually set the module version map as shown below. + // The upgrade module will automatically handle de-duplication of the module version map. app.SetInitChainer(func(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) { - app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()) + if err := app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()); err != nil { + return nil, err + } return app.App.InitChainer(ctx, req) }) diff --git a/ignite/templates/app/files/app/app.go.plush b/ignite/templates/app/files/app/app.go.plush index 31f1fb806e..4f55168cd0 100644 --- a/ignite/templates/app/files/app/app.go.plush +++ b/ignite/templates/app/files/app/app.go.plush @@ -339,10 +339,13 @@ func New( app.sm.RegisterStoreDecoders() // A custom InitChainer sets if extra pre-init-genesis logic is required. - // As we are registering modules manually (i.e. that does not support app wiring), - // the module version map must be set manually as follow. + // This is necessary for manually registered modules that do not support app wiring. + // Manually set the module version map as shown below. + // The upgrade module will automatically handle de-duplication of the module version map. app.SetInitChainer(func(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) { - app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()) + if err := app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()); err != nil { + return nil, err + } return app.App.InitChainer(ctx, req) })