fix: runtime: fix (*App).RegisterMoodules inconsistency in checking/memoizing appModule (#14128)

Fixes an inconsistency in checking for duplicates in ModuleManager's
Modules[name] then also basicManager[name] in which memoization could
happen for .Module[name] but fail after a duplicate check in
basicManager[name]. This change instead only memoizes the AppModule
after the duplicate checks have all cleared.

Fixes #14006
This commit is contained in:
Emmanuel T Odeke 2022-12-01 14:18:58 -08:00 committed by GitHub
parent 9f46665d93
commit 3aff993fcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -59,12 +59,12 @@ func (a *App) RegisterModules(modules ...module.AppModule) error {
if _, ok := a.ModuleManager.Modules[name]; ok {
return fmt.Errorf("AppModule named %q already exists", name)
}
a.ModuleManager.Modules[name] = appModule
if _, ok := a.basicManager[name]; ok {
return fmt.Errorf("AppModuleBasic named %q already exists", name)
}
a.ModuleManager.Modules[name] = appModule
a.basicManager[name] = appModule
appModule.RegisterInterfaces(a.interfaceRegistry)
appModule.RegisterLegacyAminoCodec(a.amino)