-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
refactor(simapp): remove public module basic manager #15958
Conversation
@julienrbrt lmk if you need help here, I have a deep hated passion for having to define this variable LOL |
Haha thanks, the biggest wonder is how to make it nice when you need to manually instantiate AppModuleBasic (for gov and genutil f.e), but I have an idea. |
Feels a bit like a hack but what do you think? |
_ "cosmossdk.io/x/nft/module" // import for side-effects | ||
_ "cosmossdk.io/x/upgrade" // import for side-effects | ||
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import for side-effects | ||
_ "github.com/cosmos/cosmos-sdk/x/auth/vesting" // import for side-effects |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is so hood.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, because we do not import the module directl now that there is no app basic imports, we need these for app wiring.
Fortunately depinject has a descriptive error message and points which import is missing.
@@ -101,7 +102,7 @@ func NewRootCmd() *cobra.Command { | |||
}, | |||
} | |||
|
|||
initRootCmd(rootCmd, encodingConfig) | |||
initRootCmd(rootCmd, encodingConfig, tempApp.BasicModuleManager) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this feels big bad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this tempApp and where is this coming from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The origin is not to use depinject for app v1 (as this means we do not show how to get those values for app v1 apps).
For app v2 app, we can just use depinject. I can remove it to clean it up, but then it does mean that when building with the app legacy flag, it will still use the app wiring config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing I can simply do is try to create a root.go and root_v2.go for both implementations. So we can simplify the example for those using depinject, where it is way cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that'd be fire actually!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, for app v1 it does need to stay like this. app v2 is way cleaner :)
yeah this is kinda gross. I feel like it adds more complexity than it helps solve. What if the Appliation interface forces the app to expose what modules it supports? I think the thing that bugs me the most is the whole |
Yeah, the |
for name, module := range manager.Modules { | ||
if customBasicMod, ok := customModuleBasics[name]; ok { | ||
moduleMap[name] = customBasicMod | ||
continue | ||
} | ||
|
||
if basicMod, ok := module.(AppModuleBasic); ok { | ||
moduleMap[name] = basicMod | ||
} | ||
} |
Check warning
Code scanning / CodeQL
Iteration over map
runtime/app.go
Outdated
appConfig *appv1alpha1.Config | ||
logger log.Logger | ||
ModuleManager *module.Manager | ||
BasicModuleManager module.BasicManager |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this need to be exported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did that for parity with app v1, I won't do that anymore given I will create a second root.go for app v2 only 👍🏾
@@ -101,7 +102,7 @@ func NewRootCmd() *cobra.Command { | |||
}, | |||
} | |||
|
|||
initRootCmd(rootCmd, encodingConfig) | |||
initRootCmd(rootCmd, encodingConfig, tempApp.BasicModuleManager) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this tempApp and where is this coming from?
|
||
if basicMod, ok := module.(AppModuleBasic); ok { | ||
moduleMap[name] = basicMod | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use an app module basic adapter for core app modules?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add a condition for that but we will still need this one.
In runtime, we can indeed directly use the adapter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, after a few trials, the core app module adapter does not work. I will leave it out of this PR.
Done the following in SetupAppBuilder
app.basicManager[name] = basicMod
basicMod.RegisterInterfaces(inputs.InterfaceRegistry)
basicMod.RegisterLegacyAminoCodec(inputs.LegacyAmino)
basicMod := module.CoreAppModuleBasicAdaptor(name, mod)
And the following in NewBasicManagerFromManager
if appModule, ok := module.(appmodule.AppModule); ok {
moduleMap[name] = CoreAppModuleBasicAdaptor(name, appModule)
continue
}
Something to investigate in a follow-up.
Description
ref: #15304
PR to investigate how to get group genesis working nicely with app v1 and app v2. Currently,
InitGenesis
utilizes the basic module manager, but we need an app module instantiated for creating an app module basic forappmodule.HasGenesis
.This removes the need to define a list
AppModuleBasic
in app.go and app_v2.go. Now it will infer it from the module manager.Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change