-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(server/v2): eager config loading (#22267)
- Loading branch information
1 parent
7b9a89b
commit 31f97e9
Showing
39 changed files
with
1,045 additions
and
676 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package runtime | ||
|
||
import ( | ||
"cosmossdk.io/core/server" | ||
"cosmossdk.io/depinject" | ||
) | ||
|
||
// ModuleConfigMaps is a map module scoped ConfigMaps | ||
type ModuleConfigMaps map[string]server.ConfigMap | ||
|
||
type ModuleConfigMapsInput struct { | ||
depinject.In | ||
|
||
ModuleConfigs []server.ModuleConfigMap | ||
DynamicConfig server.DynamicConfig `optional:"true"` | ||
} | ||
|
||
// ProvideModuleConfigMaps returns a map of module name to module config map. | ||
// The module config map is a map of flag to value. | ||
func ProvideModuleConfigMaps(in ModuleConfigMapsInput) ModuleConfigMaps { | ||
moduleConfigMaps := make(ModuleConfigMaps) | ||
if in.DynamicConfig == nil { | ||
return moduleConfigMaps | ||
} | ||
for _, moduleConfig := range in.ModuleConfigs { | ||
cfg := moduleConfig.Config | ||
name := moduleConfig.Module | ||
moduleConfigMaps[name] = make(server.ConfigMap) | ||
for flag, df := range cfg { | ||
val := in.DynamicConfig.Get(flag) | ||
if val != nil { | ||
moduleConfigMaps[name][flag] = val | ||
} else { | ||
moduleConfigMaps[name][flag] = df | ||
} | ||
} | ||
} | ||
return moduleConfigMaps | ||
} | ||
|
||
func ProvideModuleScopedConfigMap( | ||
key depinject.ModuleKey, | ||
moduleConfigs ModuleConfigMaps, | ||
) server.ConfigMap { | ||
return moduleConfigs[key.Name()] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package runtime | ||
|
||
import ( | ||
"strings" | ||
|
||
"cosmossdk.io/core/server" | ||
"cosmossdk.io/depinject" | ||
) | ||
|
||
// GlobalConfig is a recursive configuration map containing configuration | ||
// key-value pairs parsed from the configuration file, flags, or other | ||
// input sources. | ||
// | ||
// It is aliased to server.ConfigMap so that DI can distinguish between | ||
// module-scoped and global configuration maps. In the DI container `server.ConfigMap` | ||
// objects are module-scoped and `GlobalConfig` is global-scoped. | ||
type GlobalConfig server.ConfigMap | ||
|
||
// ModuleConfigMaps is a map module scoped ConfigMaps | ||
type ModuleConfigMaps map[string]server.ConfigMap | ||
|
||
// ProvideModuleConfigMaps returns a map of module name to module config map. | ||
// The module config map is a map of flag to value. | ||
func ProvideModuleConfigMaps( | ||
moduleConfigs []server.ModuleConfigMap, | ||
globalConfig GlobalConfig, | ||
) ModuleConfigMaps { | ||
moduleConfigMaps := make(ModuleConfigMaps) | ||
for _, moduleConfig := range moduleConfigs { | ||
cfg := moduleConfig.Config | ||
name := moduleConfig.Module | ||
moduleConfigMaps[name] = make(server.ConfigMap) | ||
for flag, df := range cfg { | ||
m := globalConfig | ||
fetchFlag := flag | ||
// splitting on "." is required to handle nested flags which are defined | ||
// in other modules that are not the current module | ||
// for example: "server.minimum-gas-prices" is defined in the server module | ||
// but required by x/validate | ||
for _, part := range strings.Split(flag, ".") { | ||
if maybeMap, ok := m[part]; ok { | ||
innerMap, ok := maybeMap.(map[string]any) | ||
if !ok { | ||
fetchFlag = part | ||
break | ||
} | ||
m = innerMap | ||
} else { | ||
break | ||
} | ||
} | ||
if val, ok := m[fetchFlag]; ok { | ||
moduleConfigMaps[name][flag] = val | ||
} else { | ||
moduleConfigMaps[name][flag] = df | ||
} | ||
} | ||
} | ||
return moduleConfigMaps | ||
} | ||
|
||
func ProvideModuleScopedConfigMap( | ||
key depinject.ModuleKey, | ||
moduleConfigs ModuleConfigMaps, | ||
) server.ConfigMap { | ||
return moduleConfigs[key.Name()] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.