From b2072deb09a63b1dc58f7572096b183797779485 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Fri, 11 Oct 2024 09:53:54 -0500 Subject: [PATCH 01/46] begin config rationalization --- client/v2/helpers/home.go | 24 ++++++++++++++++++++ server/v2/commands.go | 13 +++++++---- simapp/v2/simdv2/cmd/root_di.go | 40 ++++++++++++++++++++++++++++----- simapp/v2/simdv2/main.go | 11 ++++++++- 4 files changed, 78 insertions(+), 10 deletions(-) diff --git a/client/v2/helpers/home.go b/client/v2/helpers/home.go index af3fc2886673..631b9fa0e457 100644 --- a/client/v2/helpers/home.go +++ b/client/v2/helpers/home.go @@ -46,3 +46,27 @@ func GetNodeHomeDirectory(name string) (string, error) { return filepath.Join(userHomeDir, name), nil } + +func DefaultHomeDir(name string) (string, error) { + // get the home directory from the environment variable + // to not clash with the $HOME system variable, when no prefix is set + // we check the NODE_HOME environment variable + envPrefix := EnvPrefix + homeDir, envHome := "", "HOME" + if len(envPrefix) > 0 { + homeDir = os.Getenv(envPrefix + "_" + envHome) + } else { + homeDir = os.Getenv("NODE_" + envHome) + } + if homeDir != "" { + return filepath.Clean(homeDir), nil + } + + // get user home directory + userHomeDir, err := os.UserHomeDir() + if err != nil { + return "", err + } + + return filepath.Join(userHomeDir, name), nil +} diff --git a/server/v2/commands.go b/server/v2/commands.go index 0357fe180d93..a7db3f25f9b8 100644 --- a/server/v2/commands.go +++ b/server/v2/commands.go @@ -10,6 +10,7 @@ import ( "syscall" "github.com/spf13/cobra" + "github.com/spf13/pflag" "github.com/spf13/viper" "cosmossdk.io/core/transaction" @@ -19,10 +20,7 @@ import ( // Execute executes the root command of an application. // It handles adding core CLI flags, specifically the logging flags. func Execute(rootCmd *cobra.Command, envPrefix, defaultHome string) error { - rootCmd.PersistentFlags().String(FlagLogLevel, "info", "The logging level (trace|debug|info|warn|error|fatal|panic|disabled or '*:,:')") - rootCmd.PersistentFlags().String(FlagLogFormat, "plain", "The logging format (json|plain)") - rootCmd.PersistentFlags().Bool(FlagLogNoColor, false, "Disable colored logs") - rootCmd.PersistentFlags().StringP(FlagHome, "", defaultHome, "directory for config and data") + SetPersistentFlags(rootCmd.PersistentFlags(), defaultHome) // update the global viper with the root command's configuration viper.SetEnvPrefix(envPrefix) @@ -32,6 +30,13 @@ func Execute(rootCmd *cobra.Command, envPrefix, defaultHome string) error { return rootCmd.Execute() } +func SetPersistentFlags(pflags *pflag.FlagSet, defaultHome string) { + pflags.String(FlagLogLevel, "info", "The logging level (trace|debug|info|warn|error|fatal|panic|disabled or '*:,:')") + pflags.String(FlagLogFormat, "plain", "The logging format (json|plain)") + pflags.Bool(FlagLogNoColor, false, "Disable colored logs") + pflags.StringP(FlagHome, "", defaultHome, "directory for config and data") +} + // AddCommands add the server commands to the root command // It configures the config handling and the logger handling func AddCommands[T transaction.Tx]( diff --git a/simapp/v2/simdv2/cmd/root_di.go b/simapp/v2/simdv2/cmd/root_di.go index 6b13b7201342..c0b4593c60ad 100644 --- a/simapp/v2/simdv2/cmd/root_di.go +++ b/simapp/v2/simdv2/cmd/root_di.go @@ -1,12 +1,15 @@ package cmd import ( + serverv2 "cosmossdk.io/server/v2" + "fmt" "os" "github.com/spf13/cobra" autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" "cosmossdk.io/client/v2/autocli" + clientv2helpers "cosmossdk.io/client/v2/helpers" "cosmossdk.io/core/address" "cosmossdk.io/core/registry" "cosmossdk.io/core/transaction" @@ -25,15 +28,41 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/types" ) +/* +logger cannot be injected until command line arguments are parsed but injection is needed before + command line args are parsed due to closing over DI outputs. + +Q: Where is logger needed in injection? +A: ProvideEnvironment and ProvideModuleManager need it. They are receiving a noop logger in the initial injection +and a parsed and configured one in the second. + +!! Return a bootstrap command first with Persistent flags, then parse them. This configures the logger and the home directory. +this can also be folded in and nuked: +https://github.com/cosmos/cosmos-sdk/blob/6708818470826923b96ff7fb6ef55729d8c4269e/client/v2/helpers/home.go#L17 + +*/ + // NewRootCmd creates a new root command for simd. It is called once in the main function. -func NewRootCmd[T transaction.Tx]() *cobra.Command { +func NewRootCmd[T transaction.Tx](args []string) (*cobra.Command, error) { var ( autoCliOpts autocli.AppOptions moduleManager *runtime.MM[T] clientCtx client.Context ) + defaultHomeDir, err := clientv2helpers.DefaultHomeDir(".simappv2") + if err != nil { + return nil, err + } + bootstrapCmd := &cobra.Command{} + bootstrapCmd.FParseErrWhitelist.UnknownFlags = true + bootstrapFlags := bootstrapCmd.PersistentFlags() + serverv2.SetPersistentFlags(bootstrapFlags, defaultHomeDir) + err = bootstrapCmd.ParseFlags(args) + if err != nil { + return nil, err + } - if err := depinject.Inject( + if err = depinject.Inject( depinject.Configs( simapp.AppConfig(), depinject.Provide(ProvideClientContext), @@ -43,14 +72,15 @@ func NewRootCmd[T transaction.Tx]() *cobra.Command { &moduleManager, &clientCtx, ); err != nil { - panic(err) + return nil, err } rootCmd := &cobra.Command{ - Use: "simd", + Use: "simdv2", Short: "simulation app", SilenceErrors: true, - PersistentPreRunE: func(cmd *cobra.Command, _ []string) error { + PersistentPreRunE: func(cmd *cobra.Command, args []string) error { + fmt.Printf("simd root command persistent pre-run %+v\n", args) clientCtx = clientCtx.WithCmdContext(cmd.Context()) clientCtx, err := client.ReadPersistentCommandFlags(clientCtx, cmd.Flags()) if err != nil { diff --git a/simapp/v2/simdv2/main.go b/simapp/v2/simdv2/main.go index eb7d9a1b005b..ae5dce37f3fa 100644 --- a/simapp/v2/simdv2/main.go +++ b/simapp/v2/simdv2/main.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "os" @@ -12,7 +13,15 @@ import ( ) func main() { - rootCmd := cmd.NewRootCmd[transaction.Tx]() + // see: https://github.com/spf13/cobra/blob/e94f6d0dd9a5e5738dca6bce03c4b1207ffbc0ec/command.go#L1082 + args := os.Args[1:] + rootCmd, err := cmd.NewRootCmd[transaction.Tx](args) + if err != nil { + if _, pErr := fmt.Fprintln(os.Stderr, err); pErr != nil { + panic(errors.Join(err, pErr)) + } + os.Exit(1) + } if err := serverv2.Execute(rootCmd, clientv2helpers.EnvPrefix, simapp.DefaultNodeHome); err != nil { fmt.Fprintln(rootCmd.OutOrStderr(), err) os.Exit(1) From ecf73cf9e0d506d3cc7a26537cd558cf5de7b35b Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Sat, 12 Oct 2024 23:50:04 -0500 Subject: [PATCH 02/46] the concept is proven --- core/server/config.go | 9 ++++ go.mod | 1 + simapp/v2/app_config.go | 4 +- simapp/v2/app_di.go | 2 +- simapp/v2/go.mod | 1 + simapp/v2/simdv2/cmd/root_di.go | 91 +++++++++++++++++++++++++++++++-- x/upgrade/depinject.go | 13 ++++- x/upgrade/go.mod | 1 + x/validate/depinject.go | 12 ++++- 9 files changed, 124 insertions(+), 10 deletions(-) diff --git a/core/server/config.go b/core/server/config.go index 997633fe46b3..8dd3a6e7bbc9 100644 --- a/core/server/config.go +++ b/core/server/config.go @@ -6,3 +6,12 @@ type DynamicConfig interface { Get(string) any GetString(string) string } + +type ConfigMap map[string]any + +type ModuleConfigMap struct { + Module string + Config ConfigMap +} + +func (ModuleConfigMap) IsManyPerContainerType() {} diff --git a/go.mod b/go.mod index b2dc62a8bc62..bfe0cce9e3a8 100644 --- a/go.mod +++ b/go.mod @@ -188,6 +188,7 @@ replace ( cosmossdk.io/x/bank => ./x/bank cosmossdk.io/x/staking => ./x/staking cosmossdk.io/x/tx => ./x/tx + cosmossdk.io/core => ./core ) // Below are the long-lived replace of the Cosmos SDK diff --git a/simapp/v2/app_config.go b/simapp/v2/app_config.go index 2f1337aec398..5ade503e6403 100644 --- a/simapp/v2/app_config.go +++ b/simapp/v2/app_config.go @@ -106,8 +106,8 @@ var ( // pooltypes.ModuleName } - // application configuration (used by depinject) - appConfig = appconfig.Compose(&appv1alpha1.Config{ + // ModuleConfig is the application module configuration used by depinject + ModuleConfig = appconfig.Compose(&appv1alpha1.Config{ Modules: []*appv1alpha1.ModuleConfig{ { Name: runtime.ModuleName, diff --git a/simapp/v2/app_di.go b/simapp/v2/app_di.go index b1dfc26f99ff..c9121c4a9519 100644 --- a/simapp/v2/app_di.go +++ b/simapp/v2/app_di.go @@ -59,7 +59,7 @@ func init() { // AppConfig returns the default app config. func AppConfig() depinject.Config { return depinject.Configs( - appConfig, // Alternatively use appconfig.LoadYAML(AppConfigYAML) + ModuleConfig, // Alternatively use appconfig.LoadYAML(AppConfigYAML) runtime.DefaultServiceBindings(), depinject.Provide( codec.ProvideInterfaceRegistry, diff --git a/simapp/v2/go.mod b/simapp/v2/go.mod index 448a98a8928f..d450a069e2a0 100644 --- a/simapp/v2/go.mod +++ b/simapp/v2/go.mod @@ -273,6 +273,7 @@ replace ( cosmossdk.io/x/staking => ../../x/staking cosmossdk.io/x/tx => ../../x/tx cosmossdk.io/x/upgrade => ../../x/upgrade + cosmossdk.io/core => ../../core ) // Below are the long-lived replace of the SimApp diff --git a/simapp/v2/simdv2/cmd/root_di.go b/simapp/v2/simdv2/cmd/root_di.go index c0b4593c60ad..796ff20d4630 100644 --- a/simapp/v2/simdv2/cmd/root_di.go +++ b/simapp/v2/simdv2/cmd/root_di.go @@ -1,11 +1,13 @@ package cmd import ( + "cosmossdk.io/core/server" serverv2 "cosmossdk.io/server/v2" "fmt" - "os" - "github.com/spf13/cobra" + "github.com/spf13/pflag" + "os" + "strings" autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" "cosmossdk.io/client/v2/autocli" @@ -42,6 +44,74 @@ https://github.com/cosmos/cosmos-sdk/blob/6708818470826923b96ff7fb6ef55729d8c426 */ +type ModuleConfigMaps map[string]server.ConfigMap +type FlagParser func() error + +func ProvideModuleConfigMap( + moduleConfigs []server.ModuleConfigMap, + flags *pflag.FlagSet, + parseFlags FlagParser, +) (ModuleConfigMaps, error) { + var err error + globalConfig := make(ModuleConfigMaps) + for _, moduleConfig := range moduleConfigs { + cfg := moduleConfig.Config + name := moduleConfig.Module + globalConfig[name] = make(server.ConfigMap) + for flag, defaultValue := range cfg { + globalConfig[name][flag] = defaultValue + switch defaultValue.(type) { + case string: + _, maybeNotFound := flags.GetString(flag) + if maybeNotFound != nil && strings.Contains(maybeNotFound.Error(), + "flag accessed but not defined") { + flags.String(flag, defaultValue.(string), "") + } else { + // slightly skip the flag if it's already defined + continue + } + case []int: + flags.IntSlice(flag, defaultValue.([]int), "") + case int: + flags.Int(flag, defaultValue.(int), "") + default: + return nil, fmt.Errorf("unsupported type %T for flag %s", defaultValue, flag) + } + if err != nil { + return nil, err + } + } + } + if err = parseFlags(); err != nil { + return nil, err + } + for _, cfg := range globalConfig { + for flag, defaulValue := range cfg { + switch defaulValue.(type) { + case string: + cfg[flag], err = flags.GetString(flag) + case []int: + cfg[flag], err = flags.GetIntSlice(flag) + case int: + cfg[flag], err = flags.GetInt(flag) + default: + return nil, fmt.Errorf("unsupported type %T for flag %s", defaulValue, flag) + } + if err != nil { + return nil, err + } + } + } + return globalConfig, nil +} + +func ProvideModuleScopedConfigMap( + key depinject.ModuleKey, + moduleConfigs ModuleConfigMaps, +) server.ConfigMap { + return moduleConfigs[key.Name()] +} + // NewRootCmd creates a new root command for simd. It is called once in the main function. func NewRootCmd[T transaction.Tx](args []string) (*cobra.Command, error) { var ( @@ -61,12 +131,23 @@ func NewRootCmd[T transaction.Tx](args []string) (*cobra.Command, error) { if err != nil { return nil, err } + flagParser := FlagParser(func() error { + return bootstrapCmd.ParseFlags(args) + }) if err = depinject.Inject( depinject.Configs( simapp.AppConfig(), - depinject.Provide(ProvideClientContext), - depinject.Supply(log.NewNopLogger()), + depinject.Provide( + ProvideClientContext, + ProvideModuleConfigMap, + ProvideModuleScopedConfigMap, + ), + depinject.Supply( + log.NewNopLogger(), + flagParser, + bootstrapCmd.Flags(), + ), ), &autoCliOpts, &moduleManager, @@ -111,7 +192,7 @@ func NewRootCmd[T transaction.Tx](args []string) (*cobra.Command, error) { panic(err) } - return rootCmd + return rootCmd, nil } func ProvideClientContext( diff --git a/x/upgrade/depinject.go b/x/upgrade/depinject.go index d0ad08a1c34e..28befab7ca6b 100644 --- a/x/upgrade/depinject.go +++ b/x/upgrade/depinject.go @@ -26,15 +26,26 @@ func (am AppModule) IsOnePerModuleType() {} func init() { appconfig.RegisterModule(&modulev1.Module{}, - appconfig.Provide(ProvideModule), + appconfig.Provide(ProvideModule, ProvideConfig), appconfig.Invoke(PopulateVersionMap), ) } +func ProvideConfig(key depinject.OwnModuleKey) coreserver.ModuleConfigMap { + return coreserver.ModuleConfigMap{ + Module: depinject.ModuleKey(key).Name(), + Config: coreserver.ConfigMap{ + server.FlagUnsafeSkipUpgrades: []int{}, + flags.FlagHome: "", + }, + } +} + type ModuleInputs struct { depinject.In Config *modulev1.Module + ConfigMap coreserver.ConfigMap Environment appmodule.Environment Cdc codec.Codec AddressCodec address.Codec diff --git a/x/upgrade/go.mod b/x/upgrade/go.mod index 7f9a2eafcd9e..9c930907e927 100644 --- a/x/upgrade/go.mod +++ b/x/upgrade/go.mod @@ -207,4 +207,5 @@ replace ( cosmossdk.io/x/gov => ../gov cosmossdk.io/x/staking => ../staking cosmossdk.io/x/tx => ../tx + cosmossdk.io/core => ../../core ) diff --git a/x/validate/depinject.go b/x/validate/depinject.go index 9f508717f04f..0f6cc5dd549d 100644 --- a/x/validate/depinject.go +++ b/x/validate/depinject.go @@ -25,10 +25,19 @@ const flagMinGasPricesV2 = "server.minimum-gas-prices" func init() { appconfig.RegisterModule(&modulev1.Module{}, - appconfig.Provide(ProvideModule), + appconfig.Provide(ProvideModule, ProvideConfig), ) } +func ProvideConfig(key depinject.OwnModuleKey) server.ModuleConfigMap { + return server.ModuleConfigMap{ + Module: depinject.ModuleKey(key).Name(), + Config: server.ConfigMap{ + flagMinGasPricesV2: "", + }, + } +} + type ModuleInputs struct { depinject.In @@ -36,6 +45,7 @@ type ModuleInputs struct { Environment appmodulev2.Environment TxConfig client.TxConfig DynamicConfig server.DynamicConfig `optional:"true"` + ConfigMap server.ConfigMap AccountKeeper ante.AccountKeeper BankKeeper authtypes.BankKeeper From 8cb7307d409b0ee85a00b007c6fd00f655363c76 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Mon, 14 Oct 2024 18:33:48 -0500 Subject: [PATCH 03/46] interesting, start command works --- core/server/config.go | 4 + go.mod | 2 +- go.sum | 2 - runtime/v2/go.mod | 1 + runtime/v2/module.go | 5 +- server/v2/commands.go | 75 +++++------- server/v2/go.mod | 1 + server/v2/go.sum | 2 - server/v2/logger.go | 40 +++++++ simapp/v2/app_di.go | 106 ++++++++++++++++- simapp/v2/go.mod | 2 +- simapp/v2/go.sum | 2 - simapp/v2/simdv2/cmd/commands.go | 31 ++--- simapp/v2/simdv2/cmd/config.go | 1 + simapp/v2/simdv2/cmd/root_di.go | 192 ++++++++++++++++++++++--------- simapp/v2/simdv2/main.go | 5 +- x/genutil/client/cli/collect.go | 7 +- x/genutil/v2/cli/commands.go | 14 ++- x/genutil/v2/cli/export.go | 7 +- x/upgrade/go.mod | 2 +- x/upgrade/go.sum | 2 - 21 files changed, 362 insertions(+), 141 deletions(-) diff --git a/core/server/config.go b/core/server/config.go index 8dd3a6e7bbc9..6ba618dae8e9 100644 --- a/core/server/config.go +++ b/core/server/config.go @@ -9,6 +9,10 @@ type DynamicConfig interface { type ConfigMap map[string]any +func (c ConfigMap) Get(s string) any { + return c[s] +} + type ModuleConfigMap struct { Module string Config ConfigMap diff --git a/go.mod b/go.mod index bfe0cce9e3a8..e29e524be82e 100644 --- a/go.mod +++ b/go.mod @@ -184,11 +184,11 @@ require ( replace ( cosmossdk.io/api => ./api cosmossdk.io/collections => ./collections + cosmossdk.io/core => ./core cosmossdk.io/store => ./store cosmossdk.io/x/bank => ./x/bank cosmossdk.io/x/staking => ./x/staking cosmossdk.io/x/tx => ./x/tx - cosmossdk.io/core => ./core ) // Below are the long-lived replace of the Cosmos SDK diff --git a/go.sum b/go.sum index 39a05c2011fc..231e3121740a 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,6 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88ef6483f90f.2/go.mod h1:HqcXMSa5qnNuakaMUo+hWhF51mKbcrZxGl9Vp5EeJXc= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/runtime/v2/go.mod b/runtime/v2/go.mod index c28b2b52a05b..3352af1f6b40 100644 --- a/runtime/v2/go.mod +++ b/runtime/v2/go.mod @@ -9,6 +9,7 @@ replace ( cosmossdk.io/server/v2/stf => ../../server/v2/stf cosmossdk.io/store/v2 => ../../store/v2 cosmossdk.io/x/tx => ../../x/tx + cosmossdk.io/core => ../../core ) require ( diff --git a/runtime/v2/module.go b/runtime/v2/module.go index dcde5ae48772..bdb4c7a340bd 100644 --- a/runtime/v2/module.go +++ b/runtime/v2/module.go @@ -142,6 +142,7 @@ func ProvideAppBuilder[T transaction.Tx]( type AppInputs struct { depinject.In + StoreConfig *root.Config Config *runtimev2.Module AppBuilder *AppBuilder[transaction.Tx] ModuleManager *MM[transaction.Tx] @@ -151,7 +152,7 @@ type AppInputs struct { StoreBuilder root.Builder } -func SetupAppBuilder(inputs AppInputs) { +func SetupAppBuilder(inputs AppInputs) error { app := inputs.AppBuilder.app app.config = inputs.Config app.logger = inputs.Logger @@ -160,6 +161,8 @@ func SetupAppBuilder(inputs AppInputs) { app.moduleManager.RegisterLegacyAminoCodec(inputs.LegacyAmino) // STF requires some state to run inputs.StoreBuilder.RegisterKey("stf") + _, err := inputs.StoreBuilder.Build(inputs.Logger, inputs.StoreConfig) + return err } func ProvideModuleManager[T transaction.Tx]( diff --git a/server/v2/commands.go b/server/v2/commands.go index a7db3f25f9b8..3d8f5b079e67 100644 --- a/server/v2/commands.go +++ b/server/v2/commands.go @@ -11,25 +11,12 @@ import ( "github.com/spf13/cobra" "github.com/spf13/pflag" - "github.com/spf13/viper" + "cosmossdk.io/core/server" "cosmossdk.io/core/transaction" "cosmossdk.io/log" ) -// Execute executes the root command of an application. -// It handles adding core CLI flags, specifically the logging flags. -func Execute(rootCmd *cobra.Command, envPrefix, defaultHome string) error { - SetPersistentFlags(rootCmd.PersistentFlags(), defaultHome) - - // update the global viper with the root command's configuration - viper.SetEnvPrefix(envPrefix) - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_")) - viper.AutomaticEnv() - - return rootCmd.Execute() -} - func SetPersistentFlags(pflags *pflag.FlagSet, defaultHome string) { pflags.String(FlagLogLevel, "info", "The logging level (trace|debug|info|warn|error|fatal|panic|disabled or '*:,:')") pflags.String(FlagLogFormat, "plain", "The logging format (json|plain)") @@ -37,41 +24,40 @@ func SetPersistentFlags(pflags *pflag.FlagSet, defaultHome string) { pflags.StringP(FlagHome, "", defaultHome, "directory for config and data") } +// Allow the chain developer to overwrite the server default app toml config. +func initServerConfig() ServerConfig { + serverCfg := DefaultServerConfig() + // The server's default minimum gas price is set to "0stake" inside + // app.toml. However, the chain developer can set a default app.toml value for their + // validators here. Please update value based on chain denom. + // + // In summary: + // - if you set serverCfg.MinGasPrices value, validators CAN tweak their + // own app.toml to override, or use this default value. + // + // In simapp, we set the min gas prices to 0. + serverCfg.MinGasPrices = "0stake" + + return serverCfg +} + // AddCommands add the server commands to the root command // It configures the config handling and the logger handling func AddCommands[T transaction.Tx]( rootCmd *cobra.Command, - newApp AppCreator[T], + app AppI[T], logger log.Logger, - globalServerCfg ServerConfig, + globalServerCfg server.ConfigMap, components ...ServerComponent[T], -) error { +) (interface{ WriteConfig(string) error }, error) { if len(components) == 0 { - return errors.New("no components provided") - } - - server := NewServer(logger, globalServerCfg, components...) - originalPersistentPreRunE := rootCmd.PersistentPreRunE - rootCmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error { - // set the default command outputs - cmd.SetOut(cmd.OutOrStdout()) - cmd.SetErr(cmd.ErrOrStderr()) - - if err := configHandle(server, cmd); err != nil { - return err - } - - // call the original PersistentPreRun(E) if it exists - if rootCmd.PersistentPreRun != nil { - rootCmd.PersistentPreRun(cmd, args) - return nil - } - - return originalPersistentPreRunE(cmd, args) + return nil, errors.New("no components provided") } + server := NewServer(logger, initServerConfig(), components...) cmds := server.CLICommands() - startCmd := createStartCommand(server, newApp) + startCmd := createStartCommand(server, app) + // TODO necessary? won't the parent context be inherited? startCmd.SetContext(rootCmd.Context()) cmds.Commands = append(cmds.Commands, startCmd) rootCmd.AddCommand(cmds.Commands...) @@ -97,19 +83,20 @@ func AddCommands[T transaction.Tx]( } } - return nil + return server, nil } // createStartCommand creates the start command for the application. func createStartCommand[T transaction.Tx]( server *Server[T], - newApp AppCreator[T], + app AppI[T], ) *cobra.Command { flags := server.StartFlags() cmd := &cobra.Command{ - Use: "start", - Short: "Run the application", + Use: "start", + Short: "Run the application", + Annotations: map[string]string{"needs-app": "true"}, RunE: func(cmd *cobra.Command, args []string) error { v := GetViperFromCmd(cmd) l := GetLoggerFromCmd(cmd) @@ -117,7 +104,7 @@ func createStartCommand[T transaction.Tx]( return err } - if err := server.Init(newApp(l, v), v.AllSettings(), l); err != nil { + if err := server.Init(app, v.AllSettings(), l); err != nil { return err } diff --git a/server/v2/go.mod b/server/v2/go.mod index 1fca8cbb4416..19ffdcc61e1c 100644 --- a/server/v2/go.mod +++ b/server/v2/go.mod @@ -4,6 +4,7 @@ go 1.23 replace ( cosmossdk.io/api => ../../api + cosmossdk.io/core => ../../core cosmossdk.io/server/v2/appmanager => ./appmanager cosmossdk.io/server/v2/stf => ./stf cosmossdk.io/store/v2 => ../../store/v2 diff --git a/server/v2/go.sum b/server/v2/go.sum index 26e67ab39a4c..ef8cddf06a05 100644 --- a/server/v2/go.sum +++ b/server/v2/go.sum @@ -1,7 +1,5 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/errors/v2 v2.0.0-20240731132947-df72853b3ca5 h1:IQNdY2kB+k+1OM2DvqFG1+UgeU1JzZrWtwuWzI3ZfwA= diff --git a/server/v2/logger.go b/server/v2/logger.go index 8ca80e4cce45..d28ddfd3b4b6 100644 --- a/server/v2/logger.go +++ b/server/v2/logger.go @@ -1,8 +1,10 @@ package serverv2 import ( + "fmt" "io" + "cosmossdk.io/core/server" "github.com/rs/zerolog" "github.com/spf13/viper" @@ -42,3 +44,41 @@ func NewLogger(v *viper.Viper, out io.Writer) (log.Logger, error) { return log.NewLogger(out, opts...), nil } + +func NewLoggerFromConfig(configMap server.ConfigMap, out io.Writer) (log.Logger, error) { + var opts []log.Option + if v, ok := configMap[FlagLogFormat]; ok && v == OutputFormatJSON { + opts = append(opts, log.OutputJSONOption()) + } + if v, ok := configMap[FlagLogNoColor]; ok && v == true { + opts = append(opts, log.ColorOption(false)) + } + if v, ok := configMap[FlagTrace]; ok && v == true { + opts = append(opts, log.TraceOption(true)) + } + logLvlAny, ok := configMap[FlagLogLevel] + if !ok { + return log.NewLogger(out, opts...), nil + } + logLvlStr, ok := logLvlAny.(string) + if !ok { + return nil, fmt.Errorf("invalid log level type: %T", logLvlAny) + } + + logLvl, err := zerolog.ParseLevel(logLvlStr) + switch { + case err != nil: + // If the log level is not a valid zerolog level, then we try to parse it as a key filter. + filterFunc, err := log.ParseLogLevel(logLvlStr) + if err != nil { + return nil, err + } + + opts = append(opts, log.FilterOption(filterFunc)) + default: + opts = append(opts, log.LevelOption(logLvl)) + } + + return log.NewLogger(out, opts...), nil + +} diff --git a/simapp/v2/app_di.go b/simapp/v2/app_di.go index c9121c4a9519..ebaa8503d18a 100644 --- a/simapp/v2/app_di.go +++ b/simapp/v2/app_di.go @@ -2,6 +2,7 @@ package simapp import ( _ "embed" + "fmt" "github.com/spf13/viper" @@ -66,6 +67,9 @@ func AppConfig() depinject.Config { codec.ProvideAddressCodec, codec.ProvideProtoCodec, codec.ProvideLegacyAmino, + ProvideModuleScopedConfigMap, + SanelyProvideModuleConfigMap, + ProvideRootStoreConfig, ), depinject.Invoke( std.RegisterInterfaces, @@ -74,6 +78,65 @@ func AppConfig() depinject.Config { ) } +func NewSimAppWithConfig[T transaction.Tx]( + config depinject.Config, + outputs ...any, +) (*SimApp[T], error) { + var ( + app = &SimApp[T]{} + appBuilder *runtime.AppBuilder[T] + storeBuilder root.Builder + logger log.Logger + + // merge the AppConfig and other configuration in one config + appConfig = depinject.Configs( + AppConfig(), + config, + depinject.Provide( + multisigdepinject.ProvideAccount, + basedepinject.ProvideAccount, + lockupdepinject.ProvideAllLockupAccounts, + basedepinject.ProvideSecp256K1PubKey, + ), + ) + ) + + outputs = append(outputs, + &logger, + &storeBuilder, + &appBuilder, + &app.appCodec, + &app.legacyAmino, + &app.txConfig, + &app.interfaceRegistry, + &app.UpgradeKeeper, + &app.StakingKeeper) + + if err := depinject.Inject(appConfig, outputs...); err != nil { + return nil, err + } + + app.store = storeBuilder.Get() + if app.store == nil { + return nil, fmt.Errorf("store builder not return a db") + } + var err error + app.App, err = appBuilder.Build() + if err != nil { + return nil, err + } + + /**** Module Options ****/ + + // RegisterUpgradeHandlers is used for registering any on-chain upgrades. + app.RegisterUpgradeHandlers() + + if err = app.LoadLatest(); err != nil { + return nil, err + } + return app, nil +} + // NewSimApp returns a reference to an initialized SimApp. func NewSimApp[T transaction.Tx]( logger log.Logger, @@ -90,7 +153,6 @@ func NewSimApp[T transaction.Tx]( AppConfig(), depinject.Supply( logger, - viper, // ADVANCED CONFIGURATION @@ -200,6 +262,10 @@ func NewSimApp[T transaction.Tx]( return app } +func (app *SimApp[T]) Build() error { + return nil +} + // AppCodec returns SimApp's app codec. // // NOTE: This is solely to be used for testing purposes as it may be desirable @@ -221,3 +287,41 @@ func (app *SimApp[T]) TxConfig() client.TxConfig { func (app *SimApp[T]) GetStore() store.RootStore { return app.store } + +type GlobalConfig server.ConfigMap +type ModuleConfigMaps map[string]server.ConfigMap + +// TODO combine below 2 functions +// - linear search for module name in provider is OK +// - move elsewhere, server/v2 or runtime/v2 ? + +func SanelyProvideModuleConfigMap( + 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 { + if val, ok := globalConfig[flag]; 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()] +} + +func ProvideRootStoreConfig(config GlobalConfig) (*root.Config, error) { + return serverstore.UnmarshalConfig(config) +} diff --git a/simapp/v2/go.mod b/simapp/v2/go.mod index d450a069e2a0..9718c5fb4a99 100644 --- a/simapp/v2/go.mod +++ b/simapp/v2/go.mod @@ -250,6 +250,7 @@ require ( replace ( cosmossdk.io/client/v2 => ../../client/v2 cosmossdk.io/collections => ../../collections + cosmossdk.io/core => ../../core cosmossdk.io/tools/confix => ../../tools/confix cosmossdk.io/x/accounts => ../../x/accounts cosmossdk.io/x/accounts/defaults/base => ../../x/accounts/defaults/base @@ -273,7 +274,6 @@ replace ( cosmossdk.io/x/staking => ../../x/staking cosmossdk.io/x/tx => ../../x/tx cosmossdk.io/x/upgrade => ../../x/upgrade - cosmossdk.io/core => ../../core ) // Below are the long-lived replace of the SimApp diff --git a/simapp/v2/go.sum b/simapp/v2/go.sum index f29f693d6539..ef92a1e9d11f 100644 --- a/simapp/v2/go.sum +++ b/simapp/v2/go.sum @@ -192,8 +192,6 @@ cloud.google.com/go/webrisk v1.4.0/go.mod h1:Hn8X6Zr+ziE2aNd8SliSDWpEnSS1u4R9+xX cloud.google.com/go/webrisk v1.5.0/go.mod h1:iPG6fr52Tv7sGk0H6qUFzmL3HHZev1htXuWDEEsqMTg= cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0= cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/simapp/v2/simdv2/cmd/commands.go b/simapp/v2/simdv2/cmd/commands.go index 3fcbed114d9e..baf25a8a883b 100644 --- a/simapp/v2/simdv2/cmd/commands.go +++ b/simapp/v2/simdv2/cmd/commands.go @@ -10,6 +10,7 @@ import ( "cosmossdk.io/client/v2/offchain" corectx "cosmossdk.io/core/context" + coreserver "cosmossdk.io/core/server" "cosmossdk.io/core/transaction" "cosmossdk.io/log" runtimev2 "cosmossdk.io/runtime/v2" @@ -40,11 +41,18 @@ func newApp[T transaction.Tx](logger log.Logger, viper *viper.Viper) serverv2.Ap return serverv2.AppI[T](simapp.NewSimApp[T](logger, viper)) } +type configWriter interface { + WriteConfig(filename string) error +} + func initRootCmd[T transaction.Tx]( rootCmd *cobra.Command, + logger log.Logger, + globalServerCfg coreserver.ConfigMap, txConfig client.TxConfig, moduleManager *runtimev2.MM[T], -) { + app serverv2.AppI[T], +) (configWriter, error) { cfg := sdk.GetConfig() cfg.Seal() @@ -55,11 +63,6 @@ func initRootCmd[T transaction.Tx]( NewTestnetCmd(moduleManager), ) - logger, err := serverv2.NewLogger(viper.New(), rootCmd.OutOrStdout()) - if err != nil { - panic(fmt.Sprintf("failed to create logger: %v", err)) - } - // add keybase, auxiliary RPC, query, genesis, and tx child commands rootCmd.AddCommand( genesisCommand(moduleManager), @@ -70,11 +73,11 @@ func initRootCmd[T transaction.Tx]( ) // wire server commands - if err = serverv2.AddCommands( + return serverv2.AddCommands( rootCmd, - newApp, + app, logger, - initServerConfig(), + globalServerCfg, cometbft.New( &genericTxDecoder[T]{txConfig}, initCometOptions[T](), @@ -83,9 +86,7 @@ func initRootCmd[T transaction.Tx]( grpc.New[T](), serverstore.New[T](), telemetry.New[T](), - ); err != nil { - panic(err) - } + ) } // genesisCommand builds genesis-related `simd genesis` command. @@ -93,8 +94,12 @@ func genesisCommand[T transaction.Tx]( moduleManager *runtimev2.MM[T], cmds ...*cobra.Command, ) *cobra.Command { + var genTxValidator func([]transaction.Msg) error + if moduleManager != nil { + genTxValidator = moduleManager.Modules()[genutiltypes.ModuleName].(genutil.AppModule).GenTxValidator() + } cmd := v2.Commands( - moduleManager.Modules()[genutiltypes.ModuleName].(genutil.AppModule), + genTxValidator, moduleManager, appExport[T], ) diff --git a/simapp/v2/simdv2/cmd/config.go b/simapp/v2/simdv2/cmd/config.go index 51a7adb178e9..16e72a51551f 100644 --- a/simapp/v2/simdv2/cmd/config.go +++ b/simapp/v2/simdv2/cmd/config.go @@ -58,6 +58,7 @@ gas-adjustment = {{ .GasConfig.GasAdjustment }} } // Allow the chain developer to overwrite the server default app toml config. +// TODO: show that this now depcreated function allowed no overriding of this parameter func initServerConfig() serverv2.ServerConfig { serverCfg := serverv2.DefaultServerConfig() // The server's default minimum gas price is set to "0stake" inside diff --git a/simapp/v2/simdv2/cmd/root_di.go b/simapp/v2/simdv2/cmd/root_di.go index 796ff20d4630..40f6972e87a2 100644 --- a/simapp/v2/simdv2/cmd/root_di.go +++ b/simapp/v2/simdv2/cmd/root_di.go @@ -1,28 +1,31 @@ package cmd import ( - "cosmossdk.io/core/server" - serverv2 "cosmossdk.io/server/v2" "fmt" - "github.com/spf13/cobra" - "github.com/spf13/pflag" "os" + "path/filepath" "strings" autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + "cosmossdk.io/core/server" + "cosmossdk.io/log" + serverv2 "cosmossdk.io/server/v2" + nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + "github.com/spf13/viper" + "cosmossdk.io/client/v2/autocli" clientv2helpers "cosmossdk.io/client/v2/helpers" "cosmossdk.io/core/address" "cosmossdk.io/core/registry" "cosmossdk.io/core/transaction" "cosmossdk.io/depinject" - "cosmossdk.io/log" "cosmossdk.io/runtime/v2" "cosmossdk.io/simapp/v2" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/config" - nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/x/auth/tx" @@ -42,10 +45,17 @@ and a parsed and configured one in the second. this can also be folded in and nuked: https://github.com/cosmos/cosmos-sdk/blob/6708818470826923b96ff7fb6ef55729d8c4269e/client/v2/helpers/home.go#L17 +DI happens before commands are even created and therefore before full CLI flags binding +In the DI phase only flags mentioned in server.ModuleConfigMap will be available from CLI +In the DI phase viper config is fully available, but not overrides from CLI flags +Server components are invoked on start. +Server components receive fully parse CLI flags since the Start invocation happens in command.RunE + */ type ModuleConfigMaps map[string]server.ConfigMap type FlagParser func() error +type GlobalConfig server.ConfigMap func ProvideModuleConfigMap( moduleConfigs []server.ModuleConfigMap, @@ -53,27 +63,29 @@ func ProvideModuleConfigMap( parseFlags FlagParser, ) (ModuleConfigMaps, error) { var err error + const bootstrapFlags = "__bootstrap" globalConfig := make(ModuleConfigMaps) + globalConfig[bootstrapFlags] = make(server.ConfigMap) for _, moduleConfig := range moduleConfigs { cfg := moduleConfig.Config name := moduleConfig.Module globalConfig[name] = make(server.ConfigMap) for flag, defaultValue := range cfg { globalConfig[name][flag] = defaultValue - switch defaultValue.(type) { + switch v := defaultValue.(type) { case string: _, maybeNotFound := flags.GetString(flag) if maybeNotFound != nil && strings.Contains(maybeNotFound.Error(), "flag accessed but not defined") { - flags.String(flag, defaultValue.(string), "") + flags.String(flag, v, "") } else { - // slightly skip the flag if it's already defined + // silently skip the flag if it's already defined continue } case []int: - flags.IntSlice(flag, defaultValue.([]int), "") + flags.IntSlice(flag, v, "") case int: - flags.Int(flag, defaultValue.(int), "") + flags.Int(flag, v, "") default: return nil, fmt.Errorf("unsupported type %T for flag %s", defaultValue, flag) } @@ -87,31 +99,28 @@ func ProvideModuleConfigMap( } for _, cfg := range globalConfig { for flag, defaulValue := range cfg { + var val any switch defaulValue.(type) { case string: - cfg[flag], err = flags.GetString(flag) + val, err = flags.GetString(flag) case []int: - cfg[flag], err = flags.GetIntSlice(flag) + val, err = flags.GetIntSlice(flag) case int: - cfg[flag], err = flags.GetInt(flag) + val, err = flags.GetInt(flag) default: return nil, fmt.Errorf("unsupported type %T for flag %s", defaulValue, flag) } if err != nil { return nil, err } + cfg[flag] = val + // also collect all flags into bootstrap config + globalConfig[bootstrapFlags][flag] = val } } return globalConfig, nil } -func ProvideModuleScopedConfigMap( - key depinject.ModuleKey, - moduleConfigs ModuleConfigMaps, -) server.ConfigMap { - return moduleConfigs[key.Name()] -} - // NewRootCmd creates a new root command for simd. It is called once in the main function. func NewRootCmd[T transaction.Tx](args []string) (*cobra.Command, error) { var ( @@ -119,77 +128,136 @@ func NewRootCmd[T transaction.Tx](args []string) (*cobra.Command, error) { moduleManager *runtime.MM[T] clientCtx client.Context ) + // parse config defaultHomeDir, err := clientv2helpers.DefaultHomeDir(".simappv2") if err != nil { return nil, err } - bootstrapCmd := &cobra.Command{} - bootstrapCmd.FParseErrWhitelist.UnknownFlags = true - bootstrapFlags := bootstrapCmd.PersistentFlags() - serverv2.SetPersistentFlags(bootstrapFlags, defaultHomeDir) - err = bootstrapCmd.ParseFlags(args) + + // initial bootstrap root command for config parsing + rootCmd := &cobra.Command{ + Use: "simdv2", + Short: "simulation app", + SilenceErrors: true, + } + serverv2.SetPersistentFlags(rootCmd.PersistentFlags(), defaultHomeDir) + // update the global viper with the root command's configuration + viper.SetEnvPrefix(clientv2helpers.EnvPrefix) + viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_")) + viper.AutomaticEnv() + + srv, err := initRootCmd[T](rootCmd, log.NewNopLogger(), nil, nil, nil, nil) + if err != nil { + return nil, err + } + cmd, _, err := rootCmd.Traverse(args) + if cmd == nil || err != nil { + return rootCmd, nil + } + if err = cmd.ParseFlags(args); err != nil { + return nil, err + } + home, err := cmd.Flags().GetString(serverv2.FlagHome) + if err != nil { + return nil, err + } + + configDir := filepath.Join(home, "config") + + // we need to check app.toml as the config folder can already exist for the client.toml + if _, err := os.Stat(filepath.Join(configDir, "app.toml")); os.IsNotExist(err) { + if err = srv.WriteConfig(configDir); err != nil { + return nil, err + } + } + vipr, err := serverv2.ReadConfig(configDir) + if err != nil { + return nil, err + } + if err := vipr.BindPFlags(cmd.Flags()); err != nil { + return nil, err + } + logger, err := serverv2.NewLogger(vipr, cmd.OutOrStdout()) + if err != nil { + return nil, err + } + err = serverv2.SetCmdServerContext(cmd, vipr, logger) if err != nil { return nil, err } - flagParser := FlagParser(func() error { - return bootstrapCmd.ParseFlags(args) - }) - - if err = depinject.Inject( - depinject.Configs( - simapp.AppConfig(), - depinject.Provide( - ProvideClientContext, - ProvideModuleConfigMap, - ProvideModuleScopedConfigMap, + globalConfig := vipr.AllSettings() + + var app serverv2.AppI[T] + if needsApp(cmd) { + app, err = simapp.NewSimAppWithConfig[T]( + depinject.Configs( + depinject.Supply(logger, simapp.GlobalConfig(globalConfig)), + depinject.Provide(ProvideClientContext), ), - depinject.Supply( - log.NewNopLogger(), - flagParser, - bootstrapCmd.Flags(), + &autoCliOpts, &moduleManager, &clientCtx) + if err != nil { + return nil, err + } + } else { + if err = depinject.Inject( + depinject.Configs( + simapp.AppConfig(), + depinject.Provide( + ProvideClientContext, + ), + depinject.Supply( + logger, + globalConfig, + ), ), - ), - &autoCliOpts, - &moduleManager, - &clientCtx, - ); err != nil { - return nil, err + &autoCliOpts, + &moduleManager, + &clientCtx, + ); err != nil { + return nil, err + } } - rootCmd := &cobra.Command{ + // final root command + rootCmd = &cobra.Command{ Use: "simdv2", Short: "simulation app", SilenceErrors: true, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { - fmt.Printf("simd root command persistent pre-run %+v\n", args) clientCtx = clientCtx.WithCmdContext(cmd.Context()) - clientCtx, err := client.ReadPersistentCommandFlags(clientCtx, cmd.Flags()) + clientCtx, err = client.ReadPersistentCommandFlags(clientCtx, cmd.Flags()) if err != nil { return err } customClientTemplate, customClientConfig := initClientConfig() - clientCtx, err = config.CreateClientConfig(clientCtx, customClientTemplate, customClientConfig) + clientCtx, err = config.CreateClientConfig( + clientCtx, customClientTemplate, customClientConfig) if err != nil { return err } - if err := client.SetCmdClientContextHandler(clientCtx, cmd); err != nil { + if err = client.SetCmdClientContextHandler(clientCtx, cmd); err != nil { return err } return nil }, } - - initRootCmd(rootCmd, clientCtx.TxConfig, moduleManager) - + serverv2.SetPersistentFlags(rootCmd.PersistentFlags(), defaultHomeDir) + err = serverv2.SetCmdServerContext(rootCmd, vipr, logger) + if err != nil { + return nil, err + } + srv, err = initRootCmd[T](rootCmd, logger, globalConfig, clientCtx.TxConfig, moduleManager, app) + if err != nil { + return nil, err + } nodeCmds := nodeservice.NewNodeCommands() autoCliOpts.ModuleOptions = make(map[string]*autocliv1.ModuleOptions) autoCliOpts.ModuleOptions[nodeCmds.Name()] = nodeCmds.AutoCLIOptions() - if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil { - panic(err) + return nil, err } return rootCmd, nil @@ -240,3 +308,13 @@ func ProvideClientContext( return clientCtx } + +func needsApp(cmd *cobra.Command) bool { + if cmd.Annotations["needs-app"] == "true" { + return true + } + if cmd.Parent() == nil { + return false + } + return needsApp(cmd.Parent()) +} diff --git a/simapp/v2/simdv2/main.go b/simapp/v2/simdv2/main.go index ae5dce37f3fa..1ac9111d5b7d 100644 --- a/simapp/v2/simdv2/main.go +++ b/simapp/v2/simdv2/main.go @@ -5,10 +5,7 @@ import ( "fmt" "os" - clientv2helpers "cosmossdk.io/client/v2/helpers" "cosmossdk.io/core/transaction" - serverv2 "cosmossdk.io/server/v2" - "cosmossdk.io/simapp/v2" "cosmossdk.io/simapp/v2/simdv2/cmd" ) @@ -22,7 +19,7 @@ func main() { } os.Exit(1) } - if err := serverv2.Execute(rootCmd, clientv2helpers.EnvPrefix, simapp.DefaultNodeHome); err != nil { + if err := rootCmd.Execute(); err != nil { fmt.Fprintln(rootCmd.OutOrStderr(), err) os.Exit(1) } diff --git a/x/genutil/client/cli/collect.go b/x/genutil/client/cli/collect.go index ff3da30d5bdb..274d1dcf68bf 100644 --- a/x/genutil/client/cli/collect.go +++ b/x/genutil/client/cli/collect.go @@ -1,6 +1,7 @@ package cli import ( + "cosmossdk.io/core/transaction" "encoding/json" "path/filepath" @@ -16,7 +17,7 @@ import ( const flagGenTxDir = "gentx-dir" // CollectGenTxsCmd - return the cobra command to collect genesis transactions -func CollectGenTxsCmd(validator types.MessageValidator) *cobra.Command { +func CollectGenTxsCmd(validator func([]transaction.Msg) error) *cobra.Command { cmd := &cobra.Command{ Use: "collect-gentxs", Short: "Collect genesis txs and output a genesis.json file", @@ -50,7 +51,9 @@ func CollectGenTxsCmd(validator types.MessageValidator) *cobra.Command { toPrint := newPrintInfo(config.Moniker, appGenesis.ChainID, nodeID, genTxsDir, json.RawMessage("")) initCfg := types.NewInitConfig(appGenesis.ChainID, genTxsDir, nodeID, valPubKey) - appMessage, err := genutil.GenAppStateFromConfig(cdc, clientCtx.TxConfig, config, initCfg, appGenesis, validator, clientCtx.ValidatorAddressCodec, clientCtx.AddressCodec) + appMessage, err := genutil.GenAppStateFromConfig( + cdc, clientCtx.TxConfig, config, initCfg, appGenesis, + validator, clientCtx.ValidatorAddressCodec, clientCtx.AddressCodec) if err != nil { return errors.Wrap(err, "failed to get genesis app state from config") } diff --git a/x/genutil/v2/cli/commands.go b/x/genutil/v2/cli/commands.go index 7b871ec074a4..8dddd1713715 100644 --- a/x/genutil/v2/cli/commands.go +++ b/x/genutil/v2/cli/commands.go @@ -1,6 +1,7 @@ package cli import ( + "cosmossdk.io/core/transaction" "encoding/json" "github.com/spf13/cobra" @@ -8,7 +9,6 @@ import ( banktypes "cosmossdk.io/x/bank/types" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/x/genutil" "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" v2 "github.com/cosmos/cosmos-sdk/x/genutil/v2" @@ -20,14 +20,18 @@ type genesisMM interface { } // Commands adds core sdk's sub-commands into genesis command. -func Commands(genutilModule genutil.AppModule, genMM genesisMM, appExport v2.AppExporter) *cobra.Command { - return CommandsWithCustomMigrationMap(genutilModule, genMM, appExport, cli.MigrationMap) +func Commands( + genTxValidator func([]transaction.Msg) error, + genMM genesisMM, + appExport v2.AppExporter, +) *cobra.Command { + return CommandsWithCustomMigrationMap(genTxValidator, genMM, appExport, cli.MigrationMap) } // CommandsWithCustomMigrationMap adds core sdk's sub-commands into genesis command with custom migration map. // This custom migration map can be used by the application to add its own migration map. func CommandsWithCustomMigrationMap( - genutilModule genutil.AppModule, + genTxValidator func([]transaction.Msg) error, genMM genesisMM, appExport v2.AppExporter, migrationMap genutiltypes.MigrationMap, @@ -42,7 +46,7 @@ func CommandsWithCustomMigrationMap( cmd.AddCommand( cli.GenTxCmd(genMM, banktypes.GenesisBalancesIterator{}), cli.MigrateGenesisCmd(migrationMap), - cli.CollectGenTxsCmd(genutilModule.GenTxValidator()), + cli.CollectGenTxsCmd(genTxValidator), cli.ValidateGenesisCmd(genMM), cli.AddGenesisAccountCmd(), ExportCmd(appExport), diff --git a/x/genutil/v2/cli/export.go b/x/genutil/v2/cli/export.go index 9b0d992bad0a..5faa86a5d89c 100644 --- a/x/genutil/v2/cli/export.go +++ b/x/genutil/v2/cli/export.go @@ -24,9 +24,10 @@ const ( // ExportCmd dumps app state to JSON. func ExportCmd(appExporter v2.AppExporter) *cobra.Command { cmd := &cobra.Command{ - Use: "export", - Short: "Export state to JSON", - Args: cobra.NoArgs, + Use: "export", + Short: "Export state to JSON", + Args: cobra.NoArgs, + Annotations: map[string]string{"needs-app": "true"}, RunE: func(cmd *cobra.Command, _ []string) error { config := client.GetConfigFromCmd(cmd) diff --git a/x/upgrade/go.mod b/x/upgrade/go.mod index 9c930907e927..66e61f9e88f9 100644 --- a/x/upgrade/go.mod +++ b/x/upgrade/go.mod @@ -202,10 +202,10 @@ replace github.com/cosmos/cosmos-sdk => ../../. replace ( cosmossdk.io/api => ../../api + cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/gov => ../gov cosmossdk.io/x/staking => ../staking cosmossdk.io/x/tx => ../tx - cosmossdk.io/core => ../../core ) diff --git a/x/upgrade/go.sum b/x/upgrade/go.sum index 026ac0a983fc..93243d2bd473 100644 --- a/x/upgrade/go.sum +++ b/x/upgrade/go.sum @@ -194,8 +194,6 @@ cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1V cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= From 3803716912c80dde7f05c4ab82a72d3ae5311b75 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Mon, 14 Oct 2024 19:04:23 -0500 Subject: [PATCH 04/46] even more clean up --- server/v2/commands.go | 14 +++++--------- simapp/v2/simdv2/cmd/commands.go | 4 ++-- simapp/v2/simdv2/cmd/root_di.go | 4 +++- x/upgrade/depinject.go | 13 ++++--------- x/validate/depinject.go | 26 ++++++++++++-------------- 5 files changed, 26 insertions(+), 35 deletions(-) diff --git a/server/v2/commands.go b/server/v2/commands.go index 3d8f5b079e67..4b26a64d94d7 100644 --- a/server/v2/commands.go +++ b/server/v2/commands.go @@ -56,7 +56,7 @@ func AddCommands[T transaction.Tx]( server := NewServer(logger, initServerConfig(), components...) cmds := server.CLICommands() - startCmd := createStartCommand(server, app) + startCmd := createStartCommand(server, app, globalServerCfg, logger) // TODO necessary? won't the parent context be inherited? startCmd.SetContext(rootCmd.Context()) cmds.Commands = append(cmds.Commands, startCmd) @@ -90,6 +90,8 @@ func AddCommands[T transaction.Tx]( func createStartCommand[T transaction.Tx]( server *Server[T], app AppI[T], + config server.ConfigMap, + logger log.Logger, ) *cobra.Command { flags := server.StartFlags() @@ -98,16 +100,10 @@ func createStartCommand[T transaction.Tx]( Short: "Run the application", Annotations: map[string]string{"needs-app": "true"}, RunE: func(cmd *cobra.Command, args []string) error { - v := GetViperFromCmd(cmd) - l := GetLoggerFromCmd(cmd) - if err := v.BindPFlags(cmd.Flags()); err != nil { + err := server.Init(app, config, logger) + if err != nil { return err } - - if err := server.Init(app, v.AllSettings(), l); err != nil { - return err - } - ctx, cancelFn := context.WithCancel(cmd.Context()) go func() { sigCh := make(chan os.Signal, 1) diff --git a/simapp/v2/simdv2/cmd/commands.go b/simapp/v2/simdv2/cmd/commands.go index baf25a8a883b..2e859f15268c 100644 --- a/simapp/v2/simdv2/cmd/commands.go +++ b/simapp/v2/simdv2/cmd/commands.go @@ -48,7 +48,7 @@ type configWriter interface { func initRootCmd[T transaction.Tx]( rootCmd *cobra.Command, logger log.Logger, - globalServerCfg coreserver.ConfigMap, + globalAppConfig coreserver.ConfigMap, txConfig client.TxConfig, moduleManager *runtimev2.MM[T], app serverv2.AppI[T], @@ -77,7 +77,7 @@ func initRootCmd[T transaction.Tx]( rootCmd, app, logger, - globalServerCfg, + globalAppConfig, cometbft.New( &genericTxDecoder[T]{txConfig}, initCometOptions[T](), diff --git a/simapp/v2/simdv2/cmd/root_di.go b/simapp/v2/simdv2/cmd/root_di.go index 40f6972e87a2..1de7031e5247 100644 --- a/simapp/v2/simdv2/cmd/root_di.go +++ b/simapp/v2/simdv2/cmd/root_di.go @@ -163,7 +163,6 @@ func NewRootCmd[T transaction.Tx](args []string) (*cobra.Command, error) { } configDir := filepath.Join(home, "config") - // we need to check app.toml as the config folder can already exist for the client.toml if _, err := os.Stat(filepath.Join(configDir, "app.toml")); os.IsNotExist(err) { if err = srv.WriteConfig(configDir); err != nil { @@ -244,6 +243,9 @@ func NewRootCmd[T transaction.Tx](args []string) (*cobra.Command, error) { return nil }, } + // TODO push down to server subcommands only + // but also audit the usage of logger and viper in fetching from context, probably no + // longer needed. serverv2.SetPersistentFlags(rootCmd.PersistentFlags(), defaultHomeDir) err = serverv2.SetCmdServerContext(rootCmd, vipr, logger) if err != nil { diff --git a/x/upgrade/depinject.go b/x/upgrade/depinject.go index 28befab7ca6b..2a8305e9bad2 100644 --- a/x/upgrade/depinject.go +++ b/x/upgrade/depinject.go @@ -51,8 +51,6 @@ type ModuleInputs struct { AddressCodec address.Codec AppVersionModifier coreserver.VersionModifier ConsensusKeeper types.ConsensusKeeper - - DynamicConfig coreserver.DynamicConfig `optional:"true"` } type ModuleOutputs struct { @@ -68,14 +66,11 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { skipUpgradeHeights = make(map[int64]bool) ) - if in.DynamicConfig != nil { - skipUpgrades := cast.ToIntSlice(in.DynamicConfig.Get(server.FlagUnsafeSkipUpgrades)) - for _, h := range skipUpgrades { - skipUpgradeHeights[int64(h)] = true - } - - homePath = in.DynamicConfig.GetString(flags.FlagHome) + skipUpgrades := cast.ToIntSlice(in.ConfigMap[server.FlagUnsafeSkipUpgrades]) + for _, h := range skipUpgrades { + skipUpgradeHeights[int64(h)] = true } + homePath = cast.ToString(in.ConfigMap[flags.FlagHome]) // default to governance authority if not provided authority := authtypes.NewModuleAddress(types.GovModuleName) diff --git a/x/validate/depinject.go b/x/validate/depinject.go index 0f6cc5dd549d..bfe6f7384044 100644 --- a/x/validate/depinject.go +++ b/x/validate/depinject.go @@ -18,6 +18,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/ante/unorderedtx" "github.com/cosmos/cosmos-sdk/x/auth/posthandler" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/spf13/cast" ) // flagMinGasPricesV2 is the flag name for the minimum gas prices in the main server v2 component. @@ -41,11 +42,10 @@ func ProvideConfig(key depinject.OwnModuleKey) server.ModuleConfigMap { type ModuleInputs struct { depinject.In - ModuleConfig *modulev1.Module - Environment appmodulev2.Environment - TxConfig client.TxConfig - DynamicConfig server.DynamicConfig `optional:"true"` - ConfigMap server.ConfigMap + ModuleConfig *modulev1.Module + Environment appmodulev2.Environment + TxConfig client.TxConfig + ConfigMap server.ConfigMap AccountKeeper ante.AccountKeeper BankKeeper authtypes.BankKeeper @@ -79,17 +79,15 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { unorderedTxValidator *ante.UnorderedTxDecorator ) - if in.DynamicConfig != nil { - minGasPricesStr := in.DynamicConfig.GetString(flagMinGasPricesV2) - minGasPrices, err = sdk.ParseDecCoins(minGasPricesStr) - if err != nil { - panic(fmt.Sprintf("invalid minimum gas prices: %v", err)) - } - - feeTxValidator = ante.NewDeductFeeDecorator(in.AccountKeeper, in.BankKeeper, in.FeeGrantKeeper, in.TxFeeChecker) - feeTxValidator.SetMinGasPrices(minGasPrices) // set min gas price in deduct fee decorator + minGasPricesStr := cast.ToString(in.ConfigMap[flagMinGasPricesV2]) + minGasPrices, err = sdk.ParseDecCoins(minGasPricesStr) + if err != nil { + panic(fmt.Sprintf("invalid minimum gas prices: %v", err)) } + feeTxValidator = ante.NewDeductFeeDecorator(in.AccountKeeper, in.BankKeeper, in.FeeGrantKeeper, in.TxFeeChecker) + feeTxValidator.SetMinGasPrices(minGasPrices) // set min gas price in deduct fee decorator + if in.UnorderedTxManager != nil { unorderedTxValidator = ante.NewUnorderedTxDecorator(unorderedtx.DefaultMaxTimeoutDuration, in.UnorderedTxManager, in.Environment, ante.DefaultSha256Cost) } From 30d1789839741252f6ced02fca7f1b2e09d61e0f Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Mon, 14 Oct 2024 23:18:20 -0500 Subject: [PATCH 05/46] genesis export working --- simapp/v2/simdv2/cmd/commands.go | 53 +++----------------------------- simapp/v2/simdv2/cmd/root_di.go | 7 +++-- x/genutil/v2/cli/commands.go | 13 +++++--- x/genutil/v2/cli/export.go | 14 ++++++--- 4 files changed, 27 insertions(+), 60 deletions(-) diff --git a/simapp/v2/simdv2/cmd/commands.go b/simapp/v2/simdv2/cmd/commands.go index 2e859f15268c..6dd95d241eb8 100644 --- a/simapp/v2/simdv2/cmd/commands.go +++ b/simapp/v2/simdv2/cmd/commands.go @@ -1,15 +1,12 @@ package cmd import ( - "context" "errors" - "fmt" "github.com/spf13/cobra" "github.com/spf13/viper" "cosmossdk.io/client/v2/offchain" - corectx "cosmossdk.io/core/context" coreserver "cosmossdk.io/core/server" "cosmossdk.io/core/transaction" "cosmossdk.io/log" @@ -26,13 +23,11 @@ import ( "github.com/cosmos/cosmos-sdk/client/debug" "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/client/rpc" - "github.com/cosmos/cosmos-sdk/server" sdk "github.com/cosmos/cosmos-sdk/types" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" "github.com/cosmos/cosmos-sdk/x/genutil" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" - genutilv2 "github.com/cosmos/cosmos-sdk/x/genutil/v2" v2 "github.com/cosmos/cosmos-sdk/x/genutil/v2/cli" ) @@ -51,7 +46,7 @@ func initRootCmd[T transaction.Tx]( globalAppConfig coreserver.ConfigMap, txConfig client.TxConfig, moduleManager *runtimev2.MM[T], - app serverv2.AppI[T], + app *simapp.SimApp[T], ) (configWriter, error) { cfg := sdk.GetConfig() cfg.Seal() @@ -65,7 +60,7 @@ func initRootCmd[T transaction.Tx]( // add keybase, auxiliary RPC, query, genesis, and tx child commands rootCmd.AddCommand( - genesisCommand(moduleManager), + genesisCommand(moduleManager, app), queryCommand(), txCommand(), keys.Commands(), @@ -92,7 +87,7 @@ func initRootCmd[T transaction.Tx]( // genesisCommand builds genesis-related `simd genesis` command. func genesisCommand[T transaction.Tx]( moduleManager *runtimev2.MM[T], - cmds ...*cobra.Command, + app *simapp.SimApp[T], ) *cobra.Command { var genTxValidator func([]transaction.Msg) error if moduleManager != nil { @@ -101,12 +96,9 @@ func genesisCommand[T transaction.Tx]( cmd := v2.Commands( genTxValidator, moduleManager, - appExport[T], + app, ) - for _, subCmd := range cmds { - cmd.AddCommand(subCmd) - } return cmd } @@ -153,43 +145,6 @@ func txCommand() *cobra.Command { return cmd } -// appExport creates a new simapp (optionally at a given height) and exports state. -func appExport[T transaction.Tx]( - ctx context.Context, - height int64, - jailAllowedAddrs []string, -) (genutilv2.ExportedApp, error) { - value := ctx.Value(corectx.ViperContextKey) - viper, ok := value.(*viper.Viper) - if !ok { - return genutilv2.ExportedApp{}, - fmt.Errorf("incorrect viper type %T: expected *viper.Viper in context", value) - } - value = ctx.Value(corectx.LoggerContextKey) - logger, ok := value.(log.Logger) - if !ok { - return genutilv2.ExportedApp{}, - fmt.Errorf("incorrect logger type %T: expected log.Logger in context", value) - } - - // overwrite the FlagInvCheckPeriod - viper.Set(server.FlagInvCheckPeriod, 1) - viper.Set(serverv2.FlagHome, simapp.DefaultNodeHome) - - var simApp *simapp.SimApp[T] - if height != -1 { - simApp = simapp.NewSimApp[T](logger, viper) - - if err := simApp.LoadHeight(uint64(height)); err != nil { - return genutilv2.ExportedApp{}, err - } - } else { - simApp = simapp.NewSimApp[T](logger, viper) - } - - return simApp.ExportAppStateAndValidators(jailAllowedAddrs) -} - var _ transaction.Codec[transaction.Tx] = &genericTxDecoder[transaction.Tx]{} type genericTxDecoder[T transaction.Tx] struct { diff --git a/simapp/v2/simdv2/cmd/root_di.go b/simapp/v2/simdv2/cmd/root_di.go index 1de7031e5247..235d20a60cfc 100644 --- a/simapp/v2/simdv2/cmd/root_di.go +++ b/simapp/v2/simdv2/cmd/root_di.go @@ -155,6 +155,9 @@ func NewRootCmd[T transaction.Tx](args []string) (*cobra.Command, error) { return rootCmd, nil } if err = cmd.ParseFlags(args); err != nil { + if err.Error() == "pflag: help requested" { + return cmd, nil + } return nil, err } home, err := cmd.Flags().GetString(serverv2.FlagHome) @@ -186,7 +189,7 @@ func NewRootCmd[T transaction.Tx](args []string) (*cobra.Command, error) { } globalConfig := vipr.AllSettings() - var app serverv2.AppI[T] + var app *simapp.SimApp[T] if needsApp(cmd) { app, err = simapp.NewSimAppWithConfig[T]( depinject.Configs( @@ -206,7 +209,7 @@ func NewRootCmd[T transaction.Tx](args []string) (*cobra.Command, error) { ), depinject.Supply( logger, - globalConfig, + simapp.GlobalConfig(globalConfig), ), ), &autoCliOpts, diff --git a/x/genutil/v2/cli/commands.go b/x/genutil/v2/cli/commands.go index 8dddd1713715..92a409f9bc68 100644 --- a/x/genutil/v2/cli/commands.go +++ b/x/genutil/v2/cli/commands.go @@ -19,13 +19,18 @@ type genesisMM interface { ValidateGenesis(genesisData map[string]json.RawMessage) error } +type exportableApp interface { + ExportAppStateAndValidators([]string) (v2.ExportedApp, error) + LoadHeight(uint64) error +} + // Commands adds core sdk's sub-commands into genesis command. func Commands( genTxValidator func([]transaction.Msg) error, genMM genesisMM, - appExport v2.AppExporter, + exportable exportableApp, ) *cobra.Command { - return CommandsWithCustomMigrationMap(genTxValidator, genMM, appExport, cli.MigrationMap) + return CommandsWithCustomMigrationMap(genTxValidator, genMM, exportable, cli.MigrationMap) } // CommandsWithCustomMigrationMap adds core sdk's sub-commands into genesis command with custom migration map. @@ -33,7 +38,7 @@ func Commands( func CommandsWithCustomMigrationMap( genTxValidator func([]transaction.Msg) error, genMM genesisMM, - appExport v2.AppExporter, + exportable exportableApp, migrationMap genutiltypes.MigrationMap, ) *cobra.Command { cmd := &cobra.Command{ @@ -49,7 +54,7 @@ func CommandsWithCustomMigrationMap( cli.CollectGenTxsCmd(genTxValidator), cli.ValidateGenesisCmd(genMM), cli.AddGenesisAccountCmd(), - ExportCmd(appExport), + ExportCmd(exportable), ) return cmd diff --git a/x/genutil/v2/cli/export.go b/x/genutil/v2/cli/export.go index 5faa86a5d89c..390e8e1390dd 100644 --- a/x/genutil/v2/cli/export.go +++ b/x/genutil/v2/cli/export.go @@ -13,7 +13,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/version" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" - v2 "github.com/cosmos/cosmos-sdk/x/genutil/v2" ) const ( @@ -22,7 +21,7 @@ const ( ) // ExportCmd dumps app state to JSON. -func ExportCmd(appExporter v2.AppExporter) *cobra.Command { +func ExportCmd(app exportableApp) *cobra.Command { cmd := &cobra.Command{ Use: "export", Short: "Export state to JSON", @@ -35,7 +34,7 @@ func ExportCmd(appExporter v2.AppExporter) *cobra.Command { return err } - if appExporter == nil { + if app == nil { if _, err := fmt.Fprintln(cmd.ErrOrStderr(), "WARNING: App exporter not defined. Returning genesis file."); err != nil { return err } @@ -60,8 +59,13 @@ func ExportCmd(appExporter v2.AppExporter) *cobra.Command { height, _ := cmd.Flags().GetInt64(flagHeight) jailAllowedAddrs, _ := cmd.Flags().GetStringSlice(flagJailAllowedAddrs) outputDocument, _ := cmd.Flags().GetString(flags.FlagOutputDocument) - - exported, err := appExporter(cmd.Context(), height, jailAllowedAddrs) + fmt.Printf("height: %d\n", height) + if height != -1 { + if err := app.LoadHeight(uint64(height)); err != nil { + return err + } + } + exported, err := app.ExportAppStateAndValidators(jailAllowedAddrs) if err != nil { return fmt.Errorf("error exporting state: %w", err) } From 23780e2e22af6fc6426e23930d239d690970b8d0 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Tue, 15 Oct 2024 02:35:02 -0500 Subject: [PATCH 06/46] only build store in app builder --- runtime/v2/builder.go | 10 ++++++---- runtime/v2/module.go | 7 +++---- server/v2/commands.go | 7 +++++++ simapp/v2/app_di.go | 9 +++++---- simapp/v2/simdv2/cmd/root_di.go | 4 ---- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/runtime/v2/builder.go b/runtime/v2/builder.go index adb177d41eb0..b0331504234e 100644 --- a/runtime/v2/builder.go +++ b/runtime/v2/builder.go @@ -24,6 +24,7 @@ import ( type AppBuilder[T transaction.Tx] struct { app *App[T] storeBuilder root.Builder + storeConfig *root.Config // the following fields are used to overwrite the default branch func(state store.ReaderMap) store.WriterMap @@ -87,12 +88,13 @@ func (a *AppBuilder[T]) Build(opts ...AppBuilderOption[T]) (*App[T], error) { } } - a.app.db = a.storeBuilder.Get() - if a.app.db == nil { - return nil, fmt.Errorf("storeBuilder did not return a db") + var err error + a.app.db, err = a.storeBuilder.Build(a.app.logger, a.storeConfig) + if err != nil { + return nil, err } - if err := a.app.moduleManager.RegisterServices(a.app); err != nil { + if err = a.app.moduleManager.RegisterServices(a.app); err != nil { return nil, err } diff --git a/runtime/v2/module.go b/runtime/v2/module.go index bdb4c7a340bd..dd4ae7d4f8d1 100644 --- a/runtime/v2/module.go +++ b/runtime/v2/module.go @@ -108,6 +108,7 @@ func ProvideAppBuilder[T transaction.Tx]( interfaceRegistrar registry.InterfaceRegistrar, amino registry.AminoRegistrar, storeBuilder root.Builder, + storeConfig *root.Config, ) ( *AppBuilder[T], *stf.MsgRouterBuilder, @@ -134,7 +135,7 @@ func ProvideAppBuilder[T transaction.Tx]( QueryHandlers: map[string]appmodulev2.Handler{}, storeLoader: DefaultStoreLoader, } - appBuilder := &AppBuilder[T]{app: app, storeBuilder: storeBuilder} + appBuilder := &AppBuilder[T]{app: app, storeBuilder: storeBuilder, storeConfig: storeConfig} return appBuilder, msgRouterBuilder, appModule[T]{app}, protoFiles, protoTypes } @@ -152,7 +153,7 @@ type AppInputs struct { StoreBuilder root.Builder } -func SetupAppBuilder(inputs AppInputs) error { +func SetupAppBuilder(inputs AppInputs) { app := inputs.AppBuilder.app app.config = inputs.Config app.logger = inputs.Logger @@ -161,8 +162,6 @@ func SetupAppBuilder(inputs AppInputs) error { app.moduleManager.RegisterLegacyAminoCodec(inputs.LegacyAmino) // STF requires some state to run inputs.StoreBuilder.RegisterKey("stf") - _, err := inputs.StoreBuilder.Build(inputs.Logger, inputs.StoreConfig) - return err } func ProvideModuleManager[T transaction.Tx]( diff --git a/server/v2/commands.go b/server/v2/commands.go index 4b26a64d94d7..64b7bf894885 100644 --- a/server/v2/commands.go +++ b/server/v2/commands.go @@ -100,6 +100,13 @@ func createStartCommand[T transaction.Tx]( Short: "Run the application", Annotations: map[string]string{"needs-app": "true"}, RunE: func(cmd *cobra.Command, args []string) error { + // TODO: Init is no longer needed as a distinct life cycle phase due to + // eager config parsing. Therefore, consider one of: + // 1) pull .Init() up closer to ServerComponent constructor call + // 2) remove .Init() as a separate phase, move work (and dependencies) + // into the constructor directly. + // + // Note that (2) could mean the removal of AppI err := server.Init(app, config, logger) if err != nil { return err diff --git a/simapp/v2/app_di.go b/simapp/v2/app_di.go index ebaa8503d18a..6dd4e5fd40ad 100644 --- a/simapp/v2/app_di.go +++ b/simapp/v2/app_di.go @@ -116,16 +116,17 @@ func NewSimAppWithConfig[T transaction.Tx]( return nil, err } - app.store = storeBuilder.Get() - if app.store == nil { - return nil, fmt.Errorf("store builder not return a db") - } var err error app.App, err = appBuilder.Build() if err != nil { return nil, err } + app.store = storeBuilder.Get() + if app.store == nil { + return nil, fmt.Errorf("store builder not return a db") + } + /**** Module Options ****/ // RegisterUpgradeHandlers is used for registering any on-chain upgrades. diff --git a/simapp/v2/simdv2/cmd/root_di.go b/simapp/v2/simdv2/cmd/root_di.go index 235d20a60cfc..d95c198b7d7b 100644 --- a/simapp/v2/simdv2/cmd/root_di.go +++ b/simapp/v2/simdv2/cmd/root_di.go @@ -183,10 +183,6 @@ func NewRootCmd[T transaction.Tx](args []string) (*cobra.Command, error) { if err != nil { return nil, err } - err = serverv2.SetCmdServerContext(cmd, vipr, logger) - if err != nil { - return nil, err - } globalConfig := vipr.AllSettings() var app *simapp.SimApp[T] From da16c69252b591fa02dd709fdf39c3d4f699e214 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Tue, 22 Oct 2024 21:09:19 -0500 Subject: [PATCH 07/46] wipg --- server/v2/api/telemetry/server.go | 35 ++++++------- server/v2/cometbft/go.mod | 1 + server/v2/cometbft/server.go | 84 ++++++++++++++++++------------- simapp/v2/simdv2/cmd/commands.go | 36 +++++++------ simapp/v2/simdv2/cmd/root_di.go | 20 ++++++++ 5 files changed, 104 insertions(+), 72 deletions(-) diff --git a/server/v2/api/telemetry/server.go b/server/v2/api/telemetry/server.go index 411b1bda797d..eb2d58efa6b7 100644 --- a/server/v2/api/telemetry/server.go +++ b/server/v2/api/telemetry/server.go @@ -2,6 +2,7 @@ package telemetry import ( "context" + "cosmossdk.io/core/server" "encoding/json" "fmt" "net/http" @@ -27,8 +28,23 @@ type Server[T transaction.Tx] struct { } // New creates a new telemetry server. -func New[T transaction.Tx]() *Server[T] { - return &Server[T]{} +func New[T transaction.Tx](cfg server.ConfigMap, logger log.Logger) (*Server[T], error) { + srv := &Server[T]{} + serverCfg := srv.Config().(*Config) + if len(cfg) > 0 { + if err := serverv2.UnmarshalSubConfig(cfg, srv.Name(), &serverCfg); err != nil { + return nil, fmt.Errorf("failed to unmarshal config: %w", err) + } + } + srv.config = serverCfg + srv.logger = logger.With(log.ModuleKey, srv.Name()) + + metrics, err := NewMetrics(srv.config) + if err != nil { + return nil, fmt.Errorf("failed to initialize metrics: %w", err) + } + srv.metrics = metrics + return srv, nil } // Name returns the server name. @@ -46,21 +62,6 @@ func (s *Server[T]) Config() any { // Init implements serverv2.ServerComponent. func (s *Server[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logger log.Logger) error { - serverCfg := s.Config().(*Config) - if len(cfg) > 0 { - if err := serverv2.UnmarshalSubConfig(cfg, s.Name(), &serverCfg); err != nil { - return fmt.Errorf("failed to unmarshal config: %w", err) - } - } - s.config = serverCfg - s.logger = logger.With(log.ModuleKey, s.Name()) - - metrics, err := NewMetrics(s.config) - if err != nil { - return fmt.Errorf("failed to initialize metrics: %w", err) - } - s.metrics = metrics - return nil } diff --git a/server/v2/cometbft/go.mod b/server/v2/cometbft/go.mod index c95f22af817a..a0afde5dba78 100644 --- a/server/v2/cometbft/go.mod +++ b/server/v2/cometbft/go.mod @@ -13,6 +13,7 @@ replace ( cosmossdk.io/x/consensus => ../../../x/consensus cosmossdk.io/x/staking => ../../../x/staking cosmossdk.io/x/tx => ../../../x/tx + cosmossdk.io/core => ../../../core github.com/cosmos/cosmos-sdk => ../../../ ) diff --git a/server/v2/cometbft/server.go b/server/v2/cometbft/server.go index e5076b897073..0677f848b801 100644 --- a/server/v2/cometbft/server.go +++ b/server/v2/cometbft/server.go @@ -2,6 +2,10 @@ package cometbft import ( "context" + appmodulev2 "cosmossdk.io/core/appmodule/v2" + "cosmossdk.io/core/server" + "cosmossdk.io/server/v2/appmanager" + "cosmossdk.io/server/v2/cometbft/types" "crypto/sha256" "encoding/json" "fmt" @@ -48,34 +52,38 @@ type CometBFTServer[T transaction.Tx] struct { } func New[T transaction.Tx]( + logger log.Logger, + appName string, + store types.Store, + appManager *appmanager.AppManager[T], + queryHandlers map[string]appmodulev2.Handler, txCodec transaction.Codec[T], + cfg server.ConfigMap, serverOptions ServerOptions[T], cfgOptions ...CfgOption, -) *CometBFTServer[T] { - return &CometBFTServer[T]{ +) (*CometBFTServer[T], error) { + srv := &CometBFTServer[T]{ initTxCodec: txCodec, serverOptions: serverOptions, cfgOptions: cfgOptions, } -} -func (s *CometBFTServer[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logger log.Logger) error { home, _ := cfg[serverv2.FlagHome].(string) // get configs (app.toml + config.toml) from viper - appTomlConfig := s.Config().(*AppTomlConfig) + appTomlConfig := srv.Config().(*AppTomlConfig) configTomlConfig := cmtcfg.DefaultConfig().SetRoot(home) if len(cfg) > 0 { - if err := serverv2.UnmarshalSubConfig(cfg, s.Name(), &appTomlConfig); err != nil { - return fmt.Errorf("failed to unmarshal config: %w", err) + if err := serverv2.UnmarshalSubConfig(cfg, srv.Name(), &appTomlConfig); err != nil { + return nil, fmt.Errorf("failed to unmarshal config: %w", err) } if err := serverv2.UnmarshalSubConfig(cfg, "", &configTomlConfig); err != nil { - return fmt.Errorf("failed to unmarshal config: %w", err) + return nil, fmt.Errorf("failed to unmarshal config: %w", err) } } - s.config = Config{ + srv.config = Config{ ConfigTomlConfig: configTomlConfig, AppTomlConfig: appTomlConfig, } @@ -95,44 +103,48 @@ func (s *CometBFTServer[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logg } } - indexEvents := make(map[string]struct{}, len(s.config.AppTomlConfig.IndexEvents)) - for _, e := range s.config.AppTomlConfig.IndexEvents { + indexEvents := make(map[string]struct{}, len(srv.config.AppTomlConfig.IndexEvents)) + for _, e := range srv.config.AppTomlConfig.IndexEvents { indexEvents[e] = struct{}{} } - s.logger = logger.With(log.ModuleKey, s.Name()) - rs := appI.GetStore() + srv.logger = logger.With(log.ModuleKey, srv.Name()) consensus := NewConsensus( - s.logger, - appI.Name(), - appI.GetAppManager(), - s.serverOptions.Mempool(cfg), + logger, + appName, + appManager, + srv.serverOptions.Mempool(cfg), indexEvents, - appI.GetQueryHandlers(), - rs, - s.config, - s.initTxCodec, + queryHandlers, + store, + srv.config, + srv.initTxCodec, chainID, ) - consensus.prepareProposalHandler = s.serverOptions.PrepareProposalHandler - consensus.processProposalHandler = s.serverOptions.ProcessProposalHandler - consensus.checkTxHandler = s.serverOptions.CheckTxHandler - consensus.verifyVoteExt = s.serverOptions.VerifyVoteExtensionHandler - consensus.extendVote = s.serverOptions.ExtendVoteHandler - consensus.addrPeerFilter = s.serverOptions.AddrPeerFilter - consensus.idPeerFilter = s.serverOptions.IdPeerFilter - - ss := rs.GetStateStorage().(snapshots.StorageSnapshotter) - sc := rs.GetStateCommitment().(snapshots.CommitSnapshotter) - - snapshotStore, err := GetSnapshotStore(s.config.ConfigTomlConfig.RootDir) + consensus.prepareProposalHandler = srv.serverOptions.PrepareProposalHandler + consensus.processProposalHandler = srv.serverOptions.ProcessProposalHandler + consensus.checkTxHandler = srv.serverOptions.CheckTxHandler + consensus.verifyVoteExt = srv.serverOptions.VerifyVoteExtensionHandler + consensus.extendVote = srv.serverOptions.ExtendVoteHandler + consensus.addrPeerFilter = srv.serverOptions.AddrPeerFilter + consensus.idPeerFilter = srv.serverOptions.IdPeerFilter + + ss := store.GetStateStorage().(snapshots.StorageSnapshotter) + sc := store.GetStateCommitment().(snapshots.CommitSnapshotter) + + snapshotStore, err := GetSnapshotStore(srv.config.ConfigTomlConfig.RootDir) if err != nil { - return err + return nil, err } - consensus.snapshotManager = snapshots.NewManager(snapshotStore, s.serverOptions.SnapshotOptions(cfg), sc, ss, nil, s.logger) + consensus.snapshotManager = snapshots.NewManager( + snapshotStore, srv.serverOptions.SnapshotOptions(cfg), sc, ss, nil, logger) - s.Consensus = consensus + srv.Consensus = consensus + return srv, nil +} + +func (s *CometBFTServer[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logger log.Logger) error { return nil } diff --git a/simapp/v2/simdv2/cmd/commands.go b/simapp/v2/simdv2/cmd/commands.go index 6dd95d241eb8..ead508ff9d3f 100644 --- a/simapp/v2/simdv2/cmd/commands.go +++ b/simapp/v2/simdv2/cmd/commands.go @@ -12,10 +12,6 @@ import ( "cosmossdk.io/log" runtimev2 "cosmossdk.io/runtime/v2" serverv2 "cosmossdk.io/server/v2" - "cosmossdk.io/server/v2/api/grpc" - "cosmossdk.io/server/v2/api/telemetry" - "cosmossdk.io/server/v2/cometbft" - serverstore "cosmossdk.io/server/v2/store" "cosmossdk.io/simapp/v2" confixcmd "cosmossdk.io/tools/confix/cmd" @@ -67,21 +63,23 @@ func initRootCmd[T transaction.Tx]( offchain.OffChain(), ) - // wire server commands - return serverv2.AddCommands( - rootCmd, - app, - logger, - globalAppConfig, - cometbft.New( - &genericTxDecoder[T]{txConfig}, - initCometOptions[T](), - initCometConfig(), - ), - grpc.New[T](), - serverstore.New[T](), - telemetry.New[T](), - ) + //// wire server commands + //return serverv2.AddCommands( + // rootCmd, + // app, + // logger, + // globalAppConfig, + // cometbft.New( + // &genericTxDecoder[T]{txConfig}, + // initCometOptions[T](), + // initCometConfig(), + // ), + // grpc.New[T](), + // serverstore.New[T](), + // telemetry.New[T](), + //) + + return nil, nil } // genesisCommand builds genesis-related `simd genesis` command. diff --git a/simapp/v2/simdv2/cmd/root_di.go b/simapp/v2/simdv2/cmd/root_di.go index d95c198b7d7b..9eaa7b6118b0 100644 --- a/simapp/v2/simdv2/cmd/root_di.go +++ b/simapp/v2/simdv2/cmd/root_di.go @@ -1,6 +1,8 @@ package cmd import ( + "cosmossdk.io/server/v2/api/telemetry" + "cosmossdk.io/server/v2/cometbft" "fmt" "os" "path/filepath" @@ -196,6 +198,23 @@ func NewRootCmd[T transaction.Tx](args []string) (*cobra.Command, error) { if err != nil { return nil, err } + // create server components + cometBftServer, err := cometbft.New( + logger, + // TODO use depinject outputs not app + app.Name(), + app.GetStore(), + app.GetAppManager(), + app.GetQueryHandlers(), + &genericTxDecoder{clientCtx.TxConfig}, + globalConfig, + initCometOptions[T](), + initCometConfig(), + ) + telemetryServer, err := telemetry.New[transaction.Tx](globalConfig, logger) + if err != nil { + return nil, err + } } else { if err = depinject.Inject( depinject.Configs( @@ -250,6 +269,7 @@ func NewRootCmd[T transaction.Tx](args []string) (*cobra.Command, error) { if err != nil { return nil, err } + srv, err = initRootCmd[T](rootCmd, logger, globalConfig, clientCtx.TxConfig, moduleManager, app) if err != nil { return nil, err From 9c38263b72981addf95f11f4baf363bd2c11e6eb Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 23 Oct 2024 11:53:14 -0500 Subject: [PATCH 08/46] big progress! --- server/v2/api/grpc/server.go | 50 +++++++++------- server/v2/api/rest/server.go | 37 +++++++----- server/v2/cometbft/server.go | 16 +++--- server/v2/commands.go | 33 +++-------- server/v2/store/server.go | 18 ++++-- server/v2/store/snapshot.go | 3 +- simapp/v2/app_di.go | 13 +++-- simapp/v2/simdv2/cmd/commands.go | 85 +++++++++++++++++++++------- simapp/v2/simdv2/cmd/root_di.go | 97 +++----------------------------- simapp/v2/simdv2/cmd/testnet.go | 34 ++++++----- 10 files changed, 185 insertions(+), 201 deletions(-) diff --git a/server/v2/api/grpc/server.go b/server/v2/api/grpc/server.go index 10e22a514a1e..da6b84dc4c62 100644 --- a/server/v2/api/grpc/server.go +++ b/server/v2/api/grpc/server.go @@ -12,7 +12,6 @@ import ( "strings" "sync" - gogoproto "github.com/cosmos/gogoproto/proto" "github.com/spf13/pflag" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -21,10 +20,13 @@ import ( "google.golang.org/protobuf/reflect/protoreflect" appmodulev2 "cosmossdk.io/core/appmodule/v2" + "cosmossdk.io/core/server" "cosmossdk.io/core/transaction" "cosmossdk.io/log" serverv2 "cosmossdk.io/server/v2" "cosmossdk.io/server/v2/api/grpc/gogoreflection" + + gogoproto "github.com/cosmos/gogoproto/proto" ) const ( @@ -42,38 +44,46 @@ type Server[T transaction.Tx] struct { } // New creates a new grpc server. -func New[T transaction.Tx](cfgOptions ...CfgOption) *Server[T] { - return &Server[T]{ +func New[T transaction.Tx]( + logger log.Logger, + interfaceRegistry server.InterfaceRegistry, + queryHandlers map[string]appmodulev2.Handler, + queryable interface { + Query(ctx context.Context, version uint64, msg transaction.Msg) (transaction.Msg, error) + }, + cfg server.ConfigMap, + cfgOptions ...CfgOption, +) (*Server[T], error) { + srv := &Server[T]{ cfgOptions: cfgOptions, } -} - -// Init returns a correctly configured and initialized gRPC server. -// Note, the caller is responsible for starting the server. -func (s *Server[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logger log.Logger) error { - serverCfg := s.Config().(*Config) + serverCfg := srv.Config().(*Config) if len(cfg) > 0 { - if err := serverv2.UnmarshalSubConfig(cfg, s.Name(), &serverCfg); err != nil { - return fmt.Errorf("failed to unmarshal config: %w", err) + if err := serverv2.UnmarshalSubConfig(cfg, srv.Name(), &serverCfg); err != nil { + return nil, fmt.Errorf("failed to unmarshal config: %w", err) } } - methodsMap := appI.QueryHandlers() grpcSrv := grpc.NewServer( - grpc.ForceServerCodec(newProtoCodec(appI.InterfaceRegistry()).GRPCCodec()), + grpc.ForceServerCodec(newProtoCodec(interfaceRegistry).GRPCCodec()), grpc.MaxSendMsgSize(serverCfg.MaxSendMsgSize), grpc.MaxRecvMsgSize(serverCfg.MaxRecvMsgSize), - grpc.UnknownServiceHandler( - makeUnknownServiceHandler(methodsMap, appI), - ), + grpc.UnknownServiceHandler(makeUnknownServiceHandler(queryHandlers, queryable)), ) // Reflection allows external clients to see what services and methods the gRPC server exposes. - gogoreflection.Register(grpcSrv, slices.Collect(maps.Keys(methodsMap)), logger.With("sub-module", "grpc-reflection")) + gogoreflection.Register(grpcSrv, slices.Collect(maps.Keys(queryHandlers)), logger.With("sub-module", "grpc-reflection")) + + srv.grpcSrv = grpcSrv + srv.config = serverCfg + srv.logger = logger.With(log.ModuleKey, srv.Name()) + + return srv, nil +} - s.grpcSrv = grpcSrv - s.config = serverCfg - s.logger = logger.With(log.ModuleKey, s.Name()) +// Init returns a correctly configured and initialized gRPC server. +// Note, the caller is responsible for starting the server. +func (s *Server[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logger log.Logger) error { return nil } diff --git a/server/v2/api/rest/server.go b/server/v2/api/rest/server.go index 0f2b1777973a..65c2e0fe0408 100644 --- a/server/v2/api/rest/server.go +++ b/server/v2/api/rest/server.go @@ -2,6 +2,8 @@ package rest import ( "context" + "cosmossdk.io/core/server" + "cosmossdk.io/server/v2/appmanager" "errors" "fmt" "net/http" @@ -24,10 +26,29 @@ type Server[T transaction.Tx] struct { cfgOptions []CfgOption } -func New[T transaction.Tx](cfgOptions ...CfgOption) *Server[T] { - return &Server[T]{ +func New[T transaction.Tx]( + appManager appmanager.AppManager[T], + logger log.Logger, + cfg server.ConfigMap, + cfgOptions ...CfgOption, +) (*Server[T], error) { + srv := &Server[T]{ cfgOptions: cfgOptions, + logger: logger.With(log.ModuleKey, ServerName), + router: http.NewServeMux(), } + + srv.router.Handle("/", NewDefaultHandler(appManager)) + + serverCfg := srv.Config().(*Config) + if len(cfg) > 0 { + if err := serverv2.UnmarshalSubConfig(cfg, srv.Name(), &serverCfg); err != nil { + return nil, fmt.Errorf("failed to unmarshal config: %w", err) + } + } + srv.config = serverCfg + + return srv, nil } func (s *Server[T]) Name() string { @@ -35,18 +56,6 @@ func (s *Server[T]) Name() string { } func (s *Server[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logger log.Logger) error { - s.logger = logger.With(log.ModuleKey, s.Name()) - - serverCfg := s.Config().(*Config) - if len(cfg) > 0 { - if err := serverv2.UnmarshalSubConfig(cfg, s.Name(), &serverCfg); err != nil { - return fmt.Errorf("failed to unmarshal config: %w", err) - } - } - - s.router = http.NewServeMux() - s.router.Handle("/", NewDefaultHandler(appI)) - s.config = serverCfg return nil } diff --git a/server/v2/cometbft/server.go b/server/v2/cometbft/server.go index 66754efd7655..dd5dcd11fbe3 100644 --- a/server/v2/cometbft/server.go +++ b/server/v2/cometbft/server.go @@ -4,6 +4,7 @@ import ( "context" appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/server" + "cosmossdk.io/schema/decoding" "cosmossdk.io/server/v2/appmanager" "cosmossdk.io/server/v2/cometbft/types" "crypto/sha256" @@ -56,8 +57,9 @@ func New[T transaction.Tx]( logger log.Logger, appName string, store types.Store, - appManager *appmanager.AppManager[T], + appManager appmanager.AppManager[T], queryHandlers map[string]appmodulev2.Handler, + decoderResolver decoding.DecoderResolver, txCodec transaction.Codec[T], cfg server.ConfigMap, serverOptions ServerOptions[T], @@ -144,22 +146,22 @@ func New[T transaction.Tx]( srv.Consensus = consensus // initialize the indexer - if indexerCfg := s.config.AppTomlConfig.Indexer; len(indexerCfg.Target) > 0 { + if indexerCfg := srv.config.AppTomlConfig.Indexer; len(indexerCfg.Target) > 0 { listener, err := indexer.StartIndexing(indexer.IndexingOptions{ Config: indexerCfg, - Resolver: appI.SchemaDecoderResolver(), - Logger: s.logger.With(log.ModuleKey, "indexer"), + Resolver: decoderResolver, + Logger: logger.With(log.ModuleKey, "indexer"), }) if err != nil { - return fmt.Errorf("failed to start indexing: %w", err) + return nil, fmt.Errorf("failed to start indexing: %w", err) } consensus.listener = &listener.Listener } - s.Consensus = consensus + srv.Consensus = consensus return srv, nil - } +} func (s *CometBFTServer[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logger log.Logger) error { return nil diff --git a/server/v2/commands.go b/server/v2/commands.go index 689027038715..a218170a8326 100644 --- a/server/v2/commands.go +++ b/server/v2/commands.go @@ -3,7 +3,6 @@ package serverv2 import ( "context" "errors" - "github.com/spf13/viper" "os" "os/signal" "path/filepath" @@ -47,7 +46,6 @@ func initServerConfig() ServerConfig { // It configures the config handling and the logger handling func AddCommands[T transaction.Tx]( rootCmd *cobra.Command, - app AppI[T], logger log.Logger, globalServerCfg server.ConfigMap, components ...ServerComponent[T], @@ -55,10 +53,9 @@ func AddCommands[T transaction.Tx]( if len(components) == 0 { return nil, errors.New("no components provided") } - - server := NewServer(logger, initServerConfig(), components...) - cmds := server.CLICommands() - startCmd := createStartCommand(server, app, globalServerCfg, logger) + srv := NewServer(initServerConfig(), components...) + cmds := srv.CLICommands() + startCmd := createStartCommand(srv, globalServerCfg, logger) // TODO necessary? won't the parent context be inherited? startCmd.SetContext(rootCmd.Context()) cmds.Commands = append(cmds.Commands, startCmd) @@ -85,13 +82,12 @@ func AddCommands[T transaction.Tx]( } } - return server, nil + return srv, nil } // createStartCommand creates the start command for the application. func createStartCommand[T transaction.Tx]( server *Server[T], - app AppI[T], config server.ConfigMap, logger log.Logger, ) *cobra.Command { @@ -102,17 +98,6 @@ func createStartCommand[T transaction.Tx]( Short: "Run the application", Annotations: map[string]string{"needs-app": "true"}, RunE: func(cmd *cobra.Command, args []string) error { - // TODO: Init is no longer needed as a distinct life cycle phase due to - // eager config parsing. Therefore, consider one of: - // 1) pull .Init() up closer to ServerComponent constructor call - // 2) remove .Init() as a separate phase, move work (and dependencies) - // into the constructor directly. - // - // Note that (2) could mean the removal of AppI - err := server.Init(app, config, logger) - if err != nil { - return err - } ctx, cancelFn := context.WithCancel(cmd.Context()) go func() { sigCh := make(chan os.Signal, 1) @@ -126,7 +111,7 @@ func createStartCommand[T transaction.Tx]( } }() - return wrapCPUProfile(l, v, func() error { + return wrapCPUProfile(logger, config, func() error { return server.Start(ctx) }) }, @@ -142,14 +127,14 @@ func createStartCommand[T transaction.Tx]( // wrapCPUProfile starts CPU profiling, if enabled, and executes the provided // callbackFn, then waits for it to return. -func wrapCPUProfile(logger log.Logger, v *viper.Viper, callbackFn func() error) error { - cpuProfileFile := v.GetString(FlagCPUProfiling) - if len(cpuProfileFile) == 0 { +func wrapCPUProfile(logger log.Logger, cfg server.ConfigMap, callbackFn func() error) error { + cpuProfileFile, ok := cfg[FlagCPUProfiling] + if !ok { // if cpu profiling is not enabled, just run the callback return callbackFn() } - f, err := os.Create(cpuProfileFile) + f, err := os.Create(cpuProfileFile.(string)) if err != nil { return err } diff --git a/server/v2/store/server.go b/server/v2/store/server.go index 1fafe4e25d53..05cd60d66093 100644 --- a/server/v2/store/server.go +++ b/server/v2/store/server.go @@ -2,6 +2,7 @@ package store import ( "context" + "cosmossdk.io/core/server" "fmt" "github.com/spf13/cobra" @@ -27,14 +28,19 @@ type Server[T transaction.Tx] struct { backend storev2.Backend } -func New[T transaction.Tx]() *Server[T] { - return &Server[T]{} +func New[T transaction.Tx](store storev2.Backend, cfg server.ConfigMap) (*Server[T], error) { + config, err := UnmarshalConfig(cfg) + if err != nil { + return nil, err + } + return &Server[T]{ + backend: store, + config: config, + }, nil } func (s *Server[T]) Init(app serverv2.AppI[T], v map[string]any, _ log.Logger) (err error) { - s.backend = app.Store() - s.config, err = UnmarshalConfig(v) - return err + return nil } func (s *Server[T]) Name() string { @@ -58,7 +64,7 @@ func (s *Server[T]) CLICommands() serverv2.CLIConfig { s.ListSnapshotsCmd(), s.DumpArchiveCmd(), s.LoadArchiveCmd(), - s.RestoreSnapshotCmd(s.backend), + s.RestoreSnapshotCmd(), }, } } diff --git a/server/v2/store/snapshot.go b/server/v2/store/snapshot.go index cbde7cd9a7d9..811e45f292bf 100644 --- a/server/v2/store/snapshot.go +++ b/server/v2/store/snapshot.go @@ -75,7 +75,7 @@ func (s *Server[T]) ExportSnapshotCmd() *cobra.Command { } // RestoreSnapshotCmd returns a command to restore a snapshot -func (s *Server[T]) RestoreSnapshotCmd(rootStore storev2.Backend) *cobra.Command { +func (s *Server[T]) RestoreSnapshotCmd() *cobra.Command { cmd := &cobra.Command{ Use: "restore ", Short: "Restore app state from local snapshot", @@ -95,6 +95,7 @@ func (s *Server[T]) RestoreSnapshotCmd(rootStore storev2.Backend) *cobra.Command logger := log.NewLogger(cmd.OutOrStdout()) + rootStore, _, err := createRootStore(v, logger) sm, err := createSnapshotsManager(cmd, v, logger, rootStore) if err != nil { return err diff --git a/simapp/v2/app_di.go b/simapp/v2/app_di.go index 9960f8a2f19c..ddf1901a793c 100644 --- a/simapp/v2/app_di.go +++ b/simapp/v2/app_di.go @@ -70,6 +70,13 @@ func AppConfig() depinject.Config { ProvideModuleScopedConfigMap, SanelyProvideModuleConfigMap, ProvideRootStoreConfig, + // inject desired account types: + multisigdepinject.ProvideAccount, + basedepinject.ProvideAccount, + lockupdepinject.ProvideAllLockupAccounts, + + // provide base account options + basedepinject.ProvideSecp256K1PubKey, ), depinject.Invoke( std.RegisterInterfaces, @@ -92,12 +99,6 @@ func NewSimAppWithConfig[T transaction.Tx]( appConfig = depinject.Configs( AppConfig(), config, - depinject.Provide( - multisigdepinject.ProvideAccount, - basedepinject.ProvideAccount, - lockupdepinject.ProvideAllLockupAccounts, - basedepinject.ProvideSecp256K1PubKey, - ), ) ) diff --git a/simapp/v2/simdv2/cmd/commands.go b/simapp/v2/simdv2/cmd/commands.go index 64cddab731f9..b993b3d2050d 100644 --- a/simapp/v2/simdv2/cmd/commands.go +++ b/simapp/v2/simdv2/cmd/commands.go @@ -1,6 +1,11 @@ package cmd import ( + "cosmossdk.io/server/v2/api/grpc" + "cosmossdk.io/server/v2/api/rest" + "cosmossdk.io/server/v2/api/telemetry" + "cosmossdk.io/server/v2/cometbft" + serverstore "cosmossdk.io/server/v2/store" "errors" "github.com/spf13/cobra" @@ -42,7 +47,7 @@ func initRootCmd[T transaction.Tx]( globalAppConfig coreserver.ConfigMap, txConfig client.TxConfig, moduleManager *runtimev2.MM[T], - app *simapp.SimApp[T], + simApp *simapp.SimApp[T], ) (configWriter, error) { cfg := sdk.GetConfig() cfg.Seal() @@ -56,32 +61,72 @@ func initRootCmd[T transaction.Tx]( // add keybase, auxiliary RPC, query, genesis, and tx child commands rootCmd.AddCommand( - genesisCommand(moduleManager, app), + genesisCommand(moduleManager, simApp), queryCommand(), txCommand(), keys.Commands(), offchain.OffChain(), ) + // build CLI skeleton for initial config parsing or a client application invocation + if simApp == nil { + return serverv2.AddCommands[T]( + rootCmd, + logger, + globalAppConfig, + &cometbft.CometBFTServer[T]{}, + &grpc.Server[T]{}, + &serverstore.Server[T]{}, + &telemetry.Server[T]{}, + &rest.Server[T]{}, + ) + } + // build full app! + cometBftServer, err := cometbft.New( + logger, + // TODO use depinject outputs not app + simApp.Name(), + simApp.Store(), + simApp.App.AppManager, + simApp.App.QueryHandlers(), + simApp.App.SchemaDecoderResolver(), + &genericTxDecoder[T]{txConfig}, + globalAppConfig, + initCometOptions[T](), + initCometConfig(), + ) + if err != nil { + return nil, err + } + telemetryServer, err := telemetry.New[T](globalAppConfig, logger) + if err != nil { + return nil, err + } + grpcServer, err := grpc.New[T](logger, simApp.InterfaceRegistry(), simApp.QueryHandlers(), simApp, globalAppConfig) + if err != nil { + return nil, err + } + // store "server" (big quotes). + storeServer, err := serverstore.New[T](simApp.Store(), globalAppConfig) + if err != nil { + return nil, err + } + restServer, err := rest.New[T](simApp.App.AppManager, logger, globalAppConfig) + if err != nil { + return nil, err + } + // wire server commands - //if _, err := serverv2.AddCommands( - // rootCmd, - // newApp, - // initServerConfig(), - // cometbft.New( - // &genericTxDecoder[T]{txConfig}, - // initCometOptions[T](), - // initCometConfig(), - // ), - // grpc.New[T](), - // serverstore.New[T](), - // telemetry.New[T](), - // rest.New[T](), - //); err != nil { - // panic(err) - //} - - return nil, nil + return serverv2.AddCommands[T]( + rootCmd, + logger, + globalAppConfig, + cometBftServer, + grpcServer, + storeServer, + telemetryServer, + restServer, + ) } // genesisCommand builds genesis-related `simd genesis` command. diff --git a/simapp/v2/simdv2/cmd/root_di.go b/simapp/v2/simdv2/cmd/root_di.go index 715b1cc4ed9d..6bd61c55dfa2 100644 --- a/simapp/v2/simdv2/cmd/root_di.go +++ b/simapp/v2/simdv2/cmd/root_di.go @@ -1,9 +1,6 @@ package cmd import ( - "cosmossdk.io/server/v2/api/telemetry" - "cosmossdk.io/server/v2/cometbft" - "fmt" "os" "path/filepath" "strings" @@ -14,7 +11,6 @@ import ( serverv2 "cosmossdk.io/server/v2" nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" "github.com/spf13/cobra" - "github.com/spf13/pflag" "github.com/spf13/viper" "cosmossdk.io/client/v2/autocli" @@ -59,70 +55,6 @@ type ModuleConfigMaps map[string]server.ConfigMap type FlagParser func() error type GlobalConfig server.ConfigMap -func ProvideModuleConfigMap( - moduleConfigs []server.ModuleConfigMap, - flags *pflag.FlagSet, - parseFlags FlagParser, -) (ModuleConfigMaps, error) { - var err error - const bootstrapFlags = "__bootstrap" - globalConfig := make(ModuleConfigMaps) - globalConfig[bootstrapFlags] = make(server.ConfigMap) - for _, moduleConfig := range moduleConfigs { - cfg := moduleConfig.Config - name := moduleConfig.Module - globalConfig[name] = make(server.ConfigMap) - for flag, defaultValue := range cfg { - globalConfig[name][flag] = defaultValue - switch v := defaultValue.(type) { - case string: - _, maybeNotFound := flags.GetString(flag) - if maybeNotFound != nil && strings.Contains(maybeNotFound.Error(), - "flag accessed but not defined") { - flags.String(flag, v, "") - } else { - // silently skip the flag if it's already defined - continue - } - case []int: - flags.IntSlice(flag, v, "") - case int: - flags.Int(flag, v, "") - default: - return nil, fmt.Errorf("unsupported type %T for flag %s", defaultValue, flag) - } - if err != nil { - return nil, err - } - } - } - if err = parseFlags(); err != nil { - return nil, err - } - for _, cfg := range globalConfig { - for flag, defaulValue := range cfg { - var val any - switch defaulValue.(type) { - case string: - val, err = flags.GetString(flag) - case []int: - val, err = flags.GetIntSlice(flag) - case int: - val, err = flags.GetInt(flag) - default: - return nil, fmt.Errorf("unsupported type %T for flag %s", defaulValue, flag) - } - if err != nil { - return nil, err - } - cfg[flag] = val - // also collect all flags into bootstrap config - globalConfig[bootstrapFlags][flag] = val - } - } - return globalConfig, nil -} - // NewRootCmd creates a new root command for simd. It is called once in the main function. func NewRootCmd[T transaction.Tx](args []string) (*cobra.Command, error) { var ( @@ -168,7 +100,7 @@ func NewRootCmd[T transaction.Tx](args []string) (*cobra.Command, error) { } configDir := filepath.Join(home, "config") - // we need to check app.toml as the config folder can already exist for the client.toml + // create app.toml if it does not already exist if _, err := os.Stat(filepath.Join(configDir, "app.toml")); os.IsNotExist(err) { if err = srv.WriteConfig(configDir); err != nil { return nil, err @@ -187,9 +119,9 @@ func NewRootCmd[T transaction.Tx](args []string) (*cobra.Command, error) { } globalConfig := vipr.AllSettings() - var app *simapp.SimApp[T] + var simApp *simapp.SimApp[T] if needsApp(cmd) { - app, err = simapp.NewSimAppWithConfig[T]( + simApp, err = simapp.NewSimAppWithConfig[T]( depinject.Configs( depinject.Supply(logger, simapp.GlobalConfig(globalConfig)), depinject.Provide(ProvideClientContext), @@ -198,23 +130,6 @@ func NewRootCmd[T transaction.Tx](args []string) (*cobra.Command, error) { if err != nil { return nil, err } - // create server components - cometBftServer, err := cometbft.New( - logger, - // TODO use depinject outputs not app - app.Name(), - app.Store(), - &app.App.AppManager, - app.App.QueryHandlers(), - &genericTxDecoder{clientCtx.TxConfig}, - globalConfig, - initCometOptions[T](), - initCometConfig(), - ) - telemetryServer, err := telemetry.New[transaction.Tx](globalConfig, logger) - if err != nil { - return nil, err - } } else { if err = depinject.Inject( depinject.Configs( @@ -241,6 +156,10 @@ func NewRootCmd[T transaction.Tx](args []string) (*cobra.Command, error) { Short: "simulation app", SilenceErrors: true, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { + // set the default command outputs + cmd.SetOut(cmd.OutOrStdout()) + cmd.SetErr(cmd.ErrOrStderr()) + clientCtx = clientCtx.WithCmdContext(cmd.Context()) clientCtx, err = client.ReadPersistentCommandFlags(clientCtx, cmd.Flags()) if err != nil { @@ -270,7 +189,7 @@ func NewRootCmd[T transaction.Tx](args []string) (*cobra.Command, error) { return nil, err } - srv, err = initRootCmd[T](rootCmd, logger, globalConfig, clientCtx.TxConfig, moduleManager, app) + srv, err = initRootCmd[T](rootCmd, logger, globalConfig, clientCtx.TxConfig, moduleManager, simApp) if err != nil { return nil, err } diff --git a/simapp/v2/simdv2/cmd/testnet.go b/simapp/v2/simdv2/cmd/testnet.go index 7b71e98b588d..684127848592 100644 --- a/simapp/v2/simdv2/cmd/testnet.go +++ b/simapp/v2/simdv2/cmd/testnet.go @@ -20,8 +20,6 @@ import ( runtimev2 "cosmossdk.io/runtime/v2" serverv2 "cosmossdk.io/server/v2" "cosmossdk.io/server/v2/api/grpc" - "cosmossdk.io/server/v2/cometbft" - "cosmossdk.io/server/v2/store" banktypes "cosmossdk.io/x/bank/types" bankv2types "cosmossdk.io/x/bank/v2/types" stakingtypes "cosmossdk.io/x/staking/types" @@ -336,18 +334,25 @@ func initTestnetFiles[T transaction.Tx]( serverCfg.MinGasPrices = args.minGasPrices // Write server config - cometServer := cometbft.New[T]( - &genericTxDecoder[T]{clientCtx.TxConfig}, - cometbft.ServerOptions[T]{}, - cometbft.OverwriteDefaultConfigTomlConfig(nodeConfig), - ) - storeServer := store.New[T]() - grpcServer := grpc.New[T](grpc.OverwriteDefaultConfig(grpcConfig)) - server := serverv2.NewServer[T](serverCfg, cometServer, grpcServer, storeServer) - err = server.WriteConfig(filepath.Join(nodeDir, "config")) - if err != nil { - return err - } + // TODO FIX ME + fmt.Println(grpcConfig) + //cometServer, err := cometbft.New[T]( + // &genericTxDecoder[T]{clientCtx.TxConfig}, + // cometbft.ServerOptions[T]{}, + // cometbft.OverwriteDefaultConfigTomlConfig(nodeConfig), + //) + //storeServer := store.New[T]() + //grpcServer := grpc.New[T](grpc.OverwriteDefaultConfig(grpcConfig)) + //server := serverv2.NewServer[T]( + // serverCfg, + // &cometbft.CometBFTServer[T]{}, + // &grpc.Server[T]{}, + // &store.Server[T]{}, + //) + //err = server.WriteConfig(filepath.Join(nodeDir, "config")) + //if err != nil { + // return err + //} } if err := initGenFiles(clientCtx, mm, args.chainID, genAccounts, genBalances, genFiles, args.numValidators); err != nil { @@ -363,6 +368,7 @@ func initTestnetFiles[T transaction.Tx]( return err } + // TODO: sus, why not just use --home flag in the first place? // Update viper root since root dir become rootdir/node/simd serverv2.GetViperFromCmd(cmd).Set(flags.FlagHome, nodeConfig.RootDir) From cf96c1f71de4c82fbb3fa39e9b015776a39a2f6a Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 23 Oct 2024 12:57:01 -0500 Subject: [PATCH 09/46] fix testnets command --- server/v2/api/grpc/server.go | 7 ++++++- server/v2/cometbft/server.go | 5 +++++ simapp/v2/simdv2/cmd/testnet.go | 30 ++++++++++-------------------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/server/v2/api/grpc/server.go b/server/v2/api/grpc/server.go index da6b84dc4c62..4655e97ce16f 100644 --- a/server/v2/api/grpc/server.go +++ b/server/v2/api/grpc/server.go @@ -81,6 +81,11 @@ func New[T transaction.Tx]( return srv, nil } +func (s *Server[T]) WithConfigOptions(opts ...CfgOption) *Server[T] { + s.cfgOptions = append(s.cfgOptions, opts...) + return s +} + // Init returns a correctly configured and initialized gRPC server. // Note, the caller is responsible for starting the server. func (s *Server[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logger log.Logger) error { @@ -196,7 +201,7 @@ func (s *Server[T]) Config() any { return s.config } -func (s *Server[T]) Start(ctx context.Context) error { +func (s *Server[T]) Start(context.Context) error { if !s.config.Enable { s.logger.Info(fmt.Sprintf("%s server is disabled via config", s.Name())) return nil diff --git a/server/v2/cometbft/server.go b/server/v2/cometbft/server.go index dd5dcd11fbe3..cda31bb768ca 100644 --- a/server/v2/cometbft/server.go +++ b/server/v2/cometbft/server.go @@ -163,6 +163,11 @@ func New[T transaction.Tx]( return srv, nil } +func (s *CometBFTServer[T]) WithConfigOptions(opts ...CfgOption) *CometBFTServer[T] { + s.cfgOptions = append(s.cfgOptions, opts...) + return s +} + func (s *CometBFTServer[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logger log.Logger) error { return nil } diff --git a/simapp/v2/simdv2/cmd/testnet.go b/simapp/v2/simdv2/cmd/testnet.go index 684127848592..2dcc41797649 100644 --- a/simapp/v2/simdv2/cmd/testnet.go +++ b/simapp/v2/simdv2/cmd/testnet.go @@ -2,6 +2,8 @@ package cmd import ( "bufio" + "cosmossdk.io/server/v2/cometbft" + "cosmossdk.io/server/v2/store" "encoding/json" "fmt" "net" @@ -333,26 +335,14 @@ func initTestnetFiles[T transaction.Tx]( serverCfg := serverv2.DefaultServerConfig() serverCfg.MinGasPrices = args.minGasPrices - // Write server config - // TODO FIX ME - fmt.Println(grpcConfig) - //cometServer, err := cometbft.New[T]( - // &genericTxDecoder[T]{clientCtx.TxConfig}, - // cometbft.ServerOptions[T]{}, - // cometbft.OverwriteDefaultConfigTomlConfig(nodeConfig), - //) - //storeServer := store.New[T]() - //grpcServer := grpc.New[T](grpc.OverwriteDefaultConfig(grpcConfig)) - //server := serverv2.NewServer[T]( - // serverCfg, - // &cometbft.CometBFTServer[T]{}, - // &grpc.Server[T]{}, - // &store.Server[T]{}, - //) - //err = server.WriteConfig(filepath.Join(nodeDir, "config")) - //if err != nil { - // return err - //} + cometServer := (&cometbft.CometBFTServer[T]{}).WithConfigOptions(cometbft.OverwriteDefaultConfigTomlConfig(nodeConfig)) + storeServer := &store.Server[T]{} + grpcServer := (&grpc.Server[T]{}).WithConfigOptions(grpc.OverwriteDefaultConfig(grpcConfig)) + server := serverv2.NewServer[T](serverCfg, cometServer, storeServer, grpcServer) + err = server.WriteConfig(filepath.Join(nodeDir, "config")) + if err != nil { + return err + } } if err := initGenFiles(clientCtx, mm, args.chainID, genAccounts, genBalances, genFiles, args.numValidators); err != nil { From d3012f1165fe568dbea62b621a9cfdd4b91f1bad Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 23 Oct 2024 13:28:53 -0500 Subject: [PATCH 10/46] fix simapp/v2 tests --- server/v2/api/rest/server.go | 10 +- server/v2/api/rest/server_test.go | 5 +- server/v2/server_test.go | 7 +- simapp/v2/app_di.go | 171 +++++++++------------------ simapp/v2/simdv2/cmd/commands.go | 9 +- simapp/v2/simdv2/cmd/root_di.go | 37 +----- simapp/v2/simdv2/cmd/root_test.go | 24 ++-- simapp/v2/simdv2/cmd/testnet.go | 2 - simapp/v2/simdv2/cmd/testnet_test.go | 13 +- simapp/v2/simdv2/main.go | 3 +- x/validate/depinject.go | 3 +- 11 files changed, 102 insertions(+), 182 deletions(-) diff --git a/server/v2/api/rest/server.go b/server/v2/api/rest/server.go index 65c2e0fe0408..ebc4babc1075 100644 --- a/server/v2/api/rest/server.go +++ b/server/v2/api/rest/server.go @@ -2,12 +2,13 @@ package rest import ( "context" - "cosmossdk.io/core/server" - "cosmossdk.io/server/v2/appmanager" "errors" "fmt" "net/http" + "cosmossdk.io/core/server" + "cosmossdk.io/server/v2/appmanager" + "cosmossdk.io/core/transaction" "cosmossdk.io/log" serverv2 "cosmossdk.io/server/v2" @@ -90,6 +91,11 @@ func (s *Server[T]) Stop(ctx context.Context) error { return s.httpServer.Shutdown(ctx) } +func (s *Server[T]) WithConfigOptions(opts ...CfgOption) *Server[T] { + s.cfgOptions = append(s.cfgOptions, opts...) + return s +} + func (s *Server[T]) Config() any { if s.config == nil || s.config.Address == "" { cfg := DefaultConfig() diff --git a/server/v2/api/rest/server_test.go b/server/v2/api/rest/server_test.go index cec027f5d24b..919d5cace5fe 100644 --- a/server/v2/api/rest/server_test.go +++ b/server/v2/api/rest/server_test.go @@ -17,7 +17,7 @@ func TestServerConfig(t *testing.T) { { name: "Default configuration, no custom configuration", setupFunc: func() *Config { - s := New[transaction.Tx]() + s := &Server[transaction.Tx]{} return s.Config().(*Config) }, expectedConfig: DefaultConfig(), @@ -25,7 +25,8 @@ func TestServerConfig(t *testing.T) { { name: "Custom configuration", setupFunc: func() *Config { - s := New[transaction.Tx](func(config *Config) { + s := &Server[transaction.Tx]{} + s = s.WithConfigOptions(func(config *Config) { config.Enable = false }) return s.Config().(*Config) diff --git a/server/v2/server_test.go b/server/v2/server_test.go index a53b71fc35b9..f3c016f9e1b0 100644 --- a/server/v2/server_test.go +++ b/server/v2/server_test.go @@ -63,12 +63,13 @@ func TestServer(t *testing.T) { ctx, err := serverv2.SetServerContext(context.Background(), v, logger) require.NoError(t, err) + app := &mockApp[transaction.Tx]{} - grpcServer := grpc.New[transaction.Tx]() - err = grpcServer.Init(&mockApp[transaction.Tx]{}, cfg, logger) + grpcServer, err := grpc.New[transaction.Tx](logger, app.InterfaceRegistry(), app.QueryHandlers(), app, cfg) require.NoError(t, err) - storeServer := store.New[transaction.Tx]() + storeServer, err := store.New[transaction.Tx](app.Store(), cfg) + require.NoError(t, err) err = storeServer.Init(&mockApp[transaction.Tx]{}, cfg, logger) require.NoError(t, err) diff --git a/simapp/v2/app_di.go b/simapp/v2/app_di.go index ddf1901a793c..1ab3e47105e3 100644 --- a/simapp/v2/app_di.go +++ b/simapp/v2/app_di.go @@ -99,6 +99,61 @@ func NewSimAppWithConfig[T transaction.Tx]( appConfig = depinject.Configs( AppConfig(), config, + depinject.Supply( + // ADVANCED CONFIGURATION + + // + // AUTH + // + // For providing a custom function required in auth to generate custom account types + // add it below. By default the auth module uses simulation.RandomGenesisAccounts. + // + // authtypes.RandomGenesisAccountsFn(simulation.RandomGenesisAccounts), + // + // For providing a custom a base account type add it below. + // By default the auth module uses authtypes.ProtoBaseAccount(). + // + // func() sdk.AccountI { return authtypes.ProtoBaseAccount() }, + // + // For providing a different address codec, add it below. + // By default the auth module uses a Bech32 address codec, + // with the prefix defined in the auth module configuration. + // + // func() address.Codec { return <- custom address codec type -> } + + // + // STAKING + // + // For provinding a different validator and consensus address codec, add it below. + // By default the staking module uses the bech32 prefix provided in the auth config, + // and appends "valoper" and "valcons" for validator and consensus addresses respectively. + // When providing a custom address codec in auth, custom address codecs must be provided here as well. + // + // func() runtime.ValidatorAddressCodec { return <- custom validator address codec type -> } + // func() runtime.ConsensusAddressCodec { return <- custom consensus address codec type -> } + + // + // MINT + // + + // For providing a custom inflation function for x/mint add here your + // custom function that implements the minttypes.InflationCalculationFn + // interface. + ), + depinject.Provide( + // if you want to provide a custom public key you + // can do it from here. + // Example: + // basedepinject.ProvideCustomPubkey[Ed25519PublicKey]() + // + // You can also provide a custom public key with a custom validation function: + // + // basedepinject.ProvideCustomPubKeyAndValidationFunc(func(pub Ed25519PublicKey) error { + // if len(pub.Key) != 64 { + // return fmt.Errorf("invalid pub key size") + // } + // }) + ), ) ) @@ -144,123 +199,12 @@ func NewSimApp[T transaction.Tx]( logger log.Logger, viper *viper.Viper, ) *SimApp[T] { - var ( - app = &SimApp[T]{} - appBuilder *runtime.AppBuilder[T] - err error - storeBuilder root.Builder - - // merge the AppConfig and other configuration in one config - appConfig = depinject.Configs( - AppConfig(), - depinject.Supply( - logger, - - // ADVANCED CONFIGURATION - - // - // AUTH - // - // For providing a custom function required in auth to generate custom account types - // add it below. By default the auth module uses simulation.RandomGenesisAccounts. - // - // authtypes.RandomGenesisAccountsFn(simulation.RandomGenesisAccounts), - // - // For providing a custom a base account type add it below. - // By default the auth module uses authtypes.ProtoBaseAccount(). - // - // func() sdk.AccountI { return authtypes.ProtoBaseAccount() }, - // - // For providing a different address codec, add it below. - // By default the auth module uses a Bech32 address codec, - // with the prefix defined in the auth module configuration. - // - // func() address.Codec { return <- custom address codec type -> } - - // - // STAKING - // - // For provinding a different validator and consensus address codec, add it below. - // By default the staking module uses the bech32 prefix provided in the auth config, - // and appends "valoper" and "valcons" for validator and consensus addresses respectively. - // When providing a custom address codec in auth, custom address codecs must be provided here as well. - // - // func() runtime.ValidatorAddressCodec { return <- custom validator address codec type -> } - // func() runtime.ConsensusAddressCodec { return <- custom consensus address codec type -> } - - // - // MINT - // - - // For providing a custom inflation function for x/mint add here your - // custom function that implements the minttypes.InflationCalculationFn - // interface. - ), - depinject.Provide( - // inject desired account types: - multisigdepinject.ProvideAccount, - basedepinject.ProvideAccount, - lockupdepinject.ProvideAllLockupAccounts, - - // provide base account options - basedepinject.ProvideSecp256K1PubKey, - // if you want to provide a custom public key you - // can do it from here. - // Example: - // basedepinject.ProvideCustomPubkey[Ed25519PublicKey]() - // - // You can also provide a custom public key with a custom validation function: - // - // basedepinject.ProvideCustomPubKeyAndValidationFunc(func(pub Ed25519PublicKey) error { - // if len(pub.Key) != 64 { - // return fmt.Errorf("invalid pub key size") - // } - // }) - ), - ) + app, err := NewSimAppWithConfig[T](depinject.Configs( + depinject.Supply(logger, GlobalConfig(viper.AllSettings()))), ) - - if err := depinject.Inject(appConfig, - &storeBuilder, - &appBuilder, - &app.appCodec, - &app.legacyAmino, - &app.txConfig, - &app.interfaceRegistry, - &app.UpgradeKeeper, - &app.StakingKeeper, - ); err != nil { - panic(err) - } - - // store/v2 follows a slightly more eager config life cycle than server components - storeConfig, err := serverstore.UnmarshalConfig(viper.AllSettings()) - if err != nil { - panic(err) - } - - app.store, err = storeBuilder.Build(logger, storeConfig) if err != nil { panic(err) } - - app.App, err = appBuilder.Build() - if err != nil { - panic(err) - } - - /**** Module Options ****/ - - // RegisterUpgradeHandlers is used for registering any on-chain upgrades. - app.RegisterUpgradeHandlers() - - // TODO (here or in runtime/v2) - // wire simulation manager - // wire unordered tx manager - - if err := app.LoadLatest(); err != nil { - panic(err) - } return app } @@ -301,6 +245,7 @@ func (app *SimApp[T]) Close() error { } type GlobalConfig server.ConfigMap + type ModuleConfigMaps map[string]server.ConfigMap // TODO combine below 2 functions diff --git a/simapp/v2/simdv2/cmd/commands.go b/simapp/v2/simdv2/cmd/commands.go index b993b3d2050d..0301637246be 100644 --- a/simapp/v2/simdv2/cmd/commands.go +++ b/simapp/v2/simdv2/cmd/commands.go @@ -8,9 +8,6 @@ import ( serverstore "cosmossdk.io/server/v2/store" "errors" - "github.com/spf13/cobra" - "github.com/spf13/viper" - "cosmossdk.io/client/v2/offchain" coreserver "cosmossdk.io/core/server" "cosmossdk.io/core/transaction" @@ -19,6 +16,7 @@ import ( serverv2 "cosmossdk.io/server/v2" "cosmossdk.io/simapp/v2" confixcmd "cosmossdk.io/tools/confix/cmd" + "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/debug" @@ -32,11 +30,6 @@ import ( v2 "github.com/cosmos/cosmos-sdk/x/genutil/v2/cli" ) -func newApp[T transaction.Tx](logger log.Logger, viper *viper.Viper) serverv2.AppI[T] { - viper.Set(serverv2.FlagHome, simapp.DefaultNodeHome) - return serverv2.AppI[T](simapp.NewSimApp[T](logger, viper)) -} - type configWriter interface { WriteConfig(filename string) error } diff --git a/simapp/v2/simdv2/cmd/root_di.go b/simapp/v2/simdv2/cmd/root_di.go index 6bd61c55dfa2..a8b8a626950c 100644 --- a/simapp/v2/simdv2/cmd/root_di.go +++ b/simapp/v2/simdv2/cmd/root_di.go @@ -5,25 +5,24 @@ import ( "path/filepath" "strings" - autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" - "cosmossdk.io/core/server" - "cosmossdk.io/log" - serverv2 "cosmossdk.io/server/v2" - nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" "github.com/spf13/cobra" "github.com/spf13/viper" + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" "cosmossdk.io/client/v2/autocli" clientv2helpers "cosmossdk.io/client/v2/helpers" "cosmossdk.io/core/address" "cosmossdk.io/core/registry" "cosmossdk.io/core/transaction" "cosmossdk.io/depinject" + "cosmossdk.io/log" "cosmossdk.io/runtime/v2" + serverv2 "cosmossdk.io/server/v2" "cosmossdk.io/simapp/v2" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/config" + nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/x/auth/tx" @@ -31,32 +30,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/types" ) -/* -logger cannot be injected until command line arguments are parsed but injection is needed before - command line args are parsed due to closing over DI outputs. - -Q: Where is logger needed in injection? -A: ProvideEnvironment and ProvideModuleManager need it. They are receiving a noop logger in the initial injection -and a parsed and configured one in the second. - -!! Return a bootstrap command first with Persistent flags, then parse them. This configures the logger and the home directory. -this can also be folded in and nuked: -https://github.com/cosmos/cosmos-sdk/blob/6708818470826923b96ff7fb6ef55729d8c4269e/client/v2/helpers/home.go#L17 - -DI happens before commands are even created and therefore before full CLI flags binding -In the DI phase only flags mentioned in server.ModuleConfigMap will be available from CLI -In the DI phase viper config is fully available, but not overrides from CLI flags -Server components are invoked on start. -Server components receive fully parse CLI flags since the Start invocation happens in command.RunE - -*/ - -type ModuleConfigMaps map[string]server.ConfigMap -type FlagParser func() error -type GlobalConfig server.ConfigMap - // NewRootCmd creates a new root command for simd. It is called once in the main function. -func NewRootCmd[T transaction.Tx](args []string) (*cobra.Command, error) { +func NewRootCmd[T transaction.Tx](args ...string) (*cobra.Command, error) { var ( autoCliOpts autocli.AppOptions moduleManager *runtime.MM[T] @@ -189,7 +164,7 @@ func NewRootCmd[T transaction.Tx](args []string) (*cobra.Command, error) { return nil, err } - srv, err = initRootCmd[T](rootCmd, logger, globalConfig, clientCtx.TxConfig, moduleManager, simApp) + _, err = initRootCmd[T](rootCmd, logger, globalConfig, clientCtx.TxConfig, moduleManager, simApp) if err != nil { return nil, err } diff --git a/simapp/v2/simdv2/cmd/root_test.go b/simapp/v2/simdv2/cmd/root_test.go index 7c51b1b21170..7f7d6a07d95a 100644 --- a/simapp/v2/simdv2/cmd/root_test.go +++ b/simapp/v2/simdv2/cmd/root_test.go @@ -7,8 +7,6 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/core/transaction" - svrcmd "cosmossdk.io/server/v2" - "cosmossdk.io/simapp/v2" "cosmossdk.io/simapp/v2/simdv2/cmd" "github.com/cosmos/cosmos-sdk/client/flags" @@ -16,27 +14,29 @@ import ( ) func TestInitCmd(t *testing.T) { - rootCmd := cmd.NewRootCmd[transaction.Tx]() - rootCmd.SetArgs([]string{ + args := []string{ "init", // Test the init cmd "simapp-test", // Moniker fmt.Sprintf("--%s=%s", cli.FlagOverwrite, "true"), // Overwrite genesis.json, in case it already exists - }) - - require.NoError(t, svrcmd.Execute(rootCmd, "", simapp.DefaultNodeHome)) + } + rootCmd, err := cmd.NewRootCmd[transaction.Tx](args...) + require.NoError(t, err) + rootCmd.SetArgs(args) + require.NoError(t, rootCmd.Execute()) } func TestHomeFlagRegistration(t *testing.T) { homeDir := "/tmp/foo" - - rootCmd := cmd.NewRootCmd[transaction.Tx]() - rootCmd.SetArgs([]string{ + args := []string{ "query", fmt.Sprintf("--%s", flags.FlagHome), homeDir, - }) + } - require.NoError(t, svrcmd.Execute(rootCmd, "", simapp.DefaultNodeHome)) + rootCmd, err := cmd.NewRootCmd[transaction.Tx](args...) + require.NoError(t, err) + rootCmd.SetArgs(args) + require.NoError(t, rootCmd.Execute()) result, err := rootCmd.Flags().GetString(flags.FlagHome) require.NoError(t, err) diff --git a/simapp/v2/simdv2/cmd/testnet.go b/simapp/v2/simdv2/cmd/testnet.go index 2dcc41797649..44254fc01edc 100644 --- a/simapp/v2/simdv2/cmd/testnet.go +++ b/simapp/v2/simdv2/cmd/testnet.go @@ -358,8 +358,6 @@ func initTestnetFiles[T transaction.Tx]( return err } - // TODO: sus, why not just use --home flag in the first place? - // Update viper root since root dir become rootdir/node/simd serverv2.GetViperFromCmd(cmd).Set(flags.FlagHome, nodeConfig.RootDir) cmd.PrintErrf("Successfully initialized %d node directories\n", args.numValidators) diff --git a/simapp/v2/simdv2/cmd/testnet_test.go b/simapp/v2/simdv2/cmd/testnet_test.go index 145a32608e60..acf57dd37b80 100644 --- a/simapp/v2/simdv2/cmd/testnet_test.go +++ b/simapp/v2/simdv2/cmd/testnet_test.go @@ -7,8 +7,6 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/core/transaction" - svrcmd "cosmossdk.io/server/v2" - "cosmossdk.io/simapp/v2" "cosmossdk.io/simapp/v2/simdv2/cmd" "github.com/cosmos/cosmos-sdk/client/flags" @@ -16,12 +14,13 @@ import ( ) func TestInitTestFilesCmd(t *testing.T) { - rootCmd := cmd.NewRootCmd[transaction.Tx]() - rootCmd.SetArgs([]string{ + args := []string{ "testnet", // Test the testnet init-files command "init-files", fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest), // Set keyring-backend to test - }) - - require.NoError(t, svrcmd.Execute(rootCmd, "", simapp.DefaultNodeHome)) + } + rootCmd, err := cmd.NewRootCmd[transaction.Tx](args...) + require.NoError(t, err) + rootCmd.SetArgs(args) + require.NoError(t, rootCmd.Execute()) } diff --git a/simapp/v2/simdv2/main.go b/simapp/v2/simdv2/main.go index 1ac9111d5b7d..02dc59063d09 100644 --- a/simapp/v2/simdv2/main.go +++ b/simapp/v2/simdv2/main.go @@ -10,9 +10,10 @@ import ( ) func main() { + // reproduce default cobra behavior so that eager parsing of flags is possible. // see: https://github.com/spf13/cobra/blob/e94f6d0dd9a5e5738dca6bce03c4b1207ffbc0ec/command.go#L1082 args := os.Args[1:] - rootCmd, err := cmd.NewRootCmd[transaction.Tx](args) + rootCmd, err := cmd.NewRootCmd[transaction.Tx](args...) if err != nil { if _, pErr := fmt.Fprintln(os.Stderr, err); pErr != nil { panic(errors.Join(err, pErr)) diff --git a/x/validate/depinject.go b/x/validate/depinject.go index bfe6f7384044..6841055039ed 100644 --- a/x/validate/depinject.go +++ b/x/validate/depinject.go @@ -3,6 +3,8 @@ package validate import ( "fmt" + "github.com/spf13/cast" + modulev1 "cosmossdk.io/api/cosmos/validate/module/v1" appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/server" @@ -18,7 +20,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/ante/unorderedtx" "github.com/cosmos/cosmos-sdk/x/auth/posthandler" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/spf13/cast" ) // flagMinGasPricesV2 is the flag name for the minimum gas prices in the main server v2 component. From 9ca9e6bf01888259852a98ab671671d9f604549a Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 23 Oct 2024 15:16:15 -0500 Subject: [PATCH 11/46] adapt for runtime/v1 --- core/server/config.go | 5 +++ runtime/config.go | 46 ++++++++++++++++++++++++ runtime/module.go | 2 ++ runtime/v2/config.go | 62 +++++++++++++++++++++++++++++++++ runtime/v2/module.go | 2 ++ simapp/app_di.go | 6 ++-- simapp/go.mod | 1 + simapp/go.sum | 2 -- simapp/v2/app_di.go | 51 ++++----------------------- simapp/v2/app_test.go | 2 +- simapp/v2/simdv2/cmd/root_di.go | 6 ++-- x/validate/depinject.go | 2 ++ 12 files changed, 135 insertions(+), 52 deletions(-) create mode 100644 runtime/config.go create mode 100644 runtime/v2/config.go diff --git a/core/server/config.go b/core/server/config.go index 6ba618dae8e9..d65cfcb3fd58 100644 --- a/core/server/config.go +++ b/core/server/config.go @@ -7,12 +7,17 @@ type DynamicConfig interface { GetString(string) string } +// ConfigMap is a recursive map of configuration values. type ConfigMap map[string]any +// TODO delete? func (c ConfigMap) Get(s string) any { return c[s] } +// ModuleConfigMap is used to specify module configuration. +// Keys (and there default values and types) should be set in Config +// and returned by module specific provider function. type ModuleConfigMap struct { Module string Config ConfigMap diff --git a/runtime/config.go b/runtime/config.go new file mode 100644 index 000000000000..6474ebafbe02 --- /dev/null +++ b/runtime/config.go @@ -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()] +} diff --git a/runtime/module.go b/runtime/module.go index 773efe10a3e2..3cf7be226421 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -103,6 +103,8 @@ func init() { ProvideTransientStoreService, ProvideModuleManager, ProvideCometService, + ProvideModuleConfigMaps, + ProvideModuleScopedConfigMap, ), appconfig.Invoke(SetupAppBuilder), ) diff --git a/runtime/v2/config.go b/runtime/v2/config.go new file mode 100644 index 000000000000..44ffe4eaea18 --- /dev/null +++ b/runtime/v2/config.go @@ -0,0 +1,62 @@ +package runtime + +import ( + "cosmossdk.io/core/server" + "cosmossdk.io/depinject" + "strings" +) + +// GlobalConfig is a recursive configuration map containing configuration +// key-value pairs parsed from the configuration file, flags, or other +// input sources. +type GlobalConfig server.ConfigMap + +// ModuleConfigMaps is a map module scoped ConfigMaps +type ModuleConfigMaps map[string]server.ConfigMap + +// TODO combine below 2 functions +// - linear search for module name in provider is OK +// - move elsewhere, server/v2 or runtime/v2 ? + +// 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 + 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()] +} diff --git a/runtime/v2/module.go b/runtime/v2/module.go index e163a5f65b03..a2cca4a96337 100644 --- a/runtime/v2/module.go +++ b/runtime/v2/module.go @@ -99,6 +99,8 @@ func init() { ProvideModuleManager[transaction.Tx], ProvideEnvironment, ProvideKVService, + ProvideModuleConfigMaps, + ProvideModuleScopedConfigMap, ), appconfig.Invoke(SetupAppBuilder), ) diff --git a/simapp/app_di.go b/simapp/app_di.go index b26220892e0d..0704cbdc38ca 100644 --- a/simapp/app_di.go +++ b/simapp/app_di.go @@ -93,8 +93,10 @@ func init() { // AppConfig returns the default app config. func AppConfig() depinject.Config { return depinject.Configs( - appConfig, // Alternatively use appconfig.LoadYAML(AppConfigYAML) - depinject.Provide(ProvideExampleMintFn), // optional: override the mint module's mint function with epoched minting + appConfig, // Alternatively use appconfig.LoadYAML(AppConfigYAML) + depinject.Provide( + ProvideExampleMintFn, // optional: override the mint module's mint function with epoched minting + ), ) } diff --git a/simapp/go.mod b/simapp/go.mod index b18938c3719d..45344a2a4d7d 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -240,6 +240,7 @@ replace ( cosmossdk.io/api => ../api cosmossdk.io/client/v2 => ../client/v2 cosmossdk.io/collections => ../collections + cosmossdk.io/core => ../core cosmossdk.io/store => ../store cosmossdk.io/tools/confix => ../tools/confix cosmossdk.io/x/accounts => ../x/accounts diff --git a/simapp/go.sum b/simapp/go.sum index 5580a43e71f2..9d1d695d59a4 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -192,8 +192,6 @@ cloud.google.com/go/webrisk v1.4.0/go.mod h1:Hn8X6Zr+ziE2aNd8SliSDWpEnSS1u4R9+xX cloud.google.com/go/webrisk v1.5.0/go.mod h1:iPG6fr52Tv7sGk0H6qUFzmL3HHZev1htXuWDEEsqMTg= cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0= cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/simapp/v2/app_di.go b/simapp/v2/app_di.go index 1ab3e47105e3..fad99f6de2c2 100644 --- a/simapp/v2/app_di.go +++ b/simapp/v2/app_di.go @@ -1,6 +1,7 @@ package simapp import ( + serverstore "cosmossdk.io/server/v2/store" _ "embed" "fmt" @@ -13,7 +14,6 @@ import ( "cosmossdk.io/depinject" "cosmossdk.io/log" "cosmossdk.io/runtime/v2" - serverstore "cosmossdk.io/server/v2/store" "cosmossdk.io/store/v2" "cosmossdk.io/store/v2/root" basedepinject "cosmossdk.io/x/accounts/defaults/base/depinject" @@ -67,8 +67,6 @@ func AppConfig() depinject.Config { codec.ProvideAddressCodec, codec.ProvideProtoCodec, codec.ProvideLegacyAmino, - ProvideModuleScopedConfigMap, - SanelyProvideModuleConfigMap, ProvideRootStoreConfig, // inject desired account types: multisigdepinject.ProvideAccount, @@ -85,7 +83,7 @@ func AppConfig() depinject.Config { ) } -func NewSimAppWithConfig[T transaction.Tx]( +func NewSimApp[T transaction.Tx]( config depinject.Config, outputs ...any, ) (*SimApp[T], error) { @@ -194,13 +192,13 @@ func NewSimAppWithConfig[T transaction.Tx]( return app, nil } -// NewSimApp returns a reference to an initialized SimApp. -func NewSimApp[T transaction.Tx]( +// NewSimAppWithInputs returns a reference to an initialized SimApp. +func NewSimAppWithInputs[T transaction.Tx]( logger log.Logger, viper *viper.Viper, ) *SimApp[T] { - app, err := NewSimAppWithConfig[T](depinject.Configs( - depinject.Supply(logger, GlobalConfig(viper.AllSettings()))), + app, err := NewSimApp[T](depinject.Configs( + depinject.Supply(logger, runtime.GlobalConfig(viper.AllSettings()))), ) if err != nil { panic(err) @@ -244,41 +242,6 @@ func (app *SimApp[T]) Close() error { return app.App.Close() } -type GlobalConfig server.ConfigMap - -type ModuleConfigMaps map[string]server.ConfigMap - -// TODO combine below 2 functions -// - linear search for module name in provider is OK -// - move elsewhere, server/v2 or runtime/v2 ? - -func SanelyProvideModuleConfigMap( - 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 { - if val, ok := globalConfig[flag]; 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()] -} - -func ProvideRootStoreConfig(config GlobalConfig) (*root.Config, error) { +func ProvideRootStoreConfig(config runtime.GlobalConfig) (*root.Config, error) { return serverstore.UnmarshalConfig(config) } diff --git a/simapp/v2/app_test.go b/simapp/v2/app_test.go index 61ace5e4ef29..80805abc7f36 100644 --- a/simapp/v2/app_test.go +++ b/simapp/v2/app_test.go @@ -39,7 +39,7 @@ func NewTestApp(t *testing.T) (*SimApp[transaction.Tx], context.Context) { vp.Set(serverv2store.FlagAppDBBackend, string(db.DBTypeGoLevelDB)) vp.Set(serverv2.FlagHome, t.TempDir()) - app := NewSimApp[transaction.Tx](logger, vp) + app := NewSimAppWithInputs[transaction.Tx](logger, vp) genesis := app.ModuleManager().DefaultGenesis() privVal := mock.NewPV() diff --git a/simapp/v2/simdv2/cmd/root_di.go b/simapp/v2/simdv2/cmd/root_di.go index a8b8a626950c..a6d1442f28fd 100644 --- a/simapp/v2/simdv2/cmd/root_di.go +++ b/simapp/v2/simdv2/cmd/root_di.go @@ -96,9 +96,9 @@ func NewRootCmd[T transaction.Tx](args ...string) (*cobra.Command, error) { var simApp *simapp.SimApp[T] if needsApp(cmd) { - simApp, err = simapp.NewSimAppWithConfig[T]( + simApp, err = simapp.NewSimApp[T]( depinject.Configs( - depinject.Supply(logger, simapp.GlobalConfig(globalConfig)), + depinject.Supply(logger, runtime.GlobalConfig(globalConfig)), depinject.Provide(ProvideClientContext), ), &autoCliOpts, &moduleManager, &clientCtx) @@ -114,7 +114,7 @@ func NewRootCmd[T transaction.Tx](args ...string) (*cobra.Command, error) { ), depinject.Supply( logger, - simapp.GlobalConfig(globalConfig), + runtime.GlobalConfig(globalConfig), ), ), &autoCliOpts, diff --git a/x/validate/depinject.go b/x/validate/depinject.go index 6841055039ed..0c383f457abe 100644 --- a/x/validate/depinject.go +++ b/x/validate/depinject.go @@ -31,6 +31,8 @@ func init() { ) } +// ProvideConfig specifies the configuration key for the minimum gas prices. +// During dependency injection, a configuration map is provided with the key set. func ProvideConfig(key depinject.OwnModuleKey) server.ModuleConfigMap { return server.ModuleConfigMap{ Module: depinject.ModuleKey(key).Name(), From 43c10ad4feb6b27166c36b677ec84b31e1db6572 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 23 Oct 2024 15:18:34 -0500 Subject: [PATCH 12/46] rm dead method --- simapp/v2/app_di.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/simapp/v2/app_di.go b/simapp/v2/app_di.go index fad99f6de2c2..c02743f2980a 100644 --- a/simapp/v2/app_di.go +++ b/simapp/v2/app_di.go @@ -206,10 +206,6 @@ func NewSimAppWithInputs[T transaction.Tx]( return app } -func (app *SimApp[T]) Build() error { - return nil -} - // AppCodec returns SimApp's app codec. // // NOTE: This is solely to be used for testing purposes as it may be desirable From 3e0ded0a09a72f8917281b707d14c8d46a4a874c Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 23 Oct 2024 15:24:41 -0500 Subject: [PATCH 13/46] rm Init() method --- server/v2/api/grpc/server.go | 7 ------- server/v2/api/grpcgateway/server.go | 16 ---------------- server/v2/api/rest/server.go | 5 ----- server/v2/api/telemetry/server.go | 5 ----- server/v2/cometbft/server.go | 14 +++++--------- server/v2/server.go | 25 ------------------------- server/v2/server_mock_test.go | 8 -------- server/v2/server_test.go | 4 +--- server/v2/store/server.go | 5 ----- 9 files changed, 6 insertions(+), 83 deletions(-) diff --git a/server/v2/api/grpc/server.go b/server/v2/api/grpc/server.go index 4655e97ce16f..c285b218ab08 100644 --- a/server/v2/api/grpc/server.go +++ b/server/v2/api/grpc/server.go @@ -86,13 +86,6 @@ func (s *Server[T]) WithConfigOptions(opts ...CfgOption) *Server[T] { return s } -// Init returns a correctly configured and initialized gRPC server. -// Note, the caller is responsible for starting the server. -func (s *Server[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logger log.Logger) error { - - return nil -} - func (s *Server[T]) StartCmdFlags() *pflag.FlagSet { flags := pflag.NewFlagSet(s.Name(), pflag.ExitOnError) flags.String(FlagAddress, "localhost:9090", "Listen address") diff --git a/server/v2/api/grpcgateway/server.go b/server/v2/api/grpcgateway/server.go index 412c4e4ad81d..3ee58338e3cb 100644 --- a/server/v2/api/grpcgateway/server.go +++ b/server/v2/api/grpcgateway/server.go @@ -80,22 +80,6 @@ func (s *Server[T]) Config() any { return s.config } -func (s *Server[T]) Init(appI serverv2.AppI[transaction.Tx], cfg map[string]any, logger log.Logger) error { - serverCfg := s.Config().(*Config) - if len(cfg) > 0 { - if err := serverv2.UnmarshalSubConfig(cfg, s.Name(), &serverCfg); err != nil { - return fmt.Errorf("failed to unmarshal config: %w", err) - } - } - - // TODO: register the gRPC-Gateway routes - - s.logger = logger.With(log.ModuleKey, s.Name()) - s.config = serverCfg - - return nil -} - func (s *Server[T]) Start(ctx context.Context) error { if !s.config.Enable { s.logger.Info(fmt.Sprintf("%s server is disabled via config", s.Name())) diff --git a/server/v2/api/rest/server.go b/server/v2/api/rest/server.go index ebc4babc1075..a89992b19878 100644 --- a/server/v2/api/rest/server.go +++ b/server/v2/api/rest/server.go @@ -56,11 +56,6 @@ func (s *Server[T]) Name() string { return ServerName } -func (s *Server[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logger log.Logger) error { - - return nil -} - func (s *Server[T]) Start(ctx context.Context) error { if !s.config.Enable { s.logger.Info(fmt.Sprintf("%s server is disabled via config", s.Name())) diff --git a/server/v2/api/telemetry/server.go b/server/v2/api/telemetry/server.go index eb2d58efa6b7..7dec75c87673 100644 --- a/server/v2/api/telemetry/server.go +++ b/server/v2/api/telemetry/server.go @@ -60,11 +60,6 @@ func (s *Server[T]) Config() any { return s.config } -// Init implements serverv2.ServerComponent. -func (s *Server[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logger log.Logger) error { - return nil -} - func (s *Server[T]) Start(ctx context.Context) error { if !s.config.Enable { s.logger.Info(fmt.Sprintf("%s server is disabled via config", s.Name())) diff --git a/server/v2/cometbft/server.go b/server/v2/cometbft/server.go index cda31bb768ca..4e5cb4bd855b 100644 --- a/server/v2/cometbft/server.go +++ b/server/v2/cometbft/server.go @@ -2,11 +2,6 @@ package cometbft import ( "context" - appmodulev2 "cosmossdk.io/core/appmodule/v2" - "cosmossdk.io/core/server" - "cosmossdk.io/schema/decoding" - "cosmossdk.io/server/v2/appmanager" - "cosmossdk.io/server/v2/cometbft/types" "crypto/sha256" "encoding/json" "fmt" @@ -23,12 +18,17 @@ import ( "github.com/spf13/cobra" "github.com/spf13/pflag" + appmodulev2 "cosmossdk.io/core/appmodule/v2" + "cosmossdk.io/core/server" "cosmossdk.io/core/transaction" "cosmossdk.io/log" + "cosmossdk.io/schema/decoding" "cosmossdk.io/schema/indexer" serverv2 "cosmossdk.io/server/v2" + "cosmossdk.io/server/v2/appmanager" cometlog "cosmossdk.io/server/v2/cometbft/log" "cosmossdk.io/server/v2/cometbft/mempool" + "cosmossdk.io/server/v2/cometbft/types" "cosmossdk.io/store/v2/snapshots" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" @@ -168,10 +168,6 @@ func (s *CometBFTServer[T]) WithConfigOptions(opts ...CfgOption) *CometBFTServer return s } -func (s *CometBFTServer[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logger log.Logger) error { - return nil -} - func (s *CometBFTServer[T]) Name() string { return ServerName } diff --git a/server/v2/server.go b/server/v2/server.go index 980cb3e5fed2..072d00f31d03 100644 --- a/server/v2/server.go +++ b/server/v2/server.go @@ -22,7 +22,6 @@ type ServerComponent[T transaction.Tx] interface { Start(context.Context) error Stop(context.Context) error - Init(AppI[T], map[string]any, log.Logger) error } // HasStartFlags is a server module that has start flags. @@ -186,30 +185,6 @@ func (s *Server[T]) StartCmdFlags() *pflag.FlagSet { return flags } -// Init initializes all server components with the provided application, configuration, and logger. -// It returns an error if any component fails to initialize. -func (s *Server[T]) Init(appI AppI[T], cfg map[string]any, logger log.Logger) error { - serverCfg := s.config - if len(cfg) > 0 { - if err := UnmarshalSubConfig(cfg, s.Name(), &serverCfg); err != nil { - return fmt.Errorf("failed to unmarshal config: %w", err) - } - } - - var components []ServerComponent[T] - for _, mod := range s.components { - if err := mod.Init(appI, cfg, logger); err != nil { - return err - } - - components = append(components, mod) - } - - s.config = serverCfg - s.components = components - return nil -} - // WriteConfig writes the config to the given path. // Note: it does not use viper.WriteConfigAs because we do not want to store flag values in the config. func (s *Server[T]) WriteConfig(configPath string) error { diff --git a/server/v2/server_mock_test.go b/server/v2/server_mock_test.go index 8b590ba2d32f..2158549eed0c 100644 --- a/server/v2/server_mock_test.go +++ b/server/v2/server_mock_test.go @@ -4,10 +4,6 @@ import ( "context" "fmt" "math/rand" - - "cosmossdk.io/core/transaction" - "cosmossdk.io/log" - serverv2 "cosmossdk.io/server/v2" ) type mockServerConfig struct { @@ -31,10 +27,6 @@ func (s *mockServer) Name() string { return s.name } -func (s *mockServer) Init(appI serverv2.AppI[transaction.Tx], cfg map[string]any, logger log.Logger) error { - return nil -} - func (s *mockServer) Start(ctx context.Context) error { for ctx.Err() == nil { s.ch <- fmt.Sprintf("%s mock server: %d", s.name, rand.Int()) diff --git a/server/v2/server_test.go b/server/v2/server_test.go index f3c016f9e1b0..fbef37ae132c 100644 --- a/server/v2/server_test.go +++ b/server/v2/server_test.go @@ -70,12 +70,10 @@ func TestServer(t *testing.T) { storeServer, err := store.New[transaction.Tx](app.Store(), cfg) require.NoError(t, err) - err = storeServer.Init(&mockApp[transaction.Tx]{}, cfg, logger) - require.NoError(t, err) mockServer := &mockServer{name: "mock-server-1", ch: make(chan string, 100)} - server := serverv2.NewServer( + server := serverv2.NewServer[transaction.Tx]( serverv2.DefaultServerConfig(), grpcServer, storeServer, diff --git a/server/v2/store/server.go b/server/v2/store/server.go index 05cd60d66093..f5633d314366 100644 --- a/server/v2/store/server.go +++ b/server/v2/store/server.go @@ -8,7 +8,6 @@ import ( "github.com/spf13/cobra" "cosmossdk.io/core/transaction" - "cosmossdk.io/log" serverv2 "cosmossdk.io/server/v2" storev2 "cosmossdk.io/store/v2" "cosmossdk.io/store/v2/root" @@ -39,10 +38,6 @@ func New[T transaction.Tx](store storev2.Backend, cfg server.ConfigMap) (*Server }, nil } -func (s *Server[T]) Init(app serverv2.AppI[T], v map[string]any, _ log.Logger) (err error) { - return nil -} - func (s *Server[T]) Name() string { return ServerName } From 72b278ad093c116e6e194b7ac3e660238decb248 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 23 Oct 2024 15:47:35 -0500 Subject: [PATCH 14/46] clean up --- simapp/v2/simdv2/cmd/commands.go | 39 +++++++++++++++++++------------- simapp/v2/simdv2/cmd/root_di.go | 10 ++++++-- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/simapp/v2/simdv2/cmd/commands.go b/simapp/v2/simdv2/cmd/commands.go index 0301637246be..e187d025836c 100644 --- a/simapp/v2/simdv2/cmd/commands.go +++ b/simapp/v2/simdv2/cmd/commands.go @@ -34,27 +34,33 @@ type configWriter interface { WriteConfig(filename string) error } +// commandDependencies is a struct that contains all the dependencies needed to initialize the root command. +// an alternative design could fetch these even later from the command context. +type commandDependencies[T transaction.Tx] struct { + globalAppConfig coreserver.ConfigMap + txConfig client.TxConfig + moduleManager *runtimev2.MM[T] + simApp *simapp.SimApp[T] +} + func initRootCmd[T transaction.Tx]( rootCmd *cobra.Command, logger log.Logger, - globalAppConfig coreserver.ConfigMap, - txConfig client.TxConfig, - moduleManager *runtimev2.MM[T], - simApp *simapp.SimApp[T], + deps commandDependencies[T], ) (configWriter, error) { cfg := sdk.GetConfig() cfg.Seal() rootCmd.AddCommand( - genutilcli.InitCmd(moduleManager), + genutilcli.InitCmd(deps.moduleManager), debug.Cmd(), confixcmd.ConfigCommand(), - NewTestnetCmd(moduleManager), + NewTestnetCmd(deps.moduleManager), ) // add keybase, auxiliary RPC, query, genesis, and tx child commands rootCmd.AddCommand( - genesisCommand(moduleManager, simApp), + genesisCommand(deps.moduleManager, deps.simApp), queryCommand(), txCommand(), keys.Commands(), @@ -62,11 +68,11 @@ func initRootCmd[T transaction.Tx]( ) // build CLI skeleton for initial config parsing or a client application invocation - if simApp == nil { + if deps.simApp == nil { return serverv2.AddCommands[T]( rootCmd, logger, - globalAppConfig, + deps.globalAppConfig, &cometbft.CometBFTServer[T]{}, &grpc.Server[T]{}, &serverstore.Server[T]{}, @@ -74,6 +80,7 @@ func initRootCmd[T transaction.Tx]( &rest.Server[T]{}, ) } + simApp := deps.simApp // build full app! cometBftServer, err := cometbft.New( logger, @@ -83,28 +90,28 @@ func initRootCmd[T transaction.Tx]( simApp.App.AppManager, simApp.App.QueryHandlers(), simApp.App.SchemaDecoderResolver(), - &genericTxDecoder[T]{txConfig}, - globalAppConfig, + &genericTxDecoder[T]{deps.txConfig}, + deps.globalAppConfig, initCometOptions[T](), initCometConfig(), ) if err != nil { return nil, err } - telemetryServer, err := telemetry.New[T](globalAppConfig, logger) + telemetryServer, err := telemetry.New[T](deps.globalAppConfig, logger) if err != nil { return nil, err } - grpcServer, err := grpc.New[T](logger, simApp.InterfaceRegistry(), simApp.QueryHandlers(), simApp, globalAppConfig) + grpcServer, err := grpc.New[T](logger, simApp.InterfaceRegistry(), simApp.QueryHandlers(), simApp, deps.globalAppConfig) if err != nil { return nil, err } // store "server" (big quotes). - storeServer, err := serverstore.New[T](simApp.Store(), globalAppConfig) + storeServer, err := serverstore.New[T](simApp.Store(), deps.globalAppConfig) if err != nil { return nil, err } - restServer, err := rest.New[T](simApp.App.AppManager, logger, globalAppConfig) + restServer, err := rest.New[T](simApp.App.AppManager, logger, deps.globalAppConfig) if err != nil { return nil, err } @@ -113,7 +120,7 @@ func initRootCmd[T transaction.Tx]( return serverv2.AddCommands[T]( rootCmd, logger, - globalAppConfig, + deps.globalAppConfig, cometBftServer, grpcServer, storeServer, diff --git a/simapp/v2/simdv2/cmd/root_di.go b/simapp/v2/simdv2/cmd/root_di.go index a6d1442f28fd..534441269e0b 100644 --- a/simapp/v2/simdv2/cmd/root_di.go +++ b/simapp/v2/simdv2/cmd/root_di.go @@ -55,7 +55,7 @@ func NewRootCmd[T transaction.Tx](args ...string) (*cobra.Command, error) { viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_")) viper.AutomaticEnv() - srv, err := initRootCmd[T](rootCmd, log.NewNopLogger(), nil, nil, nil, nil) + srv, err := initRootCmd[T](rootCmd, log.NewNopLogger(), commandDependencies[T]{}) if err != nil { return nil, err } @@ -164,7 +164,13 @@ func NewRootCmd[T transaction.Tx](args ...string) (*cobra.Command, error) { return nil, err } - _, err = initRootCmd[T](rootCmd, logger, globalConfig, clientCtx.TxConfig, moduleManager, simApp) + commandDeps := commandDependencies[T]{ + globalAppConfig: globalConfig, + txConfig: clientCtx.TxConfig, + moduleManager: moduleManager, + simApp: simApp, + } + _, err = initRootCmd[T](rootCmd, logger, commandDeps) if err != nil { return nil, err } From a3c111f2bbdae379a541fafecbcd2e7f4a9a2b04 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 23 Oct 2024 17:19:44 -0500 Subject: [PATCH 15/46] go mod tidy all --- runtime/v2/go.mod | 2 +- runtime/v2/go.sum | 2 -- server/v2/cometbft/go.mod | 2 +- server/v2/cometbft/go.sum | 2 -- 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/runtime/v2/go.mod b/runtime/v2/go.mod index 04914c4ab0d3..846bdf28185a 100644 --- a/runtime/v2/go.mod +++ b/runtime/v2/go.mod @@ -5,11 +5,11 @@ go 1.23 // server v2 integration replace ( cosmossdk.io/api => ../../api + cosmossdk.io/core => ../../core cosmossdk.io/server/v2/appmanager => ../../server/v2/appmanager cosmossdk.io/server/v2/stf => ../../server/v2/stf cosmossdk.io/store/v2 => ../../store/v2 cosmossdk.io/x/tx => ../../x/tx - cosmossdk.io/core => ../../core ) require ( diff --git a/runtime/v2/go.sum b/runtime/v2/go.sum index fd645c890261..169f4dc9b3c6 100644 --- a/runtime/v2/go.sum +++ b/runtime/v2/go.sum @@ -2,8 +2,6 @@ buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.35.1-20240701160653-fed buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.35.1-20240701160653-fedbb9acfd2f.1/go.mod h1:JTBMfyi+qAXUHumX+rcD2WIq9FNWmdcNh5MjBnSw0L0= buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1 h1:F78ecjvMtgd1aZ1Aj9cvBjURxVGCYvRM+OOy5eR+pjw= buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1/go.mod h1:zqi/LZjZhyvjCMTEVIwAf5VRlkLduuCfqmZxgoormq0= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/server/v2/cometbft/go.mod b/server/v2/cometbft/go.mod index 26356cd3d737..28fde47963e4 100644 --- a/server/v2/cometbft/go.mod +++ b/server/v2/cometbft/go.mod @@ -4,6 +4,7 @@ go 1.23.1 replace ( cosmossdk.io/api => ../../../api + cosmossdk.io/core => ../../../core cosmossdk.io/server/v2 => ../ cosmossdk.io/server/v2/appmanager => ../appmanager cosmossdk.io/server/v2/stf => ../stf @@ -13,7 +14,6 @@ replace ( cosmossdk.io/x/consensus => ../../../x/consensus cosmossdk.io/x/staking => ../../../x/staking cosmossdk.io/x/tx => ../../../x/tx - cosmossdk.io/core => ../../../core github.com/cosmos/cosmos-sdk => ../../../ ) diff --git a/server/v2/cometbft/go.sum b/server/v2/cometbft/go.sum index 6fa28714d8e1..e84b4ccba9e4 100644 --- a/server/v2/cometbft/go.sum +++ b/server/v2/cometbft/go.sum @@ -6,8 +6,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= From b6896056d0187097ba797ce29e78d7bdaa3a3ab3 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 23 Oct 2024 17:52:47 -0500 Subject: [PATCH 16/46] lint fix --- runtime/v2/config.go | 3 +- server/v2/api/grpc/server.go | 3 +- server/v2/api/rest/server.go | 3 +- server/v2/api/telemetry/server.go | 2 +- server/v2/commands.go | 58 ++--------------------------- server/v2/logger.go | 40 -------------------- server/v2/store/server.go | 2 +- server/v2/store/snapshot.go | 3 ++ simapp/v2/app_di.go | 2 +- simapp/v2/simdv2/cmd/commands.go | 17 +++++---- simapp/v2/simdv2/cmd/config.go | 1 - simapp/v2/simdv2/cmd/testnet.go | 4 +- tests/go.mod | 1 + tests/go.sum | 2 - x/accounts/defaults/base/go.mod | 1 + x/accounts/defaults/base/go.sum | 2 - x/accounts/defaults/multisig/go.mod | 1 + x/accounts/defaults/multisig/go.sum | 2 - x/accounts/go.mod | 1 + x/accounts/go.sum | 2 - x/authz/go.mod | 1 + x/authz/go.sum | 2 - x/bank/go.mod | 1 + x/bank/go.sum | 2 - x/circuit/go.mod | 1 + x/circuit/go.sum | 2 - x/consensus/go.mod | 1 + x/consensus/go.sum | 2 - x/distribution/go.mod | 1 + x/distribution/go.sum | 2 - x/epochs/go.mod | 1 + x/epochs/go.sum | 2 - x/evidence/go.mod | 1 + x/evidence/go.sum | 2 - x/feegrant/go.mod | 1 + x/feegrant/go.sum | 2 - x/genutil/client/cli/collect.go | 2 +- x/genutil/v2/cli/commands.go | 2 +- x/gov/go.mod | 1 + x/gov/go.sum | 2 - x/group/go.mod | 1 + x/group/go.sum | 2 - x/mint/go.mod | 1 + x/mint/go.sum | 2 - x/nft/go.mod | 1 + x/nft/go.sum | 2 - x/protocolpool/go.mod | 1 + x/protocolpool/go.sum | 2 - x/slashing/go.mod | 1 + x/slashing/go.sum | 2 - x/staking/go.mod | 1 + x/staking/go.sum | 2 - 52 files changed, 47 insertions(+), 152 deletions(-) diff --git a/runtime/v2/config.go b/runtime/v2/config.go index 44ffe4eaea18..33a22983f327 100644 --- a/runtime/v2/config.go +++ b/runtime/v2/config.go @@ -1,9 +1,10 @@ package runtime import ( + "strings" + "cosmossdk.io/core/server" "cosmossdk.io/depinject" - "strings" ) // GlobalConfig is a recursive configuration map containing configuration diff --git a/server/v2/api/grpc/server.go b/server/v2/api/grpc/server.go index c285b218ab08..2be30b565ed3 100644 --- a/server/v2/api/grpc/server.go +++ b/server/v2/api/grpc/server.go @@ -12,6 +12,7 @@ import ( "strings" "sync" + gogoproto "github.com/cosmos/gogoproto/proto" "github.com/spf13/pflag" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -25,8 +26,6 @@ import ( "cosmossdk.io/log" serverv2 "cosmossdk.io/server/v2" "cosmossdk.io/server/v2/api/grpc/gogoreflection" - - gogoproto "github.com/cosmos/gogoproto/proto" ) const ( diff --git a/server/v2/api/rest/server.go b/server/v2/api/rest/server.go index a89992b19878..1c508a2bcdea 100644 --- a/server/v2/api/rest/server.go +++ b/server/v2/api/rest/server.go @@ -7,11 +7,10 @@ import ( "net/http" "cosmossdk.io/core/server" - "cosmossdk.io/server/v2/appmanager" - "cosmossdk.io/core/transaction" "cosmossdk.io/log" serverv2 "cosmossdk.io/server/v2" + "cosmossdk.io/server/v2/appmanager" ) const ( diff --git a/server/v2/api/telemetry/server.go b/server/v2/api/telemetry/server.go index 7dec75c87673..42c501fe2534 100644 --- a/server/v2/api/telemetry/server.go +++ b/server/v2/api/telemetry/server.go @@ -2,12 +2,12 @@ package telemetry import ( "context" - "cosmossdk.io/core/server" "encoding/json" "fmt" "net/http" "strings" + "cosmossdk.io/core/server" "cosmossdk.io/core/transaction" "cosmossdk.io/log" serverv2 "cosmossdk.io/server/v2" diff --git a/server/v2/commands.go b/server/v2/commands.go index fffcc00e3181..243ac4d153ab 100644 --- a/server/v2/commands.go +++ b/server/v2/commands.go @@ -5,7 +5,6 @@ import ( "errors" "os" "os/signal" - "path/filepath" "runtime/pprof" "strings" "syscall" @@ -25,37 +24,21 @@ func SetPersistentFlags(pflags *pflag.FlagSet, defaultHome string) { pflags.StringP(FlagHome, "", defaultHome, "directory for config and data") } -// Allow the chain developer to overwrite the server default app toml config. -func initServerConfig() ServerConfig { - serverCfg := DefaultServerConfig() - // The server's default minimum gas price is set to "0stake" inside - // app.toml. However, the chain developer can set a default app.toml value for their - // validators here. Please update value based on chain denom. - // - // In summary: - // - if you set serverCfg.MinGasPrices value, validators CAN tweak their - // own app.toml to override, or use this default value. - // - // In simapp, we set the min gas prices to 0. - serverCfg.MinGasPrices = "0stake" - - return serverCfg -} - // AddCommands add the server commands to the root command // It configures the config handling and the logger handling func AddCommands[T transaction.Tx]( rootCmd *cobra.Command, logger log.Logger, - globalServerCfg server.ConfigMap, + globalAppConfig server.ConfigMap, + globalServerConfig ServerConfig, components ...ServerComponent[T], ) (interface{ WriteConfig(string) error }, error) { if len(components) == 0 { return nil, errors.New("no components provided") } - srv := NewServer(initServerConfig(), components...) + srv := NewServer(globalServerConfig, components...) cmds := srv.CLICommands() - startCmd := createStartCommand(srv, globalServerCfg, logger) + startCmd := createStartCommand(srv, globalAppConfig, logger) // TODO necessary? won't the parent context be inherited? startCmd.SetContext(rootCmd.Context()) cmds.Commands = append(cmds.Commands, startCmd) @@ -162,39 +145,6 @@ func wrapCPUProfile(logger log.Logger, cfg server.ConfigMap, callbackFn func() e return callbackFn() } -// configHandle writes the default config to the home directory if it does not exist and sets the server context -func configHandle[T transaction.Tx](s *Server[T], cmd *cobra.Command) error { - home, err := cmd.Flags().GetString(FlagHome) - if err != nil { - return err - } - - configDir := filepath.Join(home, "config") - - // we need to check app.toml as the config folder can already exist for the client.toml - if _, err := os.Stat(filepath.Join(configDir, "app.toml")); os.IsNotExist(err) { - if err = s.WriteConfig(configDir); err != nil { - return err - } - } - - v, err := ReadConfig(configDir) - if err != nil { - return err - } - - if err := v.BindPFlags(cmd.Flags()); err != nil { - return err - } - - logger, err := NewLogger(v, cmd.OutOrStdout()) - if err != nil { - return err - } - - return SetCmdServerContext(cmd, v, logger) -} - // findSubCommand finds a sub-command of the provided command whose Use // string is or begins with the provided subCmdName. // It verifies the command's aliases as well. diff --git a/server/v2/logger.go b/server/v2/logger.go index d28ddfd3b4b6..8ca80e4cce45 100644 --- a/server/v2/logger.go +++ b/server/v2/logger.go @@ -1,10 +1,8 @@ package serverv2 import ( - "fmt" "io" - "cosmossdk.io/core/server" "github.com/rs/zerolog" "github.com/spf13/viper" @@ -44,41 +42,3 @@ func NewLogger(v *viper.Viper, out io.Writer) (log.Logger, error) { return log.NewLogger(out, opts...), nil } - -func NewLoggerFromConfig(configMap server.ConfigMap, out io.Writer) (log.Logger, error) { - var opts []log.Option - if v, ok := configMap[FlagLogFormat]; ok && v == OutputFormatJSON { - opts = append(opts, log.OutputJSONOption()) - } - if v, ok := configMap[FlagLogNoColor]; ok && v == true { - opts = append(opts, log.ColorOption(false)) - } - if v, ok := configMap[FlagTrace]; ok && v == true { - opts = append(opts, log.TraceOption(true)) - } - logLvlAny, ok := configMap[FlagLogLevel] - if !ok { - return log.NewLogger(out, opts...), nil - } - logLvlStr, ok := logLvlAny.(string) - if !ok { - return nil, fmt.Errorf("invalid log level type: %T", logLvlAny) - } - - logLvl, err := zerolog.ParseLevel(logLvlStr) - switch { - case err != nil: - // If the log level is not a valid zerolog level, then we try to parse it as a key filter. - filterFunc, err := log.ParseLogLevel(logLvlStr) - if err != nil { - return nil, err - } - - opts = append(opts, log.FilterOption(filterFunc)) - default: - opts = append(opts, log.LevelOption(logLvl)) - } - - return log.NewLogger(out, opts...), nil - -} diff --git a/server/v2/store/server.go b/server/v2/store/server.go index f5633d314366..897773abf28e 100644 --- a/server/v2/store/server.go +++ b/server/v2/store/server.go @@ -2,11 +2,11 @@ package store import ( "context" - "cosmossdk.io/core/server" "fmt" "github.com/spf13/cobra" + "cosmossdk.io/core/server" "cosmossdk.io/core/transaction" serverv2 "cosmossdk.io/server/v2" storev2 "cosmossdk.io/store/v2" diff --git a/server/v2/store/snapshot.go b/server/v2/store/snapshot.go index 811e45f292bf..8340ee77e8c2 100644 --- a/server/v2/store/snapshot.go +++ b/server/v2/store/snapshot.go @@ -96,6 +96,9 @@ func (s *Server[T]) RestoreSnapshotCmd() *cobra.Command { logger := log.NewLogger(cmd.OutOrStdout()) rootStore, _, err := createRootStore(v, logger) + if err != nil { + return err + } sm, err := createSnapshotsManager(cmd, v, logger, rootStore) if err != nil { return err diff --git a/simapp/v2/app_di.go b/simapp/v2/app_di.go index c02743f2980a..0191fcbe2d51 100644 --- a/simapp/v2/app_di.go +++ b/simapp/v2/app_di.go @@ -1,7 +1,6 @@ package simapp import ( - serverstore "cosmossdk.io/server/v2/store" _ "embed" "fmt" @@ -14,6 +13,7 @@ import ( "cosmossdk.io/depinject" "cosmossdk.io/log" "cosmossdk.io/runtime/v2" + serverstore "cosmossdk.io/server/v2/store" "cosmossdk.io/store/v2" "cosmossdk.io/store/v2/root" basedepinject "cosmossdk.io/x/accounts/defaults/base/depinject" diff --git a/simapp/v2/simdv2/cmd/commands.go b/simapp/v2/simdv2/cmd/commands.go index e187d025836c..13f3466d2a9a 100644 --- a/simapp/v2/simdv2/cmd/commands.go +++ b/simapp/v2/simdv2/cmd/commands.go @@ -1,22 +1,23 @@ package cmd import ( - "cosmossdk.io/server/v2/api/grpc" - "cosmossdk.io/server/v2/api/rest" - "cosmossdk.io/server/v2/api/telemetry" - "cosmossdk.io/server/v2/cometbft" - serverstore "cosmossdk.io/server/v2/store" "errors" + "github.com/spf13/cobra" + "cosmossdk.io/client/v2/offchain" coreserver "cosmossdk.io/core/server" "cosmossdk.io/core/transaction" "cosmossdk.io/log" runtimev2 "cosmossdk.io/runtime/v2" serverv2 "cosmossdk.io/server/v2" + "cosmossdk.io/server/v2/api/grpc" + "cosmossdk.io/server/v2/api/rest" + "cosmossdk.io/server/v2/api/telemetry" + "cosmossdk.io/server/v2/cometbft" + serverstore "cosmossdk.io/server/v2/store" "cosmossdk.io/simapp/v2" confixcmd "cosmossdk.io/tools/confix/cmd" - "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/debug" @@ -35,7 +36,7 @@ type configWriter interface { } // commandDependencies is a struct that contains all the dependencies needed to initialize the root command. -// an alternative design could fetch these even later from the command context. +// an alternative design could fetch these even later from the command context type commandDependencies[T transaction.Tx] struct { globalAppConfig coreserver.ConfigMap txConfig client.TxConfig @@ -73,6 +74,7 @@ func initRootCmd[T transaction.Tx]( rootCmd, logger, deps.globalAppConfig, + initServerConfig(), &cometbft.CometBFTServer[T]{}, &grpc.Server[T]{}, &serverstore.Server[T]{}, @@ -121,6 +123,7 @@ func initRootCmd[T transaction.Tx]( rootCmd, logger, deps.globalAppConfig, + initServerConfig(), cometBftServer, grpcServer, storeServer, diff --git a/simapp/v2/simdv2/cmd/config.go b/simapp/v2/simdv2/cmd/config.go index 2889cea3e4b5..16cb19db93e7 100644 --- a/simapp/v2/simdv2/cmd/config.go +++ b/simapp/v2/simdv2/cmd/config.go @@ -58,7 +58,6 @@ gas-adjustment = {{ .GasConfig.GasAdjustment }} } // Allow the chain developer to overwrite the server default app toml config. -// TODO: show that this now depcreated function allowed no overriding of this parameter func initServerConfig() serverv2.ServerConfig { serverCfg := serverv2.DefaultServerConfig() // The server's default minimum gas price is set to "0stake" inside diff --git a/simapp/v2/simdv2/cmd/testnet.go b/simapp/v2/simdv2/cmd/testnet.go index 44254fc01edc..d51a90249668 100644 --- a/simapp/v2/simdv2/cmd/testnet.go +++ b/simapp/v2/simdv2/cmd/testnet.go @@ -2,8 +2,6 @@ package cmd import ( "bufio" - "cosmossdk.io/server/v2/cometbft" - "cosmossdk.io/server/v2/store" "encoding/json" "fmt" "net" @@ -22,6 +20,8 @@ import ( runtimev2 "cosmossdk.io/runtime/v2" serverv2 "cosmossdk.io/server/v2" "cosmossdk.io/server/v2/api/grpc" + "cosmossdk.io/server/v2/cometbft" + "cosmossdk.io/server/v2/store" banktypes "cosmossdk.io/x/bank/types" bankv2types "cosmossdk.io/x/bank/v2/types" stakingtypes "cosmossdk.io/x/staking/types" diff --git a/tests/go.mod b/tests/go.mod index a8b828b0512e..082f621b2fb4 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -264,6 +264,7 @@ replace ( // Below are the long-lived replace for tests. replace ( + cosmossdk.io/core => ../core // We always want to test against the latest version of the simapp. cosmossdk.io/simapp => ../simapp github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 diff --git a/tests/go.sum b/tests/go.sum index c912b0ab64ba..b408c9a72e49 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -192,8 +192,6 @@ cloud.google.com/go/webrisk v1.4.0/go.mod h1:Hn8X6Zr+ziE2aNd8SliSDWpEnSS1u4R9+xX cloud.google.com/go/webrisk v1.5.0/go.mod h1:iPG6fr52Tv7sGk0H6qUFzmL3HHZev1htXuWDEEsqMTg= cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0= cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/accounts/defaults/base/go.mod b/x/accounts/defaults/base/go.mod index 8019839d405a..915abbbedbd9 100644 --- a/x/accounts/defaults/base/go.mod +++ b/x/accounts/defaults/base/go.mod @@ -172,6 +172,7 @@ replace github.com/cosmos/cosmos-sdk => ../../../../. replace ( cosmossdk.io/api => ../../../../api cosmossdk.io/collections => ../../../../collections // TODO tag new collections ASAP + cosmossdk.io/core => ../../../../core cosmossdk.io/store => ../../../../store cosmossdk.io/x/accounts => ../../. cosmossdk.io/x/bank => ../../../bank diff --git a/x/accounts/defaults/base/go.sum b/x/accounts/defaults/base/go.sum index 505182c3fbb8..47bd986a2209 100644 --- a/x/accounts/defaults/base/go.sum +++ b/x/accounts/defaults/base/go.sum @@ -4,8 +4,6 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1/go.mod h1:zqi/LZjZhyvjCMTEVIwAf5VRlkLduuCfqmZxgoormq0= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/accounts/defaults/multisig/go.mod b/x/accounts/defaults/multisig/go.mod index 5a3151771995..2a54379a9f3f 100644 --- a/x/accounts/defaults/multisig/go.mod +++ b/x/accounts/defaults/multisig/go.mod @@ -172,6 +172,7 @@ replace github.com/cosmos/cosmos-sdk => ../../../../. replace ( cosmossdk.io/api => ../../../../api cosmossdk.io/collections => ../../../../collections // TODO tag new collections ASAP + cosmossdk.io/core => ../../../../core cosmossdk.io/store => ../../../../store cosmossdk.io/x/accounts => ../../. cosmossdk.io/x/bank => ../../../bank diff --git a/x/accounts/defaults/multisig/go.sum b/x/accounts/defaults/multisig/go.sum index 505182c3fbb8..47bd986a2209 100644 --- a/x/accounts/defaults/multisig/go.sum +++ b/x/accounts/defaults/multisig/go.sum @@ -4,8 +4,6 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1/go.mod h1:zqi/LZjZhyvjCMTEVIwAf5VRlkLduuCfqmZxgoormq0= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/accounts/go.mod b/x/accounts/go.mod index 4239be9a2ffa..cc29f5f34f47 100644 --- a/x/accounts/go.mod +++ b/x/accounts/go.mod @@ -176,6 +176,7 @@ replace github.com/cosmos/cosmos-sdk => ../../. replace ( cosmossdk.io/api => ../../api cosmossdk.io/collections => ../../collections + cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/staking => ../staking diff --git a/x/accounts/go.sum b/x/accounts/go.sum index 505182c3fbb8..47bd986a2209 100644 --- a/x/accounts/go.sum +++ b/x/accounts/go.sum @@ -4,8 +4,6 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1/go.mod h1:zqi/LZjZhyvjCMTEVIwAf5VRlkLduuCfqmZxgoormq0= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/authz/go.mod b/x/authz/go.mod index 8f2324c6f906..e5a1e36809a1 100644 --- a/x/authz/go.mod +++ b/x/authz/go.mod @@ -177,6 +177,7 @@ replace github.com/cosmos/cosmos-sdk => ../../. replace ( cosmossdk.io/api => ../../api cosmossdk.io/collections => ../../collections + cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/staking => ../staking diff --git a/x/authz/go.sum b/x/authz/go.sum index 505182c3fbb8..47bd986a2209 100644 --- a/x/authz/go.sum +++ b/x/authz/go.sum @@ -4,8 +4,6 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1/go.mod h1:zqi/LZjZhyvjCMTEVIwAf5VRlkLduuCfqmZxgoormq0= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/bank/go.mod b/x/bank/go.mod index b273bff86cd5..cd2d427aea03 100644 --- a/x/bank/go.mod +++ b/x/bank/go.mod @@ -175,6 +175,7 @@ replace github.com/cosmos/cosmos-sdk => ../../. replace ( cosmossdk.io/api => ../../api cosmossdk.io/collections => ../../collections + cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/staking => ../staking cosmossdk.io/x/tx => ../tx diff --git a/x/bank/go.sum b/x/bank/go.sum index 505182c3fbb8..47bd986a2209 100644 --- a/x/bank/go.sum +++ b/x/bank/go.sum @@ -4,8 +4,6 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1/go.mod h1:zqi/LZjZhyvjCMTEVIwAf5VRlkLduuCfqmZxgoormq0= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/circuit/go.mod b/x/circuit/go.mod index cc7bbefe172e..28ff11a8ae6f 100644 --- a/x/circuit/go.mod +++ b/x/circuit/go.mod @@ -172,6 +172,7 @@ replace github.com/cosmos/cosmos-sdk => ../../. // TODO remove post spinning out all modules replace ( cosmossdk.io/api => ../../api + cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/staking => ../staking diff --git a/x/circuit/go.sum b/x/circuit/go.sum index 0a10fbf93445..504714b4a19f 100644 --- a/x/circuit/go.sum +++ b/x/circuit/go.sum @@ -6,8 +6,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/consensus/go.mod b/x/consensus/go.mod index d8dd49174c58..b61945345de7 100644 --- a/x/consensus/go.mod +++ b/x/consensus/go.mod @@ -170,6 +170,7 @@ replace github.com/cosmos/cosmos-sdk => ../../. replace ( cosmossdk.io/api => ../../api + cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/staking => ../staking diff --git a/x/consensus/go.sum b/x/consensus/go.sum index 0a10fbf93445..504714b4a19f 100644 --- a/x/consensus/go.sum +++ b/x/consensus/go.sum @@ -6,8 +6,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/distribution/go.mod b/x/distribution/go.mod index fb69978f928f..2852ebc2ba48 100644 --- a/x/distribution/go.mod +++ b/x/distribution/go.mod @@ -173,6 +173,7 @@ replace github.com/cosmos/cosmos-sdk => ../../. replace ( cosmossdk.io/api => ../../api cosmossdk.io/collections => ../../collections + cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/protocolpool => ../protocolpool diff --git a/x/distribution/go.sum b/x/distribution/go.sum index 505182c3fbb8..47bd986a2209 100644 --- a/x/distribution/go.sum +++ b/x/distribution/go.sum @@ -4,8 +4,6 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1/go.mod h1:zqi/LZjZhyvjCMTEVIwAf5VRlkLduuCfqmZxgoormq0= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/epochs/go.mod b/x/epochs/go.mod index 5fbb1647d68d..2f3f28c55328 100644 --- a/x/epochs/go.mod +++ b/x/epochs/go.mod @@ -175,6 +175,7 @@ replace github.com/cosmos/cosmos-sdk => ../../. // TODO remove post spinning out all modules replace ( cosmossdk.io/api => ../../api + cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/staking => ../staking diff --git a/x/epochs/go.sum b/x/epochs/go.sum index 0a10fbf93445..504714b4a19f 100644 --- a/x/epochs/go.sum +++ b/x/epochs/go.sum @@ -6,8 +6,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/evidence/go.mod b/x/evidence/go.mod index 2db9245de044..761ba97cf28f 100644 --- a/x/evidence/go.mod +++ b/x/evidence/go.mod @@ -172,6 +172,7 @@ replace github.com/cosmos/cosmos-sdk => ../../. // TODO remove post spinning out all modules replace ( cosmossdk.io/api => ../../api + cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/staking => ../staking diff --git a/x/evidence/go.sum b/x/evidence/go.sum index 0a10fbf93445..504714b4a19f 100644 --- a/x/evidence/go.sum +++ b/x/evidence/go.sum @@ -6,8 +6,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/feegrant/go.mod b/x/feegrant/go.mod index 4f1975c00166..030f84ab6b53 100644 --- a/x/feegrant/go.mod +++ b/x/feegrant/go.mod @@ -180,6 +180,7 @@ replace github.com/cosmos/cosmos-sdk => ../../. replace ( cosmossdk.io/api => ../../api cosmossdk.io/collections => ../../collections + cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/gov => ../gov diff --git a/x/feegrant/go.sum b/x/feegrant/go.sum index a2dce77f0c14..a57a57ba7b65 100644 --- a/x/feegrant/go.sum +++ b/x/feegrant/go.sum @@ -4,8 +4,6 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1/go.mod h1:zqi/LZjZhyvjCMTEVIwAf5VRlkLduuCfqmZxgoormq0= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/genutil/client/cli/collect.go b/x/genutil/client/cli/collect.go index 274d1dcf68bf..10d9db0cdc38 100644 --- a/x/genutil/client/cli/collect.go +++ b/x/genutil/client/cli/collect.go @@ -1,12 +1,12 @@ package cli import ( - "cosmossdk.io/core/transaction" "encoding/json" "path/filepath" "github.com/spf13/cobra" + "cosmossdk.io/core/transaction" "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/client" diff --git a/x/genutil/v2/cli/commands.go b/x/genutil/v2/cli/commands.go index 92a409f9bc68..f1fbff92c413 100644 --- a/x/genutil/v2/cli/commands.go +++ b/x/genutil/v2/cli/commands.go @@ -1,11 +1,11 @@ package cli import ( - "cosmossdk.io/core/transaction" "encoding/json" "github.com/spf13/cobra" + "cosmossdk.io/core/transaction" banktypes "cosmossdk.io/x/bank/types" "github.com/cosmos/cosmos-sdk/client" diff --git a/x/gov/go.mod b/x/gov/go.mod index 9d37de53be7a..4f8fd0dc4d8f 100644 --- a/x/gov/go.mod +++ b/x/gov/go.mod @@ -176,6 +176,7 @@ replace github.com/cosmos/cosmos-sdk => ../../. replace ( cosmossdk.io/api => ../../api cosmossdk.io/collections => ../../collections + cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/protocolpool => ../protocolpool diff --git a/x/gov/go.sum b/x/gov/go.sum index 6d8f9ea58704..0aecae5e6593 100644 --- a/x/gov/go.sum +++ b/x/gov/go.sum @@ -4,8 +4,6 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1/go.mod h1:zqi/LZjZhyvjCMTEVIwAf5VRlkLduuCfqmZxgoormq0= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/group/go.mod b/x/group/go.mod index 8e48243d5ec9..1dd78427f899 100644 --- a/x/group/go.mod +++ b/x/group/go.mod @@ -182,6 +182,7 @@ replace github.com/cosmos/cosmos-sdk => ../../ replace ( cosmossdk.io/api => ../../api cosmossdk.io/collections => ../../collections + cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/accounts => ../accounts cosmossdk.io/x/accounts/defaults/base => ../accounts/defaults/base diff --git a/x/group/go.sum b/x/group/go.sum index dc0cec8f43ba..ca1f744e0a21 100644 --- a/x/group/go.sum +++ b/x/group/go.sum @@ -4,8 +4,6 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1/go.mod h1:zqi/LZjZhyvjCMTEVIwAf5VRlkLduuCfqmZxgoormq0= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/mint/go.mod b/x/mint/go.mod index 1cad7f554413..724df0df7df1 100644 --- a/x/mint/go.mod +++ b/x/mint/go.mod @@ -176,6 +176,7 @@ replace github.com/cosmos/cosmos-sdk => ../../. // TODO remove post spinning out all modules replace ( cosmossdk.io/api => ../../api + cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/consensus => ../consensus diff --git a/x/mint/go.sum b/x/mint/go.sum index 0a10fbf93445..504714b4a19f 100644 --- a/x/mint/go.sum +++ b/x/mint/go.sum @@ -6,8 +6,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/nft/go.mod b/x/nft/go.mod index 77536d1b8a3d..d8de5dbf40d0 100644 --- a/x/nft/go.mod +++ b/x/nft/go.mod @@ -172,6 +172,7 @@ replace github.com/cosmos/cosmos-sdk => ../../. // TODO remove post spinning out all modules replace ( cosmossdk.io/api => ../../api + cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/staking => ../staking diff --git a/x/nft/go.sum b/x/nft/go.sum index 0a10fbf93445..504714b4a19f 100644 --- a/x/nft/go.sum +++ b/x/nft/go.sum @@ -6,8 +6,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/protocolpool/go.mod b/x/protocolpool/go.mod index e3ef7efb1957..3da3a7e9ed66 100644 --- a/x/protocolpool/go.mod +++ b/x/protocolpool/go.mod @@ -172,6 +172,7 @@ replace github.com/cosmos/cosmos-sdk => ../../. // TODO remove post spinning out all modules replace ( cosmossdk.io/api => ../../api + cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/staking => ../staking diff --git a/x/protocolpool/go.sum b/x/protocolpool/go.sum index 0a10fbf93445..504714b4a19f 100644 --- a/x/protocolpool/go.sum +++ b/x/protocolpool/go.sum @@ -6,8 +6,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/slashing/go.mod b/x/slashing/go.mod index ff10738fdf0f..d9555cd760df 100644 --- a/x/slashing/go.mod +++ b/x/slashing/go.mod @@ -173,6 +173,7 @@ replace github.com/cosmos/cosmos-sdk => ../../. // TODO remove post spinning out all modules replace ( cosmossdk.io/api => ../../api + cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/staking => ../staking diff --git a/x/slashing/go.sum b/x/slashing/go.sum index 199ef6b981a0..83b48618d669 100644 --- a/x/slashing/go.sum +++ b/x/slashing/go.sum @@ -6,8 +6,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/staking/go.mod b/x/staking/go.mod index f93e1618ee9c..5a2c0a9ce409 100644 --- a/x/staking/go.mod +++ b/x/staking/go.mod @@ -178,6 +178,7 @@ replace github.com/cosmos/cosmos-sdk => ../../. replace ( cosmossdk.io/api => ../../api cosmossdk.io/collections => ../../collections + cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/tx => ../tx diff --git a/x/staking/go.sum b/x/staking/go.sum index 505182c3fbb8..47bd986a2209 100644 --- a/x/staking/go.sum +++ b/x/staking/go.sum @@ -4,8 +4,6 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1/go.mod h1:zqi/LZjZhyvjCMTEVIwAf5VRlkLduuCfqmZxgoormq0= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= From 10e2d4b05d756260d217c370bf79d3bbc54ae21a Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 23 Oct 2024 17:56:21 -0500 Subject: [PATCH 17/46] moar dep fix --- client/v2/go.mod | 1 + client/v2/go.sum | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/client/v2/go.mod b/client/v2/go.mod index 6a895d059fb8..66456567e284 100644 --- a/client/v2/go.mod +++ b/client/v2/go.mod @@ -175,6 +175,7 @@ replace github.com/cosmos/cosmos-sdk => ./../../ // TODO remove post spinning out all modules replace ( cosmossdk.io/api => ./../../api + cosmossdk.io/core => ./../../core cosmossdk.io/store => ./../../store cosmossdk.io/x/bank => ./../../x/bank cosmossdk.io/x/gov => ./../../x/gov diff --git a/client/v2/go.sum b/client/v2/go.sum index 77ce94ccb2cb..b4fc858a84a5 100644 --- a/client/v2/go.sum +++ b/client/v2/go.sum @@ -6,8 +6,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= From b894a32f4d02a80a74948375c9a697fd280aa9e0 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 23 Oct 2024 18:22:07 -0500 Subject: [PATCH 18/46] default comet config --- simapp/v2/simdv2/cmd/commands.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/simapp/v2/simdv2/cmd/commands.go b/simapp/v2/simdv2/cmd/commands.go index 13f3466d2a9a..96452aa7a140 100644 --- a/simapp/v2/simdv2/cmd/commands.go +++ b/simapp/v2/simdv2/cmd/commands.go @@ -70,12 +70,14 @@ func initRootCmd[T transaction.Tx]( // build CLI skeleton for initial config parsing or a client application invocation if deps.simApp == nil { + comet := &cometbft.CometBFTServer[T]{} + comet = comet.WithConfigOptions(initCometConfig()) return serverv2.AddCommands[T]( rootCmd, logger, deps.globalAppConfig, initServerConfig(), - &cometbft.CometBFTServer[T]{}, + comet, &grpc.Server[T]{}, &serverstore.Server[T]{}, &telemetry.Server[T]{}, @@ -95,7 +97,6 @@ func initRootCmd[T transaction.Tx]( &genericTxDecoder[T]{deps.txConfig}, deps.globalAppConfig, initCometOptions[T](), - initCometConfig(), ) if err != nil { return nil, err From fc689793bb7a51e6add3b5f0d99917106e9c97c2 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 24 Oct 2024 11:01:12 -0500 Subject: [PATCH 19/46] minor clean up --- client/v2/helpers/command.go | 12 ++++++++++++ core/server/config.go | 5 ----- runtime/v2/config.go | 4 ---- simapp/v2/simdv2/cmd/commands.go | 7 ++++--- simapp/v2/simdv2/cmd/root_di.go | 26 ++++---------------------- simapp/v2/simdv2/main.go | 6 ++++-- 6 files changed, 24 insertions(+), 36 deletions(-) create mode 100644 client/v2/helpers/command.go diff --git a/client/v2/helpers/command.go b/client/v2/helpers/command.go new file mode 100644 index 000000000000..1158bf38d27d --- /dev/null +++ b/client/v2/helpers/command.go @@ -0,0 +1,12 @@ +package helpers + +import "github.com/spf13/cobra" + +func DefaultCmd() *cobra.Command { + cmd := &cobra.Command{} + pflags := cmd.PersistentFlags() + pflags.String(FlagLogLevel, "info", "The logging level (trace|debug|info|warn|error|fatal|panic|disabled or '*:,:')") + pflags.String(FlagLogFormat, "plain", "The logging format (json|plain)") + pflags.Bool(FlagLogNoColor, false, "Disable colored logs") + pflags.StringP(FlagHome, "", defaultHome, "directory for config and data") +} diff --git a/core/server/config.go b/core/server/config.go index d65cfcb3fd58..f3974c48e8b7 100644 --- a/core/server/config.go +++ b/core/server/config.go @@ -10,11 +10,6 @@ type DynamicConfig interface { // ConfigMap is a recursive map of configuration values. type ConfigMap map[string]any -// TODO delete? -func (c ConfigMap) Get(s string) any { - return c[s] -} - // ModuleConfigMap is used to specify module configuration. // Keys (and there default values and types) should be set in Config // and returned by module specific provider function. diff --git a/runtime/v2/config.go b/runtime/v2/config.go index 33a22983f327..ef62ddc77ef8 100644 --- a/runtime/v2/config.go +++ b/runtime/v2/config.go @@ -15,10 +15,6 @@ type GlobalConfig server.ConfigMap // ModuleConfigMaps is a map module scoped ConfigMaps type ModuleConfigMaps map[string]server.ConfigMap -// TODO combine below 2 functions -// - linear search for module name in provider is OK -// - move elsewhere, server/v2 or runtime/v2 ? - // ProvideModuleConfigMaps returns a map of module name to module config map. // The module config map is a map of flag to value. func ProvideModuleConfigMaps( diff --git a/simapp/v2/simdv2/cmd/commands.go b/simapp/v2/simdv2/cmd/commands.go index 8c44a52e085e..dbdf454587a0 100644 --- a/simapp/v2/simdv2/cmd/commands.go +++ b/simapp/v2/simdv2/cmd/commands.go @@ -14,6 +14,7 @@ import ( "cosmossdk.io/server/v2/api/grpc" "cosmossdk.io/server/v2/api/rest" "cosmossdk.io/server/v2/api/telemetry" + "cosmossdk.io/server/v2/cometbft" serverstore "cosmossdk.io/server/v2/store" "cosmossdk.io/simapp/v2" confixcmd "cosmossdk.io/tools/confix/cmd" @@ -108,8 +109,8 @@ func initRootCmd[T transaction.Tx]( if err != nil { return nil, err } - // store "server" (big quotes). - storeServer, err := serverstore.New[T](simApp.Store(), deps.globalAppConfig) + // store component (not a server) + storeComponent, err := serverstore.New[T](simApp.Store(), deps.globalAppConfig) if err != nil { return nil, err } @@ -126,7 +127,7 @@ func initRootCmd[T transaction.Tx]( initServerConfig(), cometBftServer, grpcServer, - storeServer, + storeComponent, telemetryServer, restServer, ) diff --git a/simapp/v2/simdv2/cmd/root_di.go b/simapp/v2/simdv2/cmd/root_di.go index 187eaa57acb0..a9a0b6c55773 100644 --- a/simapp/v2/simdv2/cmd/root_di.go +++ b/simapp/v2/simdv2/cmd/root_di.go @@ -18,7 +18,6 @@ import ( "cosmossdk.io/log" "cosmossdk.io/runtime/v2" serverv2 "cosmossdk.io/server/v2" - "cosmossdk.io/server/v2/cometbft" "cosmossdk.io/simapp/v2" "github.com/cosmos/cosmos-sdk/client" @@ -31,32 +30,15 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/types" ) -// NewCometBFTRootCmd creates a new root command for simd, -// using the CometBFT server component for consensus. -// It is called once in the main function. -func NewCometBFTRootCmd[T transaction.Tx]() *cobra.Command { - return NewRootCmdWithConsensusComponent(func(cc client.Context) serverv2.ServerComponent[T] { - return cometbft.New[T]( - &genericTxDecoder[T]{cc.TxConfig}, - initCometOptions[T](), - initCometConfig(), - ) - }) -} - -// NewRootCmdWithConsensusComponent returns a new root command, -// using the provided callback to instantiate the server component for the consensus layer. -// Callers who want to use CometBFT should call [NewCometBFTRootCmd] directly. -func NewRootCmdWithConsensusComponent[T transaction.Tx]( - makeConsensusComponent func(cc client.Context) serverv2.ServerComponent[T], -) *cobra.Command { +func NewRootCmd[T transaction.Tx]( + args ...string, +) (*cobra.Command, error) { var ( autoCliOpts autocli.AppOptions moduleManager *runtime.MM[T] clientCtx client.Context ) - // parse config - defaultHomeDir, err := clientv2helpers.DefaultHomeDir(".simappv2") + defaultHomeDir, err := clientv2helpers.DefaultHomeDir(".simappv2", clientv2helpers.EnvPrefix) if err != nil { return nil, err } diff --git a/simapp/v2/simdv2/main.go b/simapp/v2/simdv2/main.go index 02dc59063d09..d01a45030cb9 100644 --- a/simapp/v2/simdv2/main.go +++ b/simapp/v2/simdv2/main.go @@ -20,8 +20,10 @@ func main() { } os.Exit(1) } - if err := rootCmd.Execute(); err != nil { - fmt.Fprintln(rootCmd.OutOrStderr(), err) + if err = rootCmd.Execute(); err != nil { + if _, pErr := fmt.Fprintln(rootCmd.OutOrStderr(), err); pErr != nil { + panic(errors.Join(err, pErr)) + } os.Exit(1) } } From 348028ff7979caf027626bad4bdecba1cb4e8c4d Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 24 Oct 2024 16:16:48 -0500 Subject: [PATCH 20/46] refactor --- client/v2/helpers/command.go | 12 --- client/v2/helpers/home.go | 24 ----- server/v2/commands.go | 145 +++++++++++++++++++++++++- server/v2/server.go | 5 + simapp/v2/simdv2/cmd/commands.go | 11 +- simapp/v2/simdv2/cmd/root_di.go | 170 +++++++++++-------------------- simapp/v2/simdv2/main.go | 3 +- 7 files changed, 211 insertions(+), 159 deletions(-) delete mode 100644 client/v2/helpers/command.go diff --git a/client/v2/helpers/command.go b/client/v2/helpers/command.go deleted file mode 100644 index 1158bf38d27d..000000000000 --- a/client/v2/helpers/command.go +++ /dev/null @@ -1,12 +0,0 @@ -package helpers - -import "github.com/spf13/cobra" - -func DefaultCmd() *cobra.Command { - cmd := &cobra.Command{} - pflags := cmd.PersistentFlags() - pflags.String(FlagLogLevel, "info", "The logging level (trace|debug|info|warn|error|fatal|panic|disabled or '*:,:')") - pflags.String(FlagLogFormat, "plain", "The logging format (json|plain)") - pflags.Bool(FlagLogNoColor, false, "Disable colored logs") - pflags.StringP(FlagHome, "", defaultHome, "directory for config and data") -} diff --git a/client/v2/helpers/home.go b/client/v2/helpers/home.go index 631b9fa0e457..af3fc2886673 100644 --- a/client/v2/helpers/home.go +++ b/client/v2/helpers/home.go @@ -46,27 +46,3 @@ func GetNodeHomeDirectory(name string) (string, error) { return filepath.Join(userHomeDir, name), nil } - -func DefaultHomeDir(name string) (string, error) { - // get the home directory from the environment variable - // to not clash with the $HOME system variable, when no prefix is set - // we check the NODE_HOME environment variable - envPrefix := EnvPrefix - homeDir, envHome := "", "HOME" - if len(envPrefix) > 0 { - homeDir = os.Getenv(envPrefix + "_" + envHome) - } else { - homeDir = os.Getenv("NODE_" + envHome) - } - if homeDir != "" { - return filepath.Clean(homeDir), nil - } - - // get user home directory - userHomeDir, err := os.UserHomeDir() - if err != nil { - return "", err - } - - return filepath.Join(userHomeDir, name), nil -} diff --git a/server/v2/commands.go b/server/v2/commands.go index 243ac4d153ab..7dbf72145b4c 100644 --- a/server/v2/commands.go +++ b/server/v2/commands.go @@ -5,18 +5,161 @@ import ( "errors" "os" "os/signal" + "path/filepath" "runtime/pprof" "strings" "syscall" "github.com/spf13/cobra" "github.com/spf13/pflag" + "github.com/spf13/viper" "cosmossdk.io/core/server" "cosmossdk.io/core/transaction" "cosmossdk.io/log" ) +type RootCmdBuilder struct { + DefaultHome string + EnvPrefix string + + use string + fixture CommandFixture + vipr *viper.Viper + logger log.Logger + subCommand *cobra.Command + config server.ConfigMap +} + +type CommandFixture interface { + Bootstrap(cmd *cobra.Command) (WritesConfig, error) + RootCommand( + rootCommand *cobra.Command, + subCommand *cobra.Command, + logger log.Logger, + config server.ConfigMap, + ) (*cobra.Command, error) +} + +func NewRootCmdBuilder( + fixture CommandFixture, + use string, + defaultHomeBasename string, +) (*RootCmdBuilder, error) { + f := &RootCmdBuilder{ + fixture: fixture, + use: use, + } + var err error + f.DefaultHome, err = f.DefaultHomeDir(defaultHomeBasename) + if err != nil { + return nil, err + } + return f, nil +} + +func (b *RootCmdBuilder) Logger() log.Logger { + return b.logger +} + +func (b *RootCmdBuilder) SubCommand() *cobra.Command { + return b.subCommand +} + +func (b *RootCmdBuilder) Config() server.ConfigMap { + return b.config +} + +func (b *RootCmdBuilder) DefaultHomeDir(name string) (string, error) { + // get the home directory from the environment variable + // to not clash with the $HOME system variable, when no prefix is set + // we check the NODE_HOME environment variable + homeDir, envHome := "", "HOME" + if len(b.EnvPrefix) > 0 { + homeDir = os.Getenv(b.EnvPrefix + "_" + envHome) + } else { + homeDir = os.Getenv("NODE_" + envHome) + } + if homeDir != "" { + return filepath.Clean(homeDir), nil + } + + // get user home directory + userHomeDir, err := os.UserHomeDir() + if err != nil { + return "", err + } + + return filepath.Join(userHomeDir, name), nil +} + +func (b *RootCmdBuilder) Command() (*cobra.Command, error) { + cmd := &cobra.Command{Use: b.use, SilenceErrors: true} + SetPersistentFlags(cmd.PersistentFlags(), b.DefaultHome) + // update the global viper with the root command's configuration + viper.SetEnvPrefix(b.EnvPrefix) + viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_")) + viper.AutomaticEnv() + if b.vipr != nil && b.logger != nil { + err := SetCmdServerContext(cmd, b.vipr, b.logger) + if err != nil { + return nil, err + } + } + return cmd, nil +} + +func (b *RootCmdBuilder) Build( + args []string, +) (*cobra.Command, error) { + cmd, err := b.Command() + if err != nil { + return nil, err + } + configWriter, err := b.fixture.Bootstrap(cmd) + if err != nil { + return nil, err + } + b.subCommand, _, err = cmd.Traverse(args) + if err != nil { + return nil, err + } + if err = cmd.ParseFlags(args); err != nil { + // help requested, return the command early + if errors.Is(err, pflag.ErrHelp) { + return cmd, nil + } + return nil, err + } + home, err := cmd.Flags().GetString(FlagHome) + if err != nil { + return nil, err + } + configDir := filepath.Join(home, "config") + // create app.toml if it does not already exist + if _, err = os.Stat(filepath.Join(configDir, "app.toml")); os.IsNotExist(err) { + if err = configWriter.WriteConfig(configDir); err != nil { + return nil, err + } + } + b.vipr, err = ReadConfig(configDir) + if err != nil { + return nil, err + } + if err = b.vipr.BindPFlags(cmd.Flags()); err != nil { + return nil, err + } + b.logger, err = NewLogger(b.vipr, cmd.OutOrStdout()) + if err != nil { + return nil, err + } + b.config = b.vipr.AllSettings() + + return b.fixture.RootCommand(cmd, b.subCommand, b.logger, b.config) +} + +// SetPersistentFlags sets persistent flags which should be used by all server (and client) +// commands. They control logging behavior and home directory. func SetPersistentFlags(pflags *pflag.FlagSet, defaultHome string) { pflags.String(FlagLogLevel, "info", "The logging level (trace|debug|info|warn|error|fatal|panic|disabled or '*:,:')") pflags.String(FlagLogFormat, "plain", "The logging format (json|plain)") @@ -32,7 +175,7 @@ func AddCommands[T transaction.Tx]( globalAppConfig server.ConfigMap, globalServerConfig ServerConfig, components ...ServerComponent[T], -) (interface{ WriteConfig(string) error }, error) { +) (WritesConfig, error) { if len(components) == 0 { return nil, errors.New("no components provided") } diff --git a/server/v2/server.go b/server/v2/server.go index 072d00f31d03..3a082aac61ac 100644 --- a/server/v2/server.go +++ b/server/v2/server.go @@ -37,6 +37,11 @@ type HasConfig interface { Config() any } +// WritesConfig is a server module that can write its config to a file. +type WritesConfig interface { + WriteConfig(path string) error +} + // HasCLICommands is a server module that has CLI commands. type HasCLICommands interface { CLICommands() CLIConfig diff --git a/simapp/v2/simdv2/cmd/commands.go b/simapp/v2/simdv2/cmd/commands.go index dbdf454587a0..02aa45753c27 100644 --- a/simapp/v2/simdv2/cmd/commands.go +++ b/simapp/v2/simdv2/cmd/commands.go @@ -31,10 +31,6 @@ import ( v2 "github.com/cosmos/cosmos-sdk/x/genutil/v2/cli" ) -type configWriter interface { - WriteConfig(filename string) error -} - // commandDependencies is a struct that contains all the dependencies needed to initialize the root command. // an alternative design could fetch these even later from the command context type commandDependencies[T transaction.Tx] struct { @@ -48,7 +44,7 @@ func initRootCmd[T transaction.Tx]( rootCmd *cobra.Command, logger log.Logger, deps commandDependencies[T], -) (configWriter, error) { +) (serverv2.WritesConfig, error) { cfg := sdk.GetConfig() cfg.Seal() @@ -57,10 +53,7 @@ func initRootCmd[T transaction.Tx]( debug.Cmd(), confixcmd.ConfigCommand(), NewTestnetCmd(deps.moduleManager), - ) - - // add keybase, auxiliary RPC, query, genesis, and tx child commands - rootCmd.AddCommand( + // add keybase, auxiliary RPC, query, genesis, and tx child commands genesisCommand(deps.moduleManager, deps.simApp), queryCommand(), txCommand(), diff --git a/simapp/v2/simdv2/cmd/root_di.go b/simapp/v2/simdv2/cmd/root_di.go index a9a0b6c55773..978810eaa9a1 100644 --- a/simapp/v2/simdv2/cmd/root_di.go +++ b/simapp/v2/simdv2/cmd/root_di.go @@ -1,16 +1,13 @@ package cmd import ( + "cosmossdk.io/core/server" "os" - "path/filepath" - "strings" "github.com/spf13/cobra" - "github.com/spf13/viper" autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" "cosmossdk.io/client/v2/autocli" - clientv2helpers "cosmossdk.io/client/v2/helpers" "cosmossdk.io/core/address" "cosmossdk.io/core/registry" "cosmossdk.io/core/transaction" @@ -30,75 +27,41 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/types" ) -func NewRootCmd[T transaction.Tx]( +func NewRootCmd( + commandFixture serverv2.CommandFixture, args ...string, ) (*cobra.Command, error) { - var ( - autoCliOpts autocli.AppOptions - moduleManager *runtime.MM[T] - clientCtx client.Context - ) - defaultHomeDir, err := clientv2helpers.DefaultHomeDir(".simappv2", clientv2helpers.EnvPrefix) + builder, err := serverv2.NewRootCmdBuilder(commandFixture, "simdv2", ".simappv2") if err != nil { return nil, err } + return builder.Build(args) +} - // initial bootstrap root command for config parsing - rootCmd := &cobra.Command{ - Use: "simdv2", - Short: "simulation app", - SilenceErrors: true, - } - serverv2.SetPersistentFlags(rootCmd.PersistentFlags(), defaultHomeDir) - // update the global viper with the root command's configuration - viper.SetEnvPrefix(clientv2helpers.EnvPrefix) - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_")) - viper.AutomaticEnv() - - srv, err := initRootCmd[T](rootCmd, log.NewNopLogger(), commandDependencies[T]{}) - if err != nil { - return nil, err - } - cmd, _, err := rootCmd.Traverse(args) - if cmd == nil || err != nil { - return rootCmd, nil - } - if err = cmd.ParseFlags(args); err != nil { - if err.Error() == "pflag: help requested" { - return cmd, nil - } - return nil, err - } - home, err := cmd.Flags().GetString(serverv2.FlagHome) - if err != nil { - return nil, err - } +type DefaultCommandFixture[T transaction.Tx] struct{} - configDir := filepath.Join(home, "config") - // create app.toml if it does not already exist - if _, err := os.Stat(filepath.Join(configDir, "app.toml")); os.IsNotExist(err) { - if err = srv.WriteConfig(configDir); err != nil { - return nil, err - } - } - vipr, err := serverv2.ReadConfig(configDir) - if err != nil { - return nil, err - } - if err := vipr.BindPFlags(cmd.Flags()); err != nil { - return nil, err - } - logger, err := serverv2.NewLogger(vipr, cmd.OutOrStdout()) - if err != nil { - return nil, err - } - globalConfig := vipr.AllSettings() +func (DefaultCommandFixture[T]) Bootstrap(cmd *cobra.Command) (serverv2.WritesConfig, error) { + return initRootCmd(cmd, log.NewNopLogger(), commandDependencies[T]{}) +} - var simApp *simapp.SimApp[T] - if needsApp(cmd) { +func (DefaultCommandFixture[T]) RootCommand( + rootCommand *cobra.Command, + subCommand *cobra.Command, + logger log.Logger, + configMap server.ConfigMap, +) (*cobra.Command, error) { + var ( + autoCliOpts autocli.AppOptions + moduleManager *runtime.MM[T] + clientCtx client.Context + simApp *simapp.SimApp[T] + err error + ) + if needsApp(subCommand) { + // server construction simApp, err = simapp.NewSimApp[T]( depinject.Configs( - depinject.Supply(logger, runtime.GlobalConfig(globalConfig)), + depinject.Supply(logger, runtime.GlobalConfig(configMap)), depinject.Provide(ProvideClientContext), ), &autoCliOpts, &moduleManager, &clientCtx) @@ -106,82 +69,66 @@ func NewRootCmd[T transaction.Tx]( return nil, err } } else { + // client construction if err = depinject.Inject( depinject.Configs( simapp.AppConfig(), - depinject.Provide( - ProvideClientContext, - ), + depinject.Provide(ProvideClientContext), depinject.Supply( logger, - runtime.GlobalConfig(globalConfig), + runtime.GlobalConfig(configMap), ), ), - &autoCliOpts, - &moduleManager, - &clientCtx, + &autoCliOpts, &moduleManager, &clientCtx, ); err != nil { return nil, err } } - // final root command - rootCmd = &cobra.Command{ - Use: "simdv2", - Short: "simulation app", - SilenceErrors: true, - PersistentPreRunE: func(cmd *cobra.Command, args []string) error { - // set the default command outputs - cmd.SetOut(cmd.OutOrStdout()) - cmd.SetErr(cmd.ErrOrStderr()) - - clientCtx = clientCtx.WithCmdContext(cmd.Context()) - clientCtx, err = client.ReadPersistentCommandFlags(clientCtx, cmd.Flags()) - if err != nil { - return err - } - - customClientTemplate, customClientConfig := initClientConfig() - clientCtx, err = config.CreateClientConfig( - clientCtx, customClientTemplate, customClientConfig) - if err != nil { - return err - } - - if err = client.SetCmdClientContextHandler(clientCtx, cmd); err != nil { - return err - } - - return nil - }, - } - // TODO push down to server subcommands only - // but also audit the usage of logger and viper in fetching from context, probably no - // longer needed. - serverv2.SetPersistentFlags(rootCmd.PersistentFlags(), defaultHomeDir) - err = serverv2.SetCmdServerContext(rootCmd, vipr, logger) - if err != nil { - return nil, err + rootCommand.Short = "simulation app" + rootCommand.PersistentPreRunE = func(cmd *cobra.Command, args []string) error { + // set the default command outputs + cmd.SetOut(cmd.OutOrStdout()) + cmd.SetErr(cmd.ErrOrStderr()) + + clientCtx = clientCtx.WithCmdContext(cmd.Context()) + clientCtx, err = client.ReadPersistentCommandFlags(clientCtx, cmd.Flags()) + if err != nil { + return err + } + + customClientTemplate, customClientConfig := initClientConfig() + clientCtx, err = config.CreateClientConfig( + clientCtx, customClientTemplate, customClientConfig) + if err != nil { + return err + } + + if err = client.SetCmdClientContextHandler(clientCtx, cmd); err != nil { + return err + } + + return nil } commandDeps := commandDependencies[T]{ - globalAppConfig: globalConfig, + globalAppConfig: configMap, txConfig: clientCtx.TxConfig, moduleManager: moduleManager, simApp: simApp, } - _, err = initRootCmd[T](rootCmd, logger, commandDeps) + _, err = initRootCmd[T](rootCommand, logger, commandDeps) if err != nil { return nil, err } nodeCmds := nodeservice.NewNodeCommands() autoCliOpts.ModuleOptions = make(map[string]*autocliv1.ModuleOptions) autoCliOpts.ModuleOptions[nodeCmds.Name()] = nodeCmds.AutoCLIOptions() - if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil { + if err := autoCliOpts.EnhanceRootCommand(rootCommand); err != nil { return nil, err } - return rootCmd, nil + return rootCommand, nil } func ProvideClientContext( @@ -194,7 +141,6 @@ func ProvideClientContext( consensusAddressCodec address.ConsensusAddressCodec, ) client.Context { var err error - amino, ok := legacyAmino.(*codec.LegacyAmino) if !ok { panic("registry.AminoRegistrar must be an *codec.LegacyAmino instance for legacy ClientContext") diff --git a/simapp/v2/simdv2/main.go b/simapp/v2/simdv2/main.go index d01a45030cb9..85fc8c85c7b9 100644 --- a/simapp/v2/simdv2/main.go +++ b/simapp/v2/simdv2/main.go @@ -13,7 +13,8 @@ func main() { // reproduce default cobra behavior so that eager parsing of flags is possible. // see: https://github.com/spf13/cobra/blob/e94f6d0dd9a5e5738dca6bce03c4b1207ffbc0ec/command.go#L1082 args := os.Args[1:] - rootCmd, err := cmd.NewRootCmd[transaction.Tx](args...) + fixture := cmd.DefaultCommandFixture[transaction.Tx]{} + rootCmd, err := cmd.NewRootCmd(fixture, args...) if err != nil { if _, pErr := fmt.Fprintln(os.Stderr, err); pErr != nil { panic(errors.Join(err, pErr)) From 40bfd6b1b518387384005bea38d32844fe5eb623 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 24 Oct 2024 17:20:37 -0500 Subject: [PATCH 21/46] demo consensus override --- runtime/v2/app.go | 2 +- simapp/v2/simdv2/cmd/commands.go | 63 +++++++------ simapp/v2/simdv2/cmd/root_consensus.go | 123 +++++++++++++++++++++++++ simapp/v2/simdv2/cmd/root_di.go | 4 +- simapp/v2/simdv2/cmd/root_test.go | 6 +- simapp/v2/simdv2/cmd/testnet_test.go | 3 +- x/genutil/v2/cli/commands.go | 6 +- x/genutil/v2/cli/export.go | 2 +- 8 files changed, 171 insertions(+), 38 deletions(-) create mode 100644 simapp/v2/simdv2/cmd/root_consensus.go diff --git a/runtime/v2/app.go b/runtime/v2/app.go index b7887ab77f54..0c017fdcbcd9 100644 --- a/runtime/v2/app.go +++ b/runtime/v2/app.go @@ -83,7 +83,7 @@ func (a *App[T]) LoadLatestHeight() (uint64, error) { return a.db.GetLatestVersion() } -// GetQueryHandlers returns the query handlers. +// QueryHandlers returns the query handlers. func (a *App[T]) QueryHandlers() map[string]appmodulev2.Handler { return a.queryHandlers } diff --git a/simapp/v2/simdv2/cmd/commands.go b/simapp/v2/simdv2/cmd/commands.go index 02aa45753c27..69df1f6e0d82 100644 --- a/simapp/v2/simdv2/cmd/commands.go +++ b/simapp/v2/simdv2/cmd/commands.go @@ -34,10 +34,11 @@ import ( // commandDependencies is a struct that contains all the dependencies needed to initialize the root command. // an alternative design could fetch these even later from the command context type commandDependencies[T transaction.Tx] struct { - globalAppConfig coreserver.ConfigMap - txConfig client.TxConfig - moduleManager *runtimev2.MM[T] - simApp *simapp.SimApp[T] + globalAppConfig coreserver.ConfigMap + txConfig client.TxConfig + moduleManager *runtimev2.MM[T] + simApp *simapp.SimApp[T] + consensusComponent serverv2.ServerComponent[T] } func initRootCmd[T transaction.Tx]( @@ -63,41 +64,25 @@ func initRootCmd[T transaction.Tx]( // build CLI skeleton for initial config parsing or a client application invocation if deps.simApp == nil { - comet := &cometbft.CometBFTServer[T]{} - comet = comet.WithConfigOptions(initCometConfig()) + if deps.consensusComponent == nil { + comet := &cometbft.CometBFTServer[T]{} + deps.consensusComponent = comet.WithConfigOptions(initCometConfig()) + } return serverv2.AddCommands[T]( rootCmd, logger, deps.globalAppConfig, initServerConfig(), - comet, + deps.consensusComponent, &grpc.Server[T]{}, &serverstore.Server[T]{}, &telemetry.Server[T]{}, &rest.Server[T]{}, ) } - simApp := deps.simApp + // build full app! - cometBftServer, err := cometbft.New( - logger, - // TODO use depinject outputs not app - simApp.Name(), - simApp.Store(), - simApp.App.AppManager, - simApp.App.QueryHandlers(), - simApp.App.SchemaDecoderResolver(), - &genericTxDecoder[T]{deps.txConfig}, - deps.globalAppConfig, - initCometOptions[T](), - ) - if err != nil { - return nil, err - } - telemetryServer, err := telemetry.New[T](deps.globalAppConfig, logger) - if err != nil { - return nil, err - } + simApp := deps.simApp grpcServer, err := grpc.New[T](logger, simApp.InterfaceRegistry(), simApp.QueryHandlers(), simApp, deps.globalAppConfig) if err != nil { return nil, err @@ -112,13 +97,35 @@ func initRootCmd[T transaction.Tx]( return nil, err } + // consensus component + if deps.consensusComponent == nil { + deps.consensusComponent, err = cometbft.New( + logger, + simApp.Name(), + simApp.Store(), + simApp.App.AppManager, + simApp.App.QueryHandlers(), + simApp.App.SchemaDecoderResolver(), + &genericTxDecoder[T]{deps.txConfig}, + deps.globalAppConfig, + initCometOptions[T](), + ) + if err != nil { + return nil, err + } + } + telemetryServer, err := telemetry.New[T](deps.globalAppConfig, logger) + if err != nil { + return nil, err + } + // wire server commands return serverv2.AddCommands[T]( rootCmd, logger, deps.globalAppConfig, initServerConfig(), - cometBftServer, + deps.consensusComponent, grpcServer, storeComponent, telemetryServer, diff --git a/simapp/v2/simdv2/cmd/root_consensus.go b/simapp/v2/simdv2/cmd/root_consensus.go new file mode 100644 index 000000000000..6ac991f1c9ed --- /dev/null +++ b/simapp/v2/simdv2/cmd/root_consensus.go @@ -0,0 +1,123 @@ +package cmd + +import ( + "github.com/spf13/cobra" + + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + "cosmossdk.io/client/v2/autocli" + "cosmossdk.io/core/server" + "cosmossdk.io/core/transaction" + "cosmossdk.io/depinject" + "cosmossdk.io/log" + "cosmossdk.io/runtime/v2" + serverv2 "cosmossdk.io/server/v2" + "cosmossdk.io/simapp/v2" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/config" + nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" +) + +// AlternateConsensusFixture is a custom implementation of the CommandFixture interface +// which demonstrates how an app developer can customize the root command initialization. +// In this case a different consensus assummed but not implemented. +type AlternateConsensusFixture[T transaction.Tx] struct{} + +func (AlternateConsensusFixture[T]) Bootstrap(cmd *cobra.Command) (serverv2.WritesConfig, error) { + // create your custom consensus component here + var consensusComponent serverv2.ServerComponent[T] + return initRootCmd(cmd, log.NewNopLogger(), commandDependencies[T]{ + consensusComponent: consensusComponent, + }) +} + +func (AlternateConsensusFixture[T]) RootCommand( + rootCommand *cobra.Command, + subCommand *cobra.Command, + logger log.Logger, + configMap server.ConfigMap, +) (*cobra.Command, error) { + var ( + autoCliOpts autocli.AppOptions + moduleManager *runtime.MM[T] + clientCtx client.Context + simApp *simapp.SimApp[T] + err error + consensusComponent serverv2.ServerComponent[T] + ) + if needsApp(subCommand) { + // server construction + simApp, err = simapp.NewSimApp[T]( + depinject.Configs( + depinject.Supply(logger, runtime.GlobalConfig(configMap)), + depinject.Provide(ProvideClientContext), + ), + &autoCliOpts, &moduleManager, &clientCtx) + if err != nil { + return nil, err + } + // initialize your custom consensus component here with outputs now available from DI + consensusComponent = nil + } else { + // client construction + if err = depinject.Inject( + depinject.Configs( + simapp.AppConfig(), + depinject.Provide(ProvideClientContext), + depinject.Supply( + logger, + runtime.GlobalConfig(configMap), + ), + ), + &autoCliOpts, &moduleManager, &clientCtx, + ); err != nil { + return nil, err + } + } + + rootCommand.Short = "simulation app" + rootCommand.PersistentPreRunE = func(cmd *cobra.Command, args []string) error { + // set the default command outputs + cmd.SetOut(cmd.OutOrStdout()) + cmd.SetErr(cmd.ErrOrStderr()) + + clientCtx = clientCtx.WithCmdContext(cmd.Context()) + clientCtx, err = client.ReadPersistentCommandFlags(clientCtx, cmd.Flags()) + if err != nil { + return err + } + + customClientTemplate, customClientConfig := initClientConfig() + clientCtx, err = config.CreateClientConfig( + clientCtx, customClientTemplate, customClientConfig) + if err != nil { + return err + } + + if err = client.SetCmdClientContextHandler(clientCtx, cmd); err != nil { + return err + } + + return nil + } + + commandDeps := commandDependencies[T]{ + globalAppConfig: configMap, + txConfig: clientCtx.TxConfig, + moduleManager: moduleManager, + simApp: simApp, + consensusComponent: consensusComponent, + } + _, err = initRootCmd(rootCommand, logger, commandDeps) + if err != nil { + return nil, err + } + nodeCmds := nodeservice.NewNodeCommands() + autoCliOpts.ModuleOptions = make(map[string]*autocliv1.ModuleOptions) + autoCliOpts.ModuleOptions[nodeCmds.Name()] = nodeCmds.AutoCLIOptions() + if err := autoCliOpts.EnhanceRootCommand(rootCommand); err != nil { + return nil, err + } + + return rootCommand, nil +} diff --git a/simapp/v2/simdv2/cmd/root_di.go b/simapp/v2/simdv2/cmd/root_di.go index 978810eaa9a1..74dc4504583c 100644 --- a/simapp/v2/simdv2/cmd/root_di.go +++ b/simapp/v2/simdv2/cmd/root_di.go @@ -1,7 +1,6 @@ package cmd import ( - "cosmossdk.io/core/server" "os" "github.com/spf13/cobra" @@ -10,6 +9,7 @@ import ( "cosmossdk.io/client/v2/autocli" "cosmossdk.io/core/address" "cosmossdk.io/core/registry" + "cosmossdk.io/core/server" "cosmossdk.io/core/transaction" "cosmossdk.io/depinject" "cosmossdk.io/log" @@ -117,7 +117,7 @@ func (DefaultCommandFixture[T]) RootCommand( moduleManager: moduleManager, simApp: simApp, } - _, err = initRootCmd[T](rootCommand, logger, commandDeps) + _, err = initRootCmd(rootCommand, logger, commandDeps) if err != nil { return nil, err } diff --git a/simapp/v2/simdv2/cmd/root_test.go b/simapp/v2/simdv2/cmd/root_test.go index 7f7d6a07d95a..a6833f504e11 100644 --- a/simapp/v2/simdv2/cmd/root_test.go +++ b/simapp/v2/simdv2/cmd/root_test.go @@ -19,7 +19,8 @@ func TestInitCmd(t *testing.T) { "simapp-test", // Moniker fmt.Sprintf("--%s=%s", cli.FlagOverwrite, "true"), // Overwrite genesis.json, in case it already exists } - rootCmd, err := cmd.NewRootCmd[transaction.Tx](args...) + fixture := cmd.DefaultCommandFixture[transaction.Tx]{} + rootCmd, err := cmd.NewRootCmd(fixture, args...) require.NoError(t, err) rootCmd.SetArgs(args) require.NoError(t, rootCmd.Execute()) @@ -33,7 +34,8 @@ func TestHomeFlagRegistration(t *testing.T) { homeDir, } - rootCmd, err := cmd.NewRootCmd[transaction.Tx](args...) + fixture := cmd.DefaultCommandFixture[transaction.Tx]{} + rootCmd, err := cmd.NewRootCmd(fixture, args...) require.NoError(t, err) rootCmd.SetArgs(args) require.NoError(t, rootCmd.Execute()) diff --git a/simapp/v2/simdv2/cmd/testnet_test.go b/simapp/v2/simdv2/cmd/testnet_test.go index acf57dd37b80..fff87ec58855 100644 --- a/simapp/v2/simdv2/cmd/testnet_test.go +++ b/simapp/v2/simdv2/cmd/testnet_test.go @@ -19,7 +19,8 @@ func TestInitTestFilesCmd(t *testing.T) { "init-files", fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest), // Set keyring-backend to test } - rootCmd, err := cmd.NewRootCmd[transaction.Tx](args...) + fixture := cmd.DefaultCommandFixture[transaction.Tx]{} + rootCmd, err := cmd.NewRootCmd(fixture, args...) require.NoError(t, err) rootCmd.SetArgs(args) require.NoError(t, rootCmd.Execute()) diff --git a/x/genutil/v2/cli/commands.go b/x/genutil/v2/cli/commands.go index f1fbff92c413..6812345d23ba 100644 --- a/x/genutil/v2/cli/commands.go +++ b/x/genutil/v2/cli/commands.go @@ -19,7 +19,7 @@ type genesisMM interface { ValidateGenesis(genesisData map[string]json.RawMessage) error } -type exportableApp interface { +type ExportableApp interface { ExportAppStateAndValidators([]string) (v2.ExportedApp, error) LoadHeight(uint64) error } @@ -28,7 +28,7 @@ type exportableApp interface { func Commands( genTxValidator func([]transaction.Msg) error, genMM genesisMM, - exportable exportableApp, + exportable ExportableApp, ) *cobra.Command { return CommandsWithCustomMigrationMap(genTxValidator, genMM, exportable, cli.MigrationMap) } @@ -38,7 +38,7 @@ func Commands( func CommandsWithCustomMigrationMap( genTxValidator func([]transaction.Msg) error, genMM genesisMM, - exportable exportableApp, + exportable ExportableApp, migrationMap genutiltypes.MigrationMap, ) *cobra.Command { cmd := &cobra.Command{ diff --git a/x/genutil/v2/cli/export.go b/x/genutil/v2/cli/export.go index 390e8e1390dd..50a7adf90834 100644 --- a/x/genutil/v2/cli/export.go +++ b/x/genutil/v2/cli/export.go @@ -21,7 +21,7 @@ const ( ) // ExportCmd dumps app state to JSON. -func ExportCmd(app exportableApp) *cobra.Command { +func ExportCmd(app ExportableApp) *cobra.Command { cmd := &cobra.Command{ Use: "export", Short: "Export state to JSON", From 68f543f9067bad1fd85706da731ecddd0ecea84c Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 24 Oct 2024 17:22:39 -0500 Subject: [PATCH 22/46] changelog --- core/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index c234cc971948..62460682a648 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -36,6 +36,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Features + +* [*22267](https://github.com/cosmos/cosmos-sdk/pull/22267) Add `server.ConfigMap` and `server.ModuleConfigMap` to replace `server.DynamicConfig` in module configuration. + ## [v1.0.0-alpha.3](https://github.com/cosmos/cosmos-sdk/releases/tag/core%2Fv1.0.0-alpha.3) ### Features From bb95533583823451a799bebae7c94ae8c13d73d7 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 24 Oct 2024 17:36:36 -0500 Subject: [PATCH 23/46] fix --- server/v2/commands.go | 36 ++++++++++++------------------------ x/genutil/v2/cli/export.go | 1 - 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/server/v2/commands.go b/server/v2/commands.go index 7dbf72145b4c..7ae8bc49c065 100644 --- a/server/v2/commands.go +++ b/server/v2/commands.go @@ -23,12 +23,10 @@ type RootCmdBuilder struct { DefaultHome string EnvPrefix string - use string - fixture CommandFixture - vipr *viper.Viper - logger log.Logger - subCommand *cobra.Command - config server.ConfigMap + use string + fixture CommandFixture + vipr *viper.Viper + logger log.Logger } type CommandFixture interface { @@ -58,18 +56,6 @@ func NewRootCmdBuilder( return f, nil } -func (b *RootCmdBuilder) Logger() log.Logger { - return b.logger -} - -func (b *RootCmdBuilder) SubCommand() *cobra.Command { - return b.subCommand -} - -func (b *RootCmdBuilder) Config() server.ConfigMap { - return b.config -} - func (b *RootCmdBuilder) DefaultHomeDir(name string) (string, error) { // get the home directory from the environment variable // to not clash with the $HOME system variable, when no prefix is set @@ -112,15 +98,15 @@ func (b *RootCmdBuilder) Command() (*cobra.Command, error) { func (b *RootCmdBuilder) Build( args []string, ) (*cobra.Command, error) { - cmd, err := b.Command() + bootstrapCmd, err := b.Command() if err != nil { return nil, err } - configWriter, err := b.fixture.Bootstrap(cmd) + configWriter, err := b.fixture.Bootstrap(bootstrapCmd) if err != nil { return nil, err } - b.subCommand, _, err = cmd.Traverse(args) + cmd, _, err := bootstrapCmd.Traverse(args) if err != nil { return nil, err } @@ -153,9 +139,11 @@ func (b *RootCmdBuilder) Build( if err != nil { return nil, err } - b.config = b.vipr.AllSettings() - - return b.fixture.RootCommand(cmd, b.subCommand, b.logger, b.config) + rootCmd, err := b.Command() + if err != nil { + return nil, err + } + return b.fixture.RootCommand(rootCmd, cmd, b.logger, b.vipr.AllSettings()) } // SetPersistentFlags sets persistent flags which should be used by all server (and client) diff --git a/x/genutil/v2/cli/export.go b/x/genutil/v2/cli/export.go index 50a7adf90834..7802b062bf1e 100644 --- a/x/genutil/v2/cli/export.go +++ b/x/genutil/v2/cli/export.go @@ -59,7 +59,6 @@ func ExportCmd(app ExportableApp) *cobra.Command { height, _ := cmd.Flags().GetInt64(flagHeight) jailAllowedAddrs, _ := cmd.Flags().GetStringSlice(flagJailAllowedAddrs) outputDocument, _ := cmd.Flags().GetString(flags.FlagOutputDocument) - fmt.Printf("height: %d\n", height) if height != -1 { if err := app.LoadHeight(uint64(height)); err != nil { return err From 0f79666e505b450d7334f106d99d36a366cc02ac Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 24 Oct 2024 20:56:33 -0500 Subject: [PATCH 24/46] clean up --- server/v2/cometbft/server.go | 2 - simapp/v2/simdv2/cmd/commands.go | 28 ++++++++ simapp/v2/simdv2/cmd/config.go | 34 ++++++++++ simapp/v2/simdv2/cmd/depinject.go | 63 ++++++++++++++++++ simapp/v2/simdv2/cmd/root_consensus.go | 34 ++-------- simapp/v2/simdv2/cmd/root_di.go | 92 +------------------------- 6 files changed, 132 insertions(+), 121 deletions(-) create mode 100644 simapp/v2/simdv2/cmd/depinject.go diff --git a/server/v2/cometbft/server.go b/server/v2/cometbft/server.go index 4e5cb4bd855b..3ab3cabbb13f 100644 --- a/server/v2/cometbft/server.go +++ b/server/v2/cometbft/server.go @@ -158,8 +158,6 @@ func New[T transaction.Tx]( consensus.listener = &listener.Listener } - srv.Consensus = consensus - return srv, nil } diff --git a/simapp/v2/simdv2/cmd/commands.go b/simapp/v2/simdv2/cmd/commands.go index 69df1f6e0d82..e47d80720fcb 100644 --- a/simapp/v2/simdv2/cmd/commands.go +++ b/simapp/v2/simdv2/cmd/commands.go @@ -20,6 +20,7 @@ import ( confixcmd "cosmossdk.io/tools/confix/cmd" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/config" "github.com/cosmos/cosmos-sdk/client/debug" "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/client/rpc" @@ -194,6 +195,33 @@ func txCommand() *cobra.Command { return cmd } +func rootCommandPersistentPreRun(clientCtx client.Context) func(*cobra.Command, []string) error { + return func(cmd *cobra.Command, args []string) error { + // set the default command outputs + cmd.SetOut(cmd.OutOrStdout()) + cmd.SetErr(cmd.ErrOrStderr()) + + clientCtx = clientCtx.WithCmdContext(cmd.Context()) + clientCtx, err := client.ReadPersistentCommandFlags(clientCtx, cmd.Flags()) + if err != nil { + return err + } + + customClientTemplate, customClientConfig := initClientConfig() + clientCtx, err = config.CreateClientConfig( + clientCtx, customClientTemplate, customClientConfig) + if err != nil { + return err + } + + if err = client.SetCmdClientContextHandler(clientCtx, cmd); err != nil { + return err + } + + return nil + } +} + var _ transaction.Codec[transaction.Tx] = &genericTxDecoder[transaction.Tx]{} type genericTxDecoder[T transaction.Tx] struct { diff --git a/simapp/v2/simdv2/cmd/config.go b/simapp/v2/simdv2/cmd/config.go index 16cb19db93e7..034bb2540a23 100644 --- a/simapp/v2/simdv2/cmd/config.go +++ b/simapp/v2/simdv2/cmd/config.go @@ -1,10 +1,12 @@ package cmd import ( + "slices" "strings" "time" cmtcfg "github.com/cometbft/cometbft/config" + "github.com/spf13/cobra" "cosmossdk.io/core/transaction" serverv2 "cosmossdk.io/server/v2" @@ -104,3 +106,35 @@ func initCometOptions[T transaction.Tx]() cometbft.ServerOptions[T] { return serverOptions } + +// appBuildingCommands are the commands which need a full SimApp to be built +var appBuildingCommands = [][]string{ + {"start"}, + {"genesis", "export"}, +} + +// isAppRequired returns true if the command requires a full app to be built +// by recursively checking the command and its parents, and comparing it with +// the appBuildingCommands. +func isAppRequired(cmd *cobra.Command) bool { + m := map[string]bool{} + for _, c := range appBuildingCommands { + slices.Reverse(c) + var k string + for _, sc := range c { + k += sc + } + m[k] = true + } + var use string + for { + use += cmd.Use + if _, ok := m[use]; ok { + return true + } + if cmd.Parent() == nil { + return false + } + cmd = cmd.Parent() + } +} diff --git a/simapp/v2/simdv2/cmd/depinject.go b/simapp/v2/simdv2/cmd/depinject.go new file mode 100644 index 000000000000..a59c7f1fc2ef --- /dev/null +++ b/simapp/v2/simdv2/cmd/depinject.go @@ -0,0 +1,63 @@ +package cmd + +import ( + "os" + + "cosmossdk.io/core/address" + "cosmossdk.io/core/registry" + "cosmossdk.io/simapp/v2" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/config" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/x/auth/tx" + authtxconfig "github.com/cosmos/cosmos-sdk/x/auth/tx/config" + "github.com/cosmos/cosmos-sdk/x/auth/types" +) + +// ProvideClientContext is a depinject Provider function which assembles and returns a client.Context. +func ProvideClientContext( + appCodec codec.Codec, + interfaceRegistry codectypes.InterfaceRegistry, + txConfigOpts tx.ConfigOptions, + legacyAmino registry.AminoRegistrar, + addressCodec address.Codec, + validatorAddressCodec address.ValidatorAddressCodec, + consensusAddressCodec address.ConsensusAddressCodec, +) client.Context { + var err error + amino, ok := legacyAmino.(*codec.LegacyAmino) + if !ok { + panic("registry.AminoRegistrar must be an *codec.LegacyAmino instance for legacy ClientContext") + } + + clientCtx := client.Context{}. + WithCodec(appCodec). + WithInterfaceRegistry(interfaceRegistry). + WithLegacyAmino(amino). + WithInput(os.Stdin). + WithAccountRetriever(types.AccountRetriever{}). + WithAddressCodec(addressCodec). + WithValidatorAddressCodec(validatorAddressCodec). + WithConsensusAddressCodec(consensusAddressCodec). + WithHomeDir(simapp.DefaultNodeHome). + WithViper("") // uses by default the binary name as prefix + + // Read the config to overwrite the default values with the values from the config file + customClientTemplate, customClientConfig := initClientConfig() + clientCtx, err = config.CreateClientConfig(clientCtx, customClientTemplate, customClientConfig) + if err != nil { + panic(err) + } + + // textual is enabled by default, we need to re-create the tx config grpc instead of bank keeper. + txConfigOpts.TextualCoinMetadataQueryFn = authtxconfig.NewGRPCCoinMetadataQueryFn(clientCtx) + txConfig, err := tx.NewTxConfigWithOptions(clientCtx.Codec, txConfigOpts) + if err != nil { + panic(err) + } + clientCtx = clientCtx.WithTxConfig(txConfig) + + return clientCtx +} diff --git a/simapp/v2/simdv2/cmd/root_consensus.go b/simapp/v2/simdv2/cmd/root_consensus.go index 6ac991f1c9ed..ccb5b74040e0 100644 --- a/simapp/v2/simdv2/cmd/root_consensus.go +++ b/simapp/v2/simdv2/cmd/root_consensus.go @@ -14,17 +14,16 @@ import ( "cosmossdk.io/simapp/v2" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/config" nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" ) // AlternateConsensusFixture is a custom implementation of the CommandFixture interface // which demonstrates how an app developer can customize the root command initialization. -// In this case a different consensus assummed but not implemented. +// In this case a different consensus is assummed but not implemented. type AlternateConsensusFixture[T transaction.Tx] struct{} func (AlternateConsensusFixture[T]) Bootstrap(cmd *cobra.Command) (serverv2.WritesConfig, error) { - // create your custom consensus component here + // create your custom consensus component here for config parsing and initialization var consensusComponent serverv2.ServerComponent[T] return initRootCmd(cmd, log.NewNopLogger(), commandDependencies[T]{ consensusComponent: consensusComponent, @@ -45,7 +44,7 @@ func (AlternateConsensusFixture[T]) RootCommand( err error consensusComponent serverv2.ServerComponent[T] ) - if needsApp(subCommand) { + if isAppRequired(subCommand) { // server construction simApp, err = simapp.NewSimApp[T]( depinject.Configs( @@ -56,7 +55,7 @@ func (AlternateConsensusFixture[T]) RootCommand( if err != nil { return nil, err } - // initialize your custom consensus component here with outputs now available from DI + // create your custom consensus component here with outputs now available from DI consensusComponent = nil } else { // client construction @@ -76,30 +75,7 @@ func (AlternateConsensusFixture[T]) RootCommand( } rootCommand.Short = "simulation app" - rootCommand.PersistentPreRunE = func(cmd *cobra.Command, args []string) error { - // set the default command outputs - cmd.SetOut(cmd.OutOrStdout()) - cmd.SetErr(cmd.ErrOrStderr()) - - clientCtx = clientCtx.WithCmdContext(cmd.Context()) - clientCtx, err = client.ReadPersistentCommandFlags(clientCtx, cmd.Flags()) - if err != nil { - return err - } - - customClientTemplate, customClientConfig := initClientConfig() - clientCtx, err = config.CreateClientConfig( - clientCtx, customClientTemplate, customClientConfig) - if err != nil { - return err - } - - if err = client.SetCmdClientContextHandler(clientCtx, cmd); err != nil { - return err - } - - return nil - } + rootCommand.PersistentPreRunE = rootCommandPersistentPreRun(clientCtx) commandDeps := commandDependencies[T]{ globalAppConfig: configMap, diff --git a/simapp/v2/simdv2/cmd/root_di.go b/simapp/v2/simdv2/cmd/root_di.go index 74dc4504583c..1d0901127ff7 100644 --- a/simapp/v2/simdv2/cmd/root_di.go +++ b/simapp/v2/simdv2/cmd/root_di.go @@ -1,14 +1,10 @@ package cmd import ( - "os" - "github.com/spf13/cobra" autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" "cosmossdk.io/client/v2/autocli" - "cosmossdk.io/core/address" - "cosmossdk.io/core/registry" "cosmossdk.io/core/server" "cosmossdk.io/core/transaction" "cosmossdk.io/depinject" @@ -18,13 +14,7 @@ import ( "cosmossdk.io/simapp/v2" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/config" nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/x/auth/tx" - authtxconfig "github.com/cosmos/cosmos-sdk/x/auth/tx/config" - "github.com/cosmos/cosmos-sdk/x/auth/types" ) func NewRootCmd( @@ -57,7 +47,7 @@ func (DefaultCommandFixture[T]) RootCommand( simApp *simapp.SimApp[T] err error ) - if needsApp(subCommand) { + if isAppRequired(subCommand) { // server construction simApp, err = simapp.NewSimApp[T]( depinject.Configs( @@ -86,30 +76,7 @@ func (DefaultCommandFixture[T]) RootCommand( } rootCommand.Short = "simulation app" - rootCommand.PersistentPreRunE = func(cmd *cobra.Command, args []string) error { - // set the default command outputs - cmd.SetOut(cmd.OutOrStdout()) - cmd.SetErr(cmd.ErrOrStderr()) - - clientCtx = clientCtx.WithCmdContext(cmd.Context()) - clientCtx, err = client.ReadPersistentCommandFlags(clientCtx, cmd.Flags()) - if err != nil { - return err - } - - customClientTemplate, customClientConfig := initClientConfig() - clientCtx, err = config.CreateClientConfig( - clientCtx, customClientTemplate, customClientConfig) - if err != nil { - return err - } - - if err = client.SetCmdClientContextHandler(clientCtx, cmd); err != nil { - return err - } - - return nil - } + rootCommand.PersistentPreRunE = rootCommandPersistentPreRun(clientCtx) commandDeps := commandDependencies[T]{ globalAppConfig: configMap, @@ -130,58 +97,3 @@ func (DefaultCommandFixture[T]) RootCommand( return rootCommand, nil } - -func ProvideClientContext( - appCodec codec.Codec, - interfaceRegistry codectypes.InterfaceRegistry, - txConfigOpts tx.ConfigOptions, - legacyAmino registry.AminoRegistrar, - addressCodec address.Codec, - validatorAddressCodec address.ValidatorAddressCodec, - consensusAddressCodec address.ConsensusAddressCodec, -) client.Context { - var err error - amino, ok := legacyAmino.(*codec.LegacyAmino) - if !ok { - panic("registry.AminoRegistrar must be an *codec.LegacyAmino instance for legacy ClientContext") - } - - clientCtx := client.Context{}. - WithCodec(appCodec). - WithInterfaceRegistry(interfaceRegistry). - WithLegacyAmino(amino). - WithInput(os.Stdin). - WithAccountRetriever(types.AccountRetriever{}). - WithAddressCodec(addressCodec). - WithValidatorAddressCodec(validatorAddressCodec). - WithConsensusAddressCodec(consensusAddressCodec). - WithHomeDir(simapp.DefaultNodeHome). - WithViper("") // uses by default the binary name as prefix - - // Read the config to overwrite the default values with the values from the config file - customClientTemplate, customClientConfig := initClientConfig() - clientCtx, err = config.CreateClientConfig(clientCtx, customClientTemplate, customClientConfig) - if err != nil { - panic(err) - } - - // textual is enabled by default, we need to re-create the tx config grpc instead of bank keeper. - txConfigOpts.TextualCoinMetadataQueryFn = authtxconfig.NewGRPCCoinMetadataQueryFn(clientCtx) - txConfig, err := tx.NewTxConfigWithOptions(clientCtx.Codec, txConfigOpts) - if err != nil { - panic(err) - } - clientCtx = clientCtx.WithTxConfig(txConfig) - - return clientCtx -} - -func needsApp(cmd *cobra.Command) bool { - if cmd.Annotations["needs-app"] == "true" { - return true - } - if cmd.Parent() == nil { - return false - } - return needsApp(cmd.Parent()) -} From dcc3ddc1b2089f55ec56204620b772c4ba60f424 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Fri, 25 Oct 2024 09:58:13 -0500 Subject: [PATCH 25/46] rm core replaces --- client/v2/go.mod | 3 +-- client/v2/go.sum | 2 ++ collections/go.mod | 2 +- collections/go.sum | 4 ++-- core/testing/go.mod | 2 +- core/testing/go.sum | 4 ++-- go.mod | 3 +-- go.sum | 2 ++ runtime/v2/go.mod | 3 +-- runtime/v2/go.sum | 2 ++ server/v2/appmanager/go.mod | 2 +- server/v2/appmanager/go.sum | 4 ++-- server/v2/cometbft/go.mod | 3 +-- server/v2/cometbft/go.sum | 2 ++ server/v2/go.mod | 3 +-- server/v2/go.sum | 2 ++ server/v2/stf/go.mod | 2 +- server/v2/stf/go.sum | 4 ++-- simapp/go.mod | 3 +-- simapp/go.sum | 2 ++ simapp/v2/go.mod | 3 +-- simapp/v2/go.sum | 2 ++ store/go.mod | 2 +- store/go.sum | 4 ++-- tests/go.mod | 3 +-- tests/go.sum | 2 ++ x/accounts/defaults/base/go.mod | 3 +-- x/accounts/defaults/base/go.sum | 2 ++ x/accounts/defaults/lockup/go.mod | 2 +- x/accounts/defaults/lockup/go.sum | 4 ++-- x/accounts/defaults/multisig/go.mod | 3 +-- x/accounts/defaults/multisig/go.sum | 2 ++ x/accounts/go.mod | 3 +-- x/accounts/go.sum | 2 ++ x/authz/go.mod | 3 +-- x/authz/go.sum | 2 ++ x/bank/go.mod | 3 +-- x/bank/go.sum | 2 ++ x/circuit/go.mod | 3 +-- x/circuit/go.sum | 2 ++ x/consensus/go.mod | 3 +-- x/consensus/go.sum | 2 ++ x/distribution/go.mod | 3 +-- x/distribution/go.sum | 2 ++ x/epochs/go.mod | 3 +-- x/epochs/go.sum | 2 ++ x/evidence/go.mod | 3 +-- x/evidence/go.sum | 2 ++ x/feegrant/go.mod | 3 +-- x/feegrant/go.sum | 2 ++ x/gov/go.mod | 3 +-- x/gov/go.sum | 2 ++ x/group/go.mod | 3 +-- x/group/go.sum | 2 ++ x/mint/go.mod | 3 +-- x/mint/go.sum | 2 ++ x/nft/go.mod | 3 +-- x/nft/go.sum | 2 ++ x/params/go.mod | 2 +- x/params/go.sum | 4 ++-- x/protocolpool/go.mod | 3 +-- x/protocolpool/go.sum | 2 ++ x/slashing/go.mod | 3 +-- x/slashing/go.sum | 2 ++ x/staking/go.mod | 3 +-- x/staking/go.sum | 2 ++ x/upgrade/go.mod | 3 +-- x/upgrade/go.sum | 2 ++ 68 files changed, 102 insertions(+), 75 deletions(-) diff --git a/client/v2/go.mod b/client/v2/go.mod index 66456567e284..fca170c7e15f 100644 --- a/client/v2/go.mod +++ b/client/v2/go.mod @@ -4,7 +4,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/depinject v1.0.0 cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 cosmossdk.io/x/gov v0.0.0-20231113122742-912390d5fc4a @@ -175,7 +175,6 @@ replace github.com/cosmos/cosmos-sdk => ./../../ // TODO remove post spinning out all modules replace ( cosmossdk.io/api => ./../../api - cosmossdk.io/core => ./../../core cosmossdk.io/store => ./../../store cosmossdk.io/x/bank => ./../../x/bank cosmossdk.io/x/gov => ./../../x/gov diff --git a/client/v2/go.sum b/client/v2/go.sum index b4fc858a84a5..343839a3ec1d 100644 --- a/client/v2/go.sum +++ b/client/v2/go.sum @@ -6,6 +6,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/collections/go.mod b/collections/go.mod index e1d9dcef95d1..769d373ad6c7 100644 --- a/collections/go.mod +++ b/collections/go.mod @@ -3,7 +3,7 @@ module cosmossdk.io/collections go 1.23 require ( - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/schema v0.3.0 github.com/stretchr/testify v1.9.0 diff --git a/collections/go.sum b/collections/go.sum index ad552827598c..339220b95d0b 100644 --- a/collections/go.sum +++ b/collections/go.sum @@ -1,5 +1,5 @@ -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/schema v0.3.0 h1:01lcaM4trhzZ1HQTfTV8z6Ma1GziOZ/YmdzBN3F720c= diff --git a/core/testing/go.mod b/core/testing/go.mod index d58b3ca41c09..c81feab46344 100644 --- a/core/testing/go.mod +++ b/core/testing/go.mod @@ -3,7 +3,7 @@ module cosmossdk.io/core/testing go 1.23 require ( - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 github.com/tidwall/btree v1.7.0 go.uber.org/mock v0.5.0 ) diff --git a/core/testing/go.sum b/core/testing/go.sum index 3f2a99ea1c4c..53d361fe2b3c 100644 --- a/core/testing/go.sum +++ b/core/testing/go.sum @@ -1,5 +1,5 @@ -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/schema v0.3.0 h1:01lcaM4trhzZ1HQTfTV8z6Ma1GziOZ/YmdzBN3F720c= cosmossdk.io/schema v0.3.0/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI= diff --git a/go.mod b/go.mod index 4030b59547f5..e194006ee28c 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ module github.com/cosmos/cosmos-sdk require ( cosmossdk.io/api v0.7.6 cosmossdk.io/collections v0.4.0 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.0.0 cosmossdk.io/errors v1.0.1 @@ -185,7 +185,6 @@ require ( replace ( cosmossdk.io/api => ./api cosmossdk.io/collections => ./collections - cosmossdk.io/core => ./core cosmossdk.io/store => ./store cosmossdk.io/x/bank => ./x/bank cosmossdk.io/x/staking => ./x/staking diff --git a/go.sum b/go.sum index 0ee6f3fd6b61..f4809216a3b5 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1/go.mod h1:zqi/LZjZhyvjCMTEVIwAf5VRlkLduuCfqmZxgoormq0= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/runtime/v2/go.mod b/runtime/v2/go.mod index 846bdf28185a..e816395706d0 100644 --- a/runtime/v2/go.mod +++ b/runtime/v2/go.mod @@ -5,7 +5,6 @@ go 1.23 // server v2 integration replace ( cosmossdk.io/api => ../../api - cosmossdk.io/core => ../../core cosmossdk.io/server/v2/appmanager => ../../server/v2/appmanager cosmossdk.io/server/v2/stf => ../../server/v2/stf cosmossdk.io/store/v2 => ../../store/v2 @@ -14,7 +13,7 @@ replace ( require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/depinject v1.0.0 cosmossdk.io/log v1.4.1 cosmossdk.io/schema v0.3.0 diff --git a/runtime/v2/go.sum b/runtime/v2/go.sum index 169f4dc9b3c6..8ca72dad788c 100644 --- a/runtime/v2/go.sum +++ b/runtime/v2/go.sum @@ -2,6 +2,8 @@ buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.35.1-20240701160653-fed buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.35.1-20240701160653-fedbb9acfd2f.1/go.mod h1:JTBMfyi+qAXUHumX+rcD2WIq9FNWmdcNh5MjBnSw0L0= buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1 h1:F78ecjvMtgd1aZ1Aj9cvBjURxVGCYvRM+OOy5eR+pjw= buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1/go.mod h1:zqi/LZjZhyvjCMTEVIwAf5VRlkLduuCfqmZxgoormq0= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/server/v2/appmanager/go.mod b/server/v2/appmanager/go.mod index 381fca3bdd29..d00836cfadbd 100644 --- a/server/v2/appmanager/go.mod +++ b/server/v2/appmanager/go.mod @@ -2,6 +2,6 @@ module cosmossdk.io/server/v2/appmanager go 1.23 -require cosmossdk.io/core v1.0.0-alpha.4 +require cosmossdk.io/core v1.0.0-alpha.5 require cosmossdk.io/schema v0.3.0 // indirect diff --git a/server/v2/appmanager/go.sum b/server/v2/appmanager/go.sum index f798f0c9257f..d02010fc9fbb 100644 --- a/server/v2/appmanager/go.sum +++ b/server/v2/appmanager/go.sum @@ -1,4 +1,4 @@ -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/schema v0.3.0 h1:01lcaM4trhzZ1HQTfTV8z6Ma1GziOZ/YmdzBN3F720c= cosmossdk.io/schema v0.3.0/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= diff --git a/server/v2/cometbft/go.mod b/server/v2/cometbft/go.mod index 28fde47963e4..1fc5cc798538 100644 --- a/server/v2/cometbft/go.mod +++ b/server/v2/cometbft/go.mod @@ -4,7 +4,6 @@ go 1.23.1 replace ( cosmossdk.io/api => ../../../api - cosmossdk.io/core => ../../../core cosmossdk.io/server/v2 => ../ cosmossdk.io/server/v2/appmanager => ../appmanager cosmossdk.io/server/v2/stf => ../stf @@ -20,7 +19,7 @@ replace ( require ( cosmossdk.io/api v0.7.6 cosmossdk.io/collections v0.4.0 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/errors/v2 v2.0.0-20240731132947-df72853b3ca5 cosmossdk.io/log v1.4.1 cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac diff --git a/server/v2/cometbft/go.sum b/server/v2/cometbft/go.sum index e84b4ccba9e4..8e94e3b2b329 100644 --- a/server/v2/cometbft/go.sum +++ b/server/v2/cometbft/go.sum @@ -6,6 +6,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/server/v2/go.mod b/server/v2/go.mod index 124cf7e595d0..90da01b840f8 100644 --- a/server/v2/go.mod +++ b/server/v2/go.mod @@ -4,7 +4,6 @@ go 1.23 replace ( cosmossdk.io/api => ../../api - cosmossdk.io/core => ../../core cosmossdk.io/server/v2/appmanager => ./appmanager cosmossdk.io/server/v2/stf => ./stf cosmossdk.io/store/v2 => ../../store/v2 @@ -14,7 +13,7 @@ replace ( require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/log v1.4.1 cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac diff --git a/server/v2/go.sum b/server/v2/go.sum index e463c31061cf..3a1eb4d6d3aa 100644 --- a/server/v2/go.sum +++ b/server/v2/go.sum @@ -1,5 +1,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/errors/v2 v2.0.0-20240731132947-df72853b3ca5 h1:IQNdY2kB+k+1OM2DvqFG1+UgeU1JzZrWtwuWzI3ZfwA= diff --git a/server/v2/stf/go.mod b/server/v2/stf/go.mod index 7f55feb3f3f2..ee80284cfd41 100644 --- a/server/v2/stf/go.mod +++ b/server/v2/stf/go.mod @@ -3,7 +3,7 @@ module cosmossdk.io/server/v2/stf go 1.23 require ( - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/schema v0.3.0 github.com/cosmos/gogoproto v1.7.0 github.com/tidwall/btree v1.7.0 diff --git a/server/v2/stf/go.sum b/server/v2/stf/go.sum index 29d26cc868dc..4d3a18e53568 100644 --- a/server/v2/stf/go.sum +++ b/server/v2/stf/go.sum @@ -1,5 +1,5 @@ -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/schema v0.3.0 h1:01lcaM4trhzZ1HQTfTV8z6Ma1GziOZ/YmdzBN3F720c= cosmossdk.io/schema v0.3.0/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fro= diff --git a/simapp/go.mod b/simapp/go.mod index 45344a2a4d7d..acf7e963c7bb 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -6,7 +6,7 @@ require ( cosmossdk.io/api v0.7.6 cosmossdk.io/client/v2 v2.0.0-20230630094428-02b760776860 cosmossdk.io/collections v0.4.0 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.0.0 cosmossdk.io/log v1.4.1 @@ -240,7 +240,6 @@ replace ( cosmossdk.io/api => ../api cosmossdk.io/client/v2 => ../client/v2 cosmossdk.io/collections => ../collections - cosmossdk.io/core => ../core cosmossdk.io/store => ../store cosmossdk.io/tools/confix => ../tools/confix cosmossdk.io/x/accounts => ../x/accounts diff --git a/simapp/go.sum b/simapp/go.sum index 9d1d695d59a4..4215b27ee796 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -192,6 +192,8 @@ cloud.google.com/go/webrisk v1.4.0/go.mod h1:Hn8X6Zr+ziE2aNd8SliSDWpEnSS1u4R9+xX cloud.google.com/go/webrisk v1.5.0/go.mod h1:iPG6fr52Tv7sGk0H6qUFzmL3HHZev1htXuWDEEsqMTg= cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0= cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/simapp/v2/go.mod b/simapp/v2/go.mod index f0742e469635..dcbb5dc99dd3 100644 --- a/simapp/v2/go.mod +++ b/simapp/v2/go.mod @@ -5,7 +5,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 cosmossdk.io/client/v2 v2.0.0-00010101000000-000000000000 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/depinject v1.0.0 cosmossdk.io/log v1.4.1 cosmossdk.io/math v1.3.0 @@ -250,7 +250,6 @@ require ( replace ( cosmossdk.io/client/v2 => ../../client/v2 cosmossdk.io/collections => ../../collections - cosmossdk.io/core => ../../core cosmossdk.io/tools/confix => ../../tools/confix cosmossdk.io/x/accounts => ../../x/accounts cosmossdk.io/x/accounts/defaults/base => ../../x/accounts/defaults/base diff --git a/simapp/v2/go.sum b/simapp/v2/go.sum index 7c43f08488fe..a480ac4ea4e3 100644 --- a/simapp/v2/go.sum +++ b/simapp/v2/go.sum @@ -192,6 +192,8 @@ cloud.google.com/go/webrisk v1.4.0/go.mod h1:Hn8X6Zr+ziE2aNd8SliSDWpEnSS1u4R9+xX cloud.google.com/go/webrisk v1.5.0/go.mod h1:iPG6fr52Tv7sGk0H6qUFzmL3HHZev1htXuWDEEsqMTg= cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0= cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/store/go.mod b/store/go.mod index e3d9dd893141..20db0cea35ef 100644 --- a/store/go.mod +++ b/store/go.mod @@ -3,7 +3,7 @@ module cosmossdk.io/store go 1.23 require ( - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/errors v1.0.1 cosmossdk.io/log v1.4.1 diff --git a/store/go.sum b/store/go.sum index f30db3aaa6e1..b16dcd66f490 100644 --- a/store/go.sum +++ b/store/go.sum @@ -1,5 +1,5 @@ -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0= diff --git a/tests/go.mod b/tests/go.mod index 10484fd43497..5f58b80842f1 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -5,7 +5,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 cosmossdk.io/collections v0.4.0 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/depinject v1.0.0 cosmossdk.io/log v1.4.1 cosmossdk.io/math v1.3.0 @@ -264,7 +264,6 @@ replace ( // Below are the long-lived replace for tests. replace ( - cosmossdk.io/core => ../core // We always want to test against the latest version of the simapp. cosmossdk.io/simapp => ../simapp github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 diff --git a/tests/go.sum b/tests/go.sum index b408c9a72e49..bcb6688f04ba 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -192,6 +192,8 @@ cloud.google.com/go/webrisk v1.4.0/go.mod h1:Hn8X6Zr+ziE2aNd8SliSDWpEnSS1u4R9+xX cloud.google.com/go/webrisk v1.5.0/go.mod h1:iPG6fr52Tv7sGk0H6qUFzmL3HHZev1htXuWDEEsqMTg= cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0= cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/accounts/defaults/base/go.mod b/x/accounts/defaults/base/go.mod index 915abbbedbd9..47104229c8da 100644 --- a/x/accounts/defaults/base/go.mod +++ b/x/accounts/defaults/base/go.mod @@ -5,7 +5,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 cosmossdk.io/collections v0.4.0 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/depinject v1.0.0 cosmossdk.io/x/accounts v0.0.0-20240913065641-0064ccbce64e cosmossdk.io/x/tx v1.0.0-alpha.1 @@ -172,7 +172,6 @@ replace github.com/cosmos/cosmos-sdk => ../../../../. replace ( cosmossdk.io/api => ../../../../api cosmossdk.io/collections => ../../../../collections // TODO tag new collections ASAP - cosmossdk.io/core => ../../../../core cosmossdk.io/store => ../../../../store cosmossdk.io/x/accounts => ../../. cosmossdk.io/x/bank => ../../../bank diff --git a/x/accounts/defaults/base/go.sum b/x/accounts/defaults/base/go.sum index 47bd986a2209..f73a46026aa9 100644 --- a/x/accounts/defaults/base/go.sum +++ b/x/accounts/defaults/base/go.sum @@ -4,6 +4,8 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1/go.mod h1:zqi/LZjZhyvjCMTEVIwAf5VRlkLduuCfqmZxgoormq0= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/accounts/defaults/lockup/go.mod b/x/accounts/defaults/lockup/go.mod index c2d044aee831..7d6b09995b7d 100644 --- a/x/accounts/defaults/lockup/go.mod +++ b/x/accounts/defaults/lockup/go.mod @@ -4,7 +4,7 @@ go 1.23.1 require ( cosmossdk.io/collections v0.4.0 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/x/accounts v0.0.0-20240226161501-23359a0b6d91 cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 cosmossdk.io/x/distribution v0.0.0-00010101000000-000000000000 diff --git a/x/accounts/defaults/lockup/go.sum b/x/accounts/defaults/lockup/go.sum index 9fe9da5785db..d94fa49439da 100644 --- a/x/accounts/defaults/lockup/go.sum +++ b/x/accounts/defaults/lockup/go.sum @@ -4,8 +4,8 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1/go.mod h1:zqi/LZjZhyvjCMTEVIwAf5VRlkLduuCfqmZxgoormq0= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/accounts/defaults/multisig/go.mod b/x/accounts/defaults/multisig/go.mod index 2a54379a9f3f..2de1b5e1a878 100644 --- a/x/accounts/defaults/multisig/go.mod +++ b/x/accounts/defaults/multisig/go.mod @@ -4,7 +4,7 @@ go 1.23.1 require ( cosmossdk.io/collections v0.4.0 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/math v1.3.0 cosmossdk.io/x/accounts v0.0.0-00010101000000-000000000000 cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 @@ -172,7 +172,6 @@ replace github.com/cosmos/cosmos-sdk => ../../../../. replace ( cosmossdk.io/api => ../../../../api cosmossdk.io/collections => ../../../../collections // TODO tag new collections ASAP - cosmossdk.io/core => ../../../../core cosmossdk.io/store => ../../../../store cosmossdk.io/x/accounts => ../../. cosmossdk.io/x/bank => ../../../bank diff --git a/x/accounts/defaults/multisig/go.sum b/x/accounts/defaults/multisig/go.sum index 47bd986a2209..f73a46026aa9 100644 --- a/x/accounts/defaults/multisig/go.sum +++ b/x/accounts/defaults/multisig/go.sum @@ -4,6 +4,8 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1/go.mod h1:zqi/LZjZhyvjCMTEVIwAf5VRlkLduuCfqmZxgoormq0= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/accounts/go.mod b/x/accounts/go.mod index b319268c8b11..bd9b6b3004f8 100644 --- a/x/accounts/go.mod +++ b/x/accounts/go.mod @@ -5,7 +5,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 cosmossdk.io/collections v0.4.0 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.0.0 cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 @@ -176,7 +176,6 @@ replace github.com/cosmos/cosmos-sdk => ../../. replace ( cosmossdk.io/api => ../../api cosmossdk.io/collections => ../../collections - cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/staking => ../staking diff --git a/x/accounts/go.sum b/x/accounts/go.sum index 47bd986a2209..f73a46026aa9 100644 --- a/x/accounts/go.sum +++ b/x/accounts/go.sum @@ -4,6 +4,8 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1/go.mod h1:zqi/LZjZhyvjCMTEVIwAf5VRlkLduuCfqmZxgoormq0= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/authz/go.mod b/x/authz/go.mod index e5a1e36809a1..7981ed8c8cd1 100644 --- a/x/authz/go.mod +++ b/x/authz/go.mod @@ -4,7 +4,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/depinject v1.0.0 cosmossdk.io/errors v1.0.1 cosmossdk.io/log v1.4.1 @@ -177,7 +177,6 @@ replace github.com/cosmos/cosmos-sdk => ../../. replace ( cosmossdk.io/api => ../../api cosmossdk.io/collections => ../../collections - cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/staking => ../staking diff --git a/x/authz/go.sum b/x/authz/go.sum index 47bd986a2209..f73a46026aa9 100644 --- a/x/authz/go.sum +++ b/x/authz/go.sum @@ -4,6 +4,8 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1/go.mod h1:zqi/LZjZhyvjCMTEVIwAf5VRlkLduuCfqmZxgoormq0= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/bank/go.mod b/x/bank/go.mod index cd2d427aea03..57fa68f317cd 100644 --- a/x/bank/go.mod +++ b/x/bank/go.mod @@ -5,7 +5,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 cosmossdk.io/collections v0.4.0 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/depinject v1.0.0 cosmossdk.io/errors v1.0.1 cosmossdk.io/log v1.4.1 // indirect @@ -175,7 +175,6 @@ replace github.com/cosmos/cosmos-sdk => ../../. replace ( cosmossdk.io/api => ../../api cosmossdk.io/collections => ../../collections - cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/staking => ../staking cosmossdk.io/x/tx => ../tx diff --git a/x/bank/go.sum b/x/bank/go.sum index 47bd986a2209..f73a46026aa9 100644 --- a/x/bank/go.sum +++ b/x/bank/go.sum @@ -4,6 +4,8 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1/go.mod h1:zqi/LZjZhyvjCMTEVIwAf5VRlkLduuCfqmZxgoormq0= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/circuit/go.mod b/x/circuit/go.mod index 28ff11a8ae6f..c0617e9f2f2d 100644 --- a/x/circuit/go.mod +++ b/x/circuit/go.mod @@ -5,7 +5,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 cosmossdk.io/collections v0.4.0 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.0.0 cosmossdk.io/errors v1.0.1 @@ -172,7 +172,6 @@ replace github.com/cosmos/cosmos-sdk => ../../. // TODO remove post spinning out all modules replace ( cosmossdk.io/api => ../../api - cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/staking => ../staking diff --git a/x/circuit/go.sum b/x/circuit/go.sum index 504714b4a19f..215910c6bd26 100644 --- a/x/circuit/go.sum +++ b/x/circuit/go.sum @@ -6,6 +6,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/consensus/go.mod b/x/consensus/go.mod index b61945345de7..38fbbf9cbd9d 100644 --- a/x/consensus/go.mod +++ b/x/consensus/go.mod @@ -5,7 +5,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 cosmossdk.io/collections v0.4.0 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.0.0 cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc @@ -170,7 +170,6 @@ replace github.com/cosmos/cosmos-sdk => ../../. replace ( cosmossdk.io/api => ../../api - cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/staking => ../staking diff --git a/x/consensus/go.sum b/x/consensus/go.sum index 504714b4a19f..215910c6bd26 100644 --- a/x/consensus/go.sum +++ b/x/consensus/go.sum @@ -6,6 +6,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/distribution/go.mod b/x/distribution/go.mod index 2852ebc2ba48..d1cda9ff6829 100644 --- a/x/distribution/go.mod +++ b/x/distribution/go.mod @@ -5,7 +5,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 cosmossdk.io/collections v0.4.0 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.0.0 cosmossdk.io/errors v1.0.1 @@ -173,7 +173,6 @@ replace github.com/cosmos/cosmos-sdk => ../../. replace ( cosmossdk.io/api => ../../api cosmossdk.io/collections => ../../collections - cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/protocolpool => ../protocolpool diff --git a/x/distribution/go.sum b/x/distribution/go.sum index 47bd986a2209..f73a46026aa9 100644 --- a/x/distribution/go.sum +++ b/x/distribution/go.sum @@ -4,6 +4,8 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1/go.mod h1:zqi/LZjZhyvjCMTEVIwAf5VRlkLduuCfqmZxgoormq0= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/epochs/go.mod b/x/epochs/go.mod index 2f3f28c55328..01d309d0010e 100644 --- a/x/epochs/go.mod +++ b/x/epochs/go.mod @@ -5,7 +5,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 cosmossdk.io/collections v0.4.0 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.0.0 cosmossdk.io/errors v1.0.1 @@ -175,7 +175,6 @@ replace github.com/cosmos/cosmos-sdk => ../../. // TODO remove post spinning out all modules replace ( cosmossdk.io/api => ../../api - cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/staking => ../staking diff --git a/x/epochs/go.sum b/x/epochs/go.sum index 504714b4a19f..215910c6bd26 100644 --- a/x/epochs/go.sum +++ b/x/epochs/go.sum @@ -6,6 +6,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/evidence/go.mod b/x/evidence/go.mod index 761ba97cf28f..856f77aa24d6 100644 --- a/x/evidence/go.mod +++ b/x/evidence/go.mod @@ -5,7 +5,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 cosmossdk.io/collections v0.4.0 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.0.0 cosmossdk.io/errors v1.0.1 @@ -172,7 +172,6 @@ replace github.com/cosmos/cosmos-sdk => ../../. // TODO remove post spinning out all modules replace ( cosmossdk.io/api => ../../api - cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/staking => ../staking diff --git a/x/evidence/go.sum b/x/evidence/go.sum index 504714b4a19f..215910c6bd26 100644 --- a/x/evidence/go.sum +++ b/x/evidence/go.sum @@ -6,6 +6,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/feegrant/go.mod b/x/feegrant/go.mod index 030f84ab6b53..875f54bb9e60 100644 --- a/x/feegrant/go.mod +++ b/x/feegrant/go.mod @@ -5,7 +5,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 cosmossdk.io/collections v0.4.0 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.0.0 cosmossdk.io/errors v1.0.1 @@ -180,7 +180,6 @@ replace github.com/cosmos/cosmos-sdk => ../../. replace ( cosmossdk.io/api => ../../api cosmossdk.io/collections => ../../collections - cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/gov => ../gov diff --git a/x/feegrant/go.sum b/x/feegrant/go.sum index a57a57ba7b65..412240fe1285 100644 --- a/x/feegrant/go.sum +++ b/x/feegrant/go.sum @@ -4,6 +4,8 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1/go.mod h1:zqi/LZjZhyvjCMTEVIwAf5VRlkLduuCfqmZxgoormq0= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/gov/go.mod b/x/gov/go.mod index 4f8fd0dc4d8f..74b8649b1573 100644 --- a/x/gov/go.mod +++ b/x/gov/go.mod @@ -5,7 +5,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 cosmossdk.io/collections v0.4.0 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.0.0 cosmossdk.io/errors v1.0.1 @@ -176,7 +176,6 @@ replace github.com/cosmos/cosmos-sdk => ../../. replace ( cosmossdk.io/api => ../../api cosmossdk.io/collections => ../../collections - cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/protocolpool => ../protocolpool diff --git a/x/gov/go.sum b/x/gov/go.sum index 0aecae5e6593..acfad6c4abb9 100644 --- a/x/gov/go.sum +++ b/x/gov/go.sum @@ -4,6 +4,8 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1/go.mod h1:zqi/LZjZhyvjCMTEVIwAf5VRlkLduuCfqmZxgoormq0= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/group/go.mod b/x/group/go.mod index 1dd78427f899..b30069d479f5 100644 --- a/x/group/go.mod +++ b/x/group/go.mod @@ -4,7 +4,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.0.0 cosmossdk.io/errors v1.0.1 @@ -182,7 +182,6 @@ replace github.com/cosmos/cosmos-sdk => ../../ replace ( cosmossdk.io/api => ../../api cosmossdk.io/collections => ../../collections - cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/accounts => ../accounts cosmossdk.io/x/accounts/defaults/base => ../accounts/defaults/base diff --git a/x/group/go.sum b/x/group/go.sum index ca1f744e0a21..e858624a230f 100644 --- a/x/group/go.sum +++ b/x/group/go.sum @@ -4,6 +4,8 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1/go.mod h1:zqi/LZjZhyvjCMTEVIwAf5VRlkLduuCfqmZxgoormq0= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/mint/go.mod b/x/mint/go.mod index 724df0df7df1..a9fb59487cd0 100644 --- a/x/mint/go.mod +++ b/x/mint/go.mod @@ -5,7 +5,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 cosmossdk.io/collections v0.4.0 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.0.0 cosmossdk.io/errors v1.0.1 @@ -176,7 +176,6 @@ replace github.com/cosmos/cosmos-sdk => ../../. // TODO remove post spinning out all modules replace ( cosmossdk.io/api => ../../api - cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/consensus => ../consensus diff --git a/x/mint/go.sum b/x/mint/go.sum index 504714b4a19f..215910c6bd26 100644 --- a/x/mint/go.sum +++ b/x/mint/go.sum @@ -6,6 +6,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/nft/go.mod b/x/nft/go.mod index d8de5dbf40d0..bb20d0f32145 100644 --- a/x/nft/go.mod +++ b/x/nft/go.mod @@ -4,7 +4,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/depinject v1.0.0 cosmossdk.io/errors v1.0.1 cosmossdk.io/log v1.4.1 @@ -172,7 +172,6 @@ replace github.com/cosmos/cosmos-sdk => ../../. // TODO remove post spinning out all modules replace ( cosmossdk.io/api => ../../api - cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/staking => ../staking diff --git a/x/nft/go.sum b/x/nft/go.sum index 504714b4a19f..215910c6bd26 100644 --- a/x/nft/go.sum +++ b/x/nft/go.sum @@ -6,6 +6,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/params/go.mod b/x/params/go.mod index 8357b46db57b..728240b29f95 100644 --- a/x/params/go.mod +++ b/x/params/go.mod @@ -4,7 +4,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.0.0 cosmossdk.io/errors v1.0.1 diff --git a/x/params/go.sum b/x/params/go.sum index b99b90c57899..b5f3c269dfda 100644 --- a/x/params/go.sum +++ b/x/params/go.sum @@ -6,8 +6,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= -cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= -cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/protocolpool/go.mod b/x/protocolpool/go.mod index 3da3a7e9ed66..17c0dde58c97 100644 --- a/x/protocolpool/go.mod +++ b/x/protocolpool/go.mod @@ -5,7 +5,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 cosmossdk.io/collections v0.4.0 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.0.0 cosmossdk.io/errors v1.0.1 @@ -172,7 +172,6 @@ replace github.com/cosmos/cosmos-sdk => ../../. // TODO remove post spinning out all modules replace ( cosmossdk.io/api => ../../api - cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/staking => ../staking diff --git a/x/protocolpool/go.sum b/x/protocolpool/go.sum index 504714b4a19f..215910c6bd26 100644 --- a/x/protocolpool/go.sum +++ b/x/protocolpool/go.sum @@ -6,6 +6,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/slashing/go.mod b/x/slashing/go.mod index d9555cd760df..b5fe5e5b184e 100644 --- a/x/slashing/go.mod +++ b/x/slashing/go.mod @@ -5,7 +5,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 cosmossdk.io/collections v0.4.0 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.0.0 cosmossdk.io/errors v1.0.1 @@ -173,7 +173,6 @@ replace github.com/cosmos/cosmos-sdk => ../../. // TODO remove post spinning out all modules replace ( cosmossdk.io/api => ../../api - cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/staking => ../staking diff --git a/x/slashing/go.sum b/x/slashing/go.sum index 83b48618d669..ed2f73d3532a 100644 --- a/x/slashing/go.sum +++ b/x/slashing/go.sum @@ -6,6 +6,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/staking/go.mod b/x/staking/go.mod index 5a2c0a9ce409..effb45e50aa8 100644 --- a/x/staking/go.mod +++ b/x/staking/go.mod @@ -5,7 +5,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 cosmossdk.io/collections v0.4.0 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.0.0 cosmossdk.io/errors v1.0.1 @@ -178,7 +178,6 @@ replace github.com/cosmos/cosmos-sdk => ../../. replace ( cosmossdk.io/api => ../../api cosmossdk.io/collections => ../../collections - cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/tx => ../tx diff --git a/x/staking/go.sum b/x/staking/go.sum index 47bd986a2209..f73a46026aa9 100644 --- a/x/staking/go.sum +++ b/x/staking/go.sum @@ -4,6 +4,8 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1/go.mod h1:zqi/LZjZhyvjCMTEVIwAf5VRlkLduuCfqmZxgoormq0= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= diff --git a/x/upgrade/go.mod b/x/upgrade/go.mod index d19dccf45d59..1e8a7f54b455 100644 --- a/x/upgrade/go.mod +++ b/x/upgrade/go.mod @@ -4,7 +4,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/core v1.0.0-alpha.4 + cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.0.0 cosmossdk.io/errors v1.0.1 @@ -202,7 +202,6 @@ replace github.com/cosmos/cosmos-sdk => ../../. replace ( cosmossdk.io/api => ../../api - cosmossdk.io/core => ../../core cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/gov => ../gov diff --git a/x/upgrade/go.sum b/x/upgrade/go.sum index aa5a54d9ba73..65cec3fae535 100644 --- a/x/upgrade/go.sum +++ b/x/upgrade/go.sum @@ -194,6 +194,8 @@ cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1V cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= +cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= +cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= From ca062587422353a2d7f2008dca147e12f8c8d75b Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Fri, 25 Oct 2024 16:44:50 -0500 Subject: [PATCH 26/46] use factory pattern instead --- server/v2/command_builder.go | 169 +++++++++++++++++++++++++ server/v2/commands.go | 141 +-------------------- server/v2/logger.go | 37 ++++-- server/v2/server.go | 4 +- server/v2/server_test.go | 3 +- server/v2/store/snapshot.go | 2 +- server/v2/util.go | 12 +- simapp/v2/simdv2/cmd/commands.go | 2 +- simapp/v2/simdv2/cmd/config.go | 12 +- simapp/v2/simdv2/cmd/root_consensus.go | 99 --------------- simapp/v2/simdv2/cmd/root_di.go | 48 ++++--- simapp/v2/simdv2/cmd/root_test.go | 6 +- simapp/v2/simdv2/cmd/testnet_test.go | 3 +- simapp/v2/simdv2/main.go | 3 +- x/upgrade/depinject.go | 8 +- 15 files changed, 249 insertions(+), 300 deletions(-) create mode 100644 server/v2/command_builder.go delete mode 100644 simapp/v2/simdv2/cmd/root_consensus.go diff --git a/server/v2/command_builder.go b/server/v2/command_builder.go new file mode 100644 index 000000000000..b241db7e5065 --- /dev/null +++ b/server/v2/command_builder.go @@ -0,0 +1,169 @@ +package serverv2 + +import ( + "errors" + "os" + "path/filepath" + "strings" + + "github.com/spf13/cobra" + "github.com/spf13/pflag" + "github.com/spf13/viper" + + "cosmossdk.io/core/server" + "cosmossdk.io/log" +) + +// CommandFactory is a factory help create server/v2 root commands. +// For example usage see simapp/v2/cmd/root_di.go +type CommandFactory struct { + defaultHomeDir string + envPrefix string + configWriter ConfigWriter + logger log.Logger + // TODO remove this field + // this viper handle is kept because certain commands in server/v2 fetch a viper instance + // from the command context in order to read the config. + // After merging #22267 this is no longer required, and server.ConfigMap can be used instead. + // See issue # + vipr *viper.Viper +} + +type CommandFactoryOption func(*CommandFactory) error + +// NewCommandFactory creates a new CommandFactory with the given options. +func NewCommandFactory(opts ...CommandFactoryOption) (*CommandFactory, error) { + f := &CommandFactory{} + for _, opt := range opts { + err := opt(f) + if err != nil { + return nil, err + } + } + return f, nil +} + +// WithEnvPrefix sets the environment variable prefix for the command factory. +func WithEnvPrefix(envPrefix string) CommandFactoryOption { + return func(f *CommandFactory) error { + f.envPrefix = envPrefix + return nil + } +} + +// WithStdDefaultHomeDir sets the server's default home directory `user home directory`/`defaultHomeBasename`. +func WithStdDefaultHomeDir(defaultHomeBasename string) CommandFactoryOption { + return func(f *CommandFactory) error { + // get the home directory from the environment variable + // to not clash with the $HOME system variable, when no prefix is set + // we check the NODE_HOME environment variable + homeDir, envHome := "", "HOME" + if len(f.envPrefix) > 0 { + homeDir = os.Getenv(f.envPrefix + "_" + envHome) + } else { + homeDir = os.Getenv("NODE_" + envHome) + } + if homeDir != "" { + f.defaultHomeDir = filepath.Clean(homeDir) + return nil + } + + // get user home directory + userHomeDir, err := os.UserHomeDir() + if err != nil { + return err + } + + f.defaultHomeDir = filepath.Join(userHomeDir, defaultHomeBasename) + return nil + } +} + +// WithDefaultHomeDir sets the server's default home directory. +func WithDefaultHomeDir(homedir string) CommandFactoryOption { + return func(f *CommandFactory) error { + f.defaultHomeDir = homedir + return nil + } +} + +// WithConfigWriter sets the config writer for the command factory. +// If set the config writer will be used to write TOML config files during ParseCommand invocations. +func WithConfigWriter(configWriter ConfigWriter) CommandFactoryOption { + return func(f *CommandFactory) error { + f.configWriter = configWriter + return nil + } +} + +// SetLogger sets the logger for the command factory. +// If set the logger will be set in the command context in EnhanceCommand. +func WithLogger(logger log.Logger) CommandFactoryOption { + return func(f *CommandFactory) error { + f.logger = logger + return nil + } +} + +// EnhanceCommand adds the following flags to the command: +// +// --log-level: The logging level (trace|debug|info|warn|error|fatal|panic|disabled or '*:,:') +// --log-format: The logging format (json|plain) +// --log-no-color: Disable colored logs +// --home: directory for config and data +// +// It also sets the environment variable prefix for the viper instance. +// It sets the logger and viper in the command context (if present) +func (f *CommandFactory) EnhanceCommand(cmd *cobra.Command) { + pflags := cmd.PersistentFlags() + pflags.String(FlagLogLevel, "info", "The logging level (trace|debug|info|warn|error|fatal|panic|disabled or '*:,:')") + pflags.String(FlagLogFormat, "plain", "The logging format (json|plain)") + pflags.Bool(FlagLogNoColor, false, "Disable colored logs") + pflags.StringP(FlagHome, "", f.defaultHomeDir, "directory for config and data") + viper.SetEnvPrefix(f.envPrefix) + viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_")) + viper.AutomaticEnv() + if f.vipr != nil && f.logger != nil { + SetCmdServerContext(cmd, f.vipr, f.logger) + } +} + +// ParseCommand parses args against the input rootCmd CLI skeleton then returns the target subcommand and +// a fully realized config map. +// If `WithConfigWriter` was set in the factory options, the config writer will be used to write the app.toml file. +func (f *CommandFactory) ParseCommand(rootCmd *cobra.Command, args []string) (*cobra.Command, server.ConfigMap, error) { + f.EnhanceCommand(rootCmd) + cmd, _, err := rootCmd.Traverse(args) + if err != nil { + return nil, nil, err + } + if err = cmd.ParseFlags(args); err != nil { + // help requested, return the command early + if errors.Is(err, pflag.ErrHelp) { + return cmd, nil, nil + } + return nil, nil, err + } + home, err := cmd.Flags().GetString(FlagHome) + if err != nil { + return nil, nil, err + } + configDir := filepath.Join(home, "config") + if f.configWriter != nil { + // create app.toml if it does not already exist + if _, err = os.Stat(filepath.Join(configDir, "app.toml")); os.IsNotExist(err) { + if err = f.configWriter.WriteConfig(configDir); err != nil { + return nil, nil, err + } + } + } + f.vipr, err = ReadConfig(configDir) + if err != nil { + return nil, nil, err + } + if err = f.vipr.BindPFlags(cmd.Flags()); err != nil { + return nil, nil, err + } + + return cmd, f.vipr.AllSettings(), nil +} diff --git a/server/v2/commands.go b/server/v2/commands.go index 7ae8bc49c065..544e18a83553 100644 --- a/server/v2/commands.go +++ b/server/v2/commands.go @@ -5,156 +5,17 @@ import ( "errors" "os" "os/signal" - "path/filepath" "runtime/pprof" "strings" "syscall" "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/spf13/viper" "cosmossdk.io/core/server" "cosmossdk.io/core/transaction" "cosmossdk.io/log" ) -type RootCmdBuilder struct { - DefaultHome string - EnvPrefix string - - use string - fixture CommandFixture - vipr *viper.Viper - logger log.Logger -} - -type CommandFixture interface { - Bootstrap(cmd *cobra.Command) (WritesConfig, error) - RootCommand( - rootCommand *cobra.Command, - subCommand *cobra.Command, - logger log.Logger, - config server.ConfigMap, - ) (*cobra.Command, error) -} - -func NewRootCmdBuilder( - fixture CommandFixture, - use string, - defaultHomeBasename string, -) (*RootCmdBuilder, error) { - f := &RootCmdBuilder{ - fixture: fixture, - use: use, - } - var err error - f.DefaultHome, err = f.DefaultHomeDir(defaultHomeBasename) - if err != nil { - return nil, err - } - return f, nil -} - -func (b *RootCmdBuilder) DefaultHomeDir(name string) (string, error) { - // get the home directory from the environment variable - // to not clash with the $HOME system variable, when no prefix is set - // we check the NODE_HOME environment variable - homeDir, envHome := "", "HOME" - if len(b.EnvPrefix) > 0 { - homeDir = os.Getenv(b.EnvPrefix + "_" + envHome) - } else { - homeDir = os.Getenv("NODE_" + envHome) - } - if homeDir != "" { - return filepath.Clean(homeDir), nil - } - - // get user home directory - userHomeDir, err := os.UserHomeDir() - if err != nil { - return "", err - } - - return filepath.Join(userHomeDir, name), nil -} - -func (b *RootCmdBuilder) Command() (*cobra.Command, error) { - cmd := &cobra.Command{Use: b.use, SilenceErrors: true} - SetPersistentFlags(cmd.PersistentFlags(), b.DefaultHome) - // update the global viper with the root command's configuration - viper.SetEnvPrefix(b.EnvPrefix) - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_")) - viper.AutomaticEnv() - if b.vipr != nil && b.logger != nil { - err := SetCmdServerContext(cmd, b.vipr, b.logger) - if err != nil { - return nil, err - } - } - return cmd, nil -} - -func (b *RootCmdBuilder) Build( - args []string, -) (*cobra.Command, error) { - bootstrapCmd, err := b.Command() - if err != nil { - return nil, err - } - configWriter, err := b.fixture.Bootstrap(bootstrapCmd) - if err != nil { - return nil, err - } - cmd, _, err := bootstrapCmd.Traverse(args) - if err != nil { - return nil, err - } - if err = cmd.ParseFlags(args); err != nil { - // help requested, return the command early - if errors.Is(err, pflag.ErrHelp) { - return cmd, nil - } - return nil, err - } - home, err := cmd.Flags().GetString(FlagHome) - if err != nil { - return nil, err - } - configDir := filepath.Join(home, "config") - // create app.toml if it does not already exist - if _, err = os.Stat(filepath.Join(configDir, "app.toml")); os.IsNotExist(err) { - if err = configWriter.WriteConfig(configDir); err != nil { - return nil, err - } - } - b.vipr, err = ReadConfig(configDir) - if err != nil { - return nil, err - } - if err = b.vipr.BindPFlags(cmd.Flags()); err != nil { - return nil, err - } - b.logger, err = NewLogger(b.vipr, cmd.OutOrStdout()) - if err != nil { - return nil, err - } - rootCmd, err := b.Command() - if err != nil { - return nil, err - } - return b.fixture.RootCommand(rootCmd, cmd, b.logger, b.vipr.AllSettings()) -} - -// SetPersistentFlags sets persistent flags which should be used by all server (and client) -// commands. They control logging behavior and home directory. -func SetPersistentFlags(pflags *pflag.FlagSet, defaultHome string) { - pflags.String(FlagLogLevel, "info", "The logging level (trace|debug|info|warn|error|fatal|panic|disabled or '*:,:')") - pflags.String(FlagLogFormat, "plain", "The logging format (json|plain)") - pflags.Bool(FlagLogNoColor, false, "Disable colored logs") - pflags.StringP(FlagHome, "", defaultHome, "directory for config and data") -} - // AddCommands add the server commands to the root command // It configures the config handling and the logger handling func AddCommands[T transaction.Tx]( @@ -163,7 +24,7 @@ func AddCommands[T transaction.Tx]( globalAppConfig server.ConfigMap, globalServerConfig ServerConfig, components ...ServerComponent[T], -) (WritesConfig, error) { +) (ConfigWriter, error) { if len(components) == 0 { return nil, errors.New("no components provided") } diff --git a/server/v2/logger.go b/server/v2/logger.go index 8ca80e4cce45..33ef557ca540 100644 --- a/server/v2/logger.go +++ b/server/v2/logger.go @@ -4,33 +4,52 @@ import ( "io" "github.com/rs/zerolog" - "github.com/spf13/viper" + "cosmossdk.io/core/server" "cosmossdk.io/log" ) // NewLogger creates the default SDK logger. // It reads the log level and format from the server context. -func NewLogger(v *viper.Viper, out io.Writer) (log.Logger, error) { +func NewLogger(cfg server.ConfigMap, out io.Writer) (log.Logger, error) { var opts []log.Option - if v.GetString(FlagLogFormat) == OutputFormatJSON { + var ( + format string + noColor bool + trace bool + level string + ) + if v, ok := cfg[FlagLogFormat]; ok { + format = v.(string) + } + if v, ok := cfg[FlagLogNoColor]; ok { + noColor = v.(bool) + } + if v, ok := cfg[FlagTrace]; ok { + trace = v.(bool) + } + if v, ok := cfg[FlagLogLevel]; ok { + level = v.(string) + } + + if format == OutputFormatJSON { opts = append(opts, log.OutputJSONOption()) } opts = append(opts, - log.ColorOption(!v.GetBool(FlagLogNoColor)), - log.TraceOption(v.GetBool(FlagTrace))) + log.ColorOption(!noColor), + log.TraceOption(trace), + ) // check and set filter level or keys for the logger if any - logLvlStr := v.GetString(FlagLogLevel) - if logLvlStr == "" { + if level == "" { return log.NewLogger(out, opts...), nil } - logLvl, err := zerolog.ParseLevel(logLvlStr) + logLvl, err := zerolog.ParseLevel(level) switch { case err != nil: // If the log level is not a valid zerolog level, then we try to parse it as a key filter. - filterFunc, err := log.ParseLogLevel(logLvlStr) + filterFunc, err := log.ParseLogLevel(level) if err != nil { return nil, err } diff --git a/server/v2/server.go b/server/v2/server.go index 3a082aac61ac..063be7d1df24 100644 --- a/server/v2/server.go +++ b/server/v2/server.go @@ -37,8 +37,8 @@ type HasConfig interface { Config() any } -// WritesConfig is a server module that can write its config to a file. -type WritesConfig interface { +// ConfigWriter is a server module that can write its config to a file. +type ConfigWriter interface { WriteConfig(path string) error } diff --git a/server/v2/server_test.go b/server/v2/server_test.go index fbef37ae132c..d71416dfb3fd 100644 --- a/server/v2/server_test.go +++ b/server/v2/server_test.go @@ -61,8 +61,7 @@ func TestServer(t *testing.T) { logger := log.NewLogger(os.Stdout) - ctx, err := serverv2.SetServerContext(context.Background(), v, logger) - require.NoError(t, err) + ctx := serverv2.SetServerContext(context.Background(), v, logger) app := &mockApp[transaction.Tx]{} grpcServer, err := grpc.New[transaction.Tx](logger, app.InterfaceRegistry(), app.QueryHandlers(), app, cfg) diff --git a/server/v2/store/snapshot.go b/server/v2/store/snapshot.go index 8340ee77e8c2..c858d47757a9 100644 --- a/server/v2/store/snapshot.go +++ b/server/v2/store/snapshot.go @@ -97,7 +97,7 @@ func (s *Server[T]) RestoreSnapshotCmd() *cobra.Command { rootStore, _, err := createRootStore(v, logger) if err != nil { - return err + return fmt.Errorf("failed to create root store: %w", err) } sm, err := createSnapshotsManager(cmd, v, logger, rootStore) if err != nil { diff --git a/server/v2/util.go b/server/v2/util.go index d02ea30125e5..f17faf031595 100644 --- a/server/v2/util.go +++ b/server/v2/util.go @@ -15,26 +15,22 @@ import ( // SetServerContext sets the logger and viper in the context. // The server manager expects the logger and viper to be set in the context. -func SetServerContext(ctx context.Context, viper *viper.Viper, logger log.Logger) (context.Context, error) { +func SetServerContext(ctx context.Context, viper *viper.Viper, logger log.Logger) context.Context { if ctx == nil { ctx = context.Background() } ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) - return ctx, nil + return ctx } // SetCmdServerContext sets a command's Context value to the provided argument. // The server manager expects the logger and viper to be set in the context. // If the context has not been set, set the given context as the default. -func SetCmdServerContext(cmd *cobra.Command, viper *viper.Viper, logger log.Logger) error { - ctx, err := SetServerContext(cmd.Context(), viper, logger) - if err != nil { - return err - } +func SetCmdServerContext(cmd *cobra.Command, viper *viper.Viper, logger log.Logger) { + ctx := SetServerContext(cmd.Context(), viper, logger) cmd.SetContext(ctx) - return nil } // GetViperFromContext returns the viper instance from the context. diff --git a/simapp/v2/simdv2/cmd/commands.go b/simapp/v2/simdv2/cmd/commands.go index e47d80720fcb..7eb9f50ebdbd 100644 --- a/simapp/v2/simdv2/cmd/commands.go +++ b/simapp/v2/simdv2/cmd/commands.go @@ -46,7 +46,7 @@ func initRootCmd[T transaction.Tx]( rootCmd *cobra.Command, logger log.Logger, deps commandDependencies[T], -) (serverv2.WritesConfig, error) { +) (serverv2.ConfigWriter, error) { cfg := sdk.GetConfig() cfg.Seal() diff --git a/simapp/v2/simdv2/cmd/config.go b/simapp/v2/simdv2/cmd/config.go index 034bb2540a23..be82d9edf564 100644 --- a/simapp/v2/simdv2/cmd/config.go +++ b/simapp/v2/simdv2/cmd/config.go @@ -120,16 +120,12 @@ func isAppRequired(cmd *cobra.Command) bool { m := map[string]bool{} for _, c := range appBuildingCommands { slices.Reverse(c) - var k string - for _, sc := range c { - k += sc - } - m[k] = true + m[strings.Join(c, "")] = true } - var use string + cmdPath := make([]string, 0, 5) // Pre-allocate with reasonable capacity for { - use += cmd.Use - if _, ok := m[use]; ok { + cmdPath = append(cmdPath, cmd.Use) + if _, ok := m[strings.Join(cmdPath, "")]; ok { return true } if cmd.Parent() == nil { diff --git a/simapp/v2/simdv2/cmd/root_consensus.go b/simapp/v2/simdv2/cmd/root_consensus.go deleted file mode 100644 index ccb5b74040e0..000000000000 --- a/simapp/v2/simdv2/cmd/root_consensus.go +++ /dev/null @@ -1,99 +0,0 @@ -package cmd - -import ( - "github.com/spf13/cobra" - - autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" - "cosmossdk.io/client/v2/autocli" - "cosmossdk.io/core/server" - "cosmossdk.io/core/transaction" - "cosmossdk.io/depinject" - "cosmossdk.io/log" - "cosmossdk.io/runtime/v2" - serverv2 "cosmossdk.io/server/v2" - "cosmossdk.io/simapp/v2" - - "github.com/cosmos/cosmos-sdk/client" - nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" -) - -// AlternateConsensusFixture is a custom implementation of the CommandFixture interface -// which demonstrates how an app developer can customize the root command initialization. -// In this case a different consensus is assummed but not implemented. -type AlternateConsensusFixture[T transaction.Tx] struct{} - -func (AlternateConsensusFixture[T]) Bootstrap(cmd *cobra.Command) (serverv2.WritesConfig, error) { - // create your custom consensus component here for config parsing and initialization - var consensusComponent serverv2.ServerComponent[T] - return initRootCmd(cmd, log.NewNopLogger(), commandDependencies[T]{ - consensusComponent: consensusComponent, - }) -} - -func (AlternateConsensusFixture[T]) RootCommand( - rootCommand *cobra.Command, - subCommand *cobra.Command, - logger log.Logger, - configMap server.ConfigMap, -) (*cobra.Command, error) { - var ( - autoCliOpts autocli.AppOptions - moduleManager *runtime.MM[T] - clientCtx client.Context - simApp *simapp.SimApp[T] - err error - consensusComponent serverv2.ServerComponent[T] - ) - if isAppRequired(subCommand) { - // server construction - simApp, err = simapp.NewSimApp[T]( - depinject.Configs( - depinject.Supply(logger, runtime.GlobalConfig(configMap)), - depinject.Provide(ProvideClientContext), - ), - &autoCliOpts, &moduleManager, &clientCtx) - if err != nil { - return nil, err - } - // create your custom consensus component here with outputs now available from DI - consensusComponent = nil - } else { - // client construction - if err = depinject.Inject( - depinject.Configs( - simapp.AppConfig(), - depinject.Provide(ProvideClientContext), - depinject.Supply( - logger, - runtime.GlobalConfig(configMap), - ), - ), - &autoCliOpts, &moduleManager, &clientCtx, - ); err != nil { - return nil, err - } - } - - rootCommand.Short = "simulation app" - rootCommand.PersistentPreRunE = rootCommandPersistentPreRun(clientCtx) - - commandDeps := commandDependencies[T]{ - globalAppConfig: configMap, - txConfig: clientCtx.TxConfig, - moduleManager: moduleManager, - simApp: simApp, - consensusComponent: consensusComponent, - } - _, err = initRootCmd(rootCommand, logger, commandDeps) - if err != nil { - return nil, err - } - nodeCmds := nodeservice.NewNodeCommands() - autoCliOpts.ModuleOptions = make(map[string]*autocliv1.ModuleOptions) - autoCliOpts.ModuleOptions[nodeCmds.Name()] = nodeCmds.AutoCLIOptions() - if err := autoCliOpts.EnhanceRootCommand(rootCommand); err != nil { - return nil, err - } - - return rootCommand, nil -} diff --git a/simapp/v2/simdv2/cmd/root_di.go b/simapp/v2/simdv2/cmd/root_di.go index 1d0901127ff7..179a1412728d 100644 --- a/simapp/v2/simdv2/cmd/root_di.go +++ b/simapp/v2/simdv2/cmd/root_di.go @@ -5,7 +5,6 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" "cosmossdk.io/client/v2/autocli" - "cosmossdk.io/core/server" "cosmossdk.io/core/transaction" "cosmossdk.io/depinject" "cosmossdk.io/log" @@ -17,35 +16,36 @@ import ( nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" ) -func NewRootCmd( - commandFixture serverv2.CommandFixture, +func NewRootCmd[T transaction.Tx]( args ...string, ) (*cobra.Command, error) { - builder, err := serverv2.NewRootCmdBuilder(commandFixture, "simdv2", ".simappv2") + cmd := &cobra.Command{Use: "simdv2", SilenceErrors: true} + configWriter, err := initRootCmd(cmd, log.NewNopLogger(), commandDependencies[T]{}) + if err != nil { + return nil, err + } + stdHomeDirOption := serverv2.WithStdDefaultHomeDir(".simappv2") + factory, err := serverv2.NewCommandFactory(serverv2.WithConfigWriter(configWriter), stdHomeDirOption) if err != nil { return nil, err } - return builder.Build(args) -} - -type DefaultCommandFixture[T transaction.Tx] struct{} -func (DefaultCommandFixture[T]) Bootstrap(cmd *cobra.Command) (serverv2.WritesConfig, error) { - return initRootCmd(cmd, log.NewNopLogger(), commandDependencies[T]{}) -} + // returns the target subcommand and a fully realized config map + subCommand, configMap, err := factory.ParseCommand(cmd, args) + if err != nil { + return nil, err + } + // create default logger + logger, err := serverv2.NewLogger(configMap, cmd.OutOrStdout()) + if err != nil { + return nil, err + } -func (DefaultCommandFixture[T]) RootCommand( - rootCommand *cobra.Command, - subCommand *cobra.Command, - logger log.Logger, - configMap server.ConfigMap, -) (*cobra.Command, error) { var ( autoCliOpts autocli.AppOptions moduleManager *runtime.MM[T] clientCtx client.Context simApp *simapp.SimApp[T] - err error ) if isAppRequired(subCommand) { // server construction @@ -75,8 +75,16 @@ func (DefaultCommandFixture[T]) RootCommand( } } - rootCommand.Short = "simulation app" - rootCommand.PersistentPreRunE = rootCommandPersistentPreRun(clientCtx) + rootCommand := &cobra.Command{ + Use: "simdv2", + Short: "simulation app", + PersistentPreRunE: rootCommandPersistentPreRun(clientCtx), + } + factory, err = serverv2.NewCommandFactory(stdHomeDirOption, serverv2.WithLogger(logger)) + if err != nil { + return nil, err + } + factory.EnhanceCommand(rootCommand) commandDeps := commandDependencies[T]{ globalAppConfig: configMap, diff --git a/simapp/v2/simdv2/cmd/root_test.go b/simapp/v2/simdv2/cmd/root_test.go index a6833f504e11..7f7d6a07d95a 100644 --- a/simapp/v2/simdv2/cmd/root_test.go +++ b/simapp/v2/simdv2/cmd/root_test.go @@ -19,8 +19,7 @@ func TestInitCmd(t *testing.T) { "simapp-test", // Moniker fmt.Sprintf("--%s=%s", cli.FlagOverwrite, "true"), // Overwrite genesis.json, in case it already exists } - fixture := cmd.DefaultCommandFixture[transaction.Tx]{} - rootCmd, err := cmd.NewRootCmd(fixture, args...) + rootCmd, err := cmd.NewRootCmd[transaction.Tx](args...) require.NoError(t, err) rootCmd.SetArgs(args) require.NoError(t, rootCmd.Execute()) @@ -34,8 +33,7 @@ func TestHomeFlagRegistration(t *testing.T) { homeDir, } - fixture := cmd.DefaultCommandFixture[transaction.Tx]{} - rootCmd, err := cmd.NewRootCmd(fixture, args...) + rootCmd, err := cmd.NewRootCmd[transaction.Tx](args...) require.NoError(t, err) rootCmd.SetArgs(args) require.NoError(t, rootCmd.Execute()) diff --git a/simapp/v2/simdv2/cmd/testnet_test.go b/simapp/v2/simdv2/cmd/testnet_test.go index fff87ec58855..acf57dd37b80 100644 --- a/simapp/v2/simdv2/cmd/testnet_test.go +++ b/simapp/v2/simdv2/cmd/testnet_test.go @@ -19,8 +19,7 @@ func TestInitTestFilesCmd(t *testing.T) { "init-files", fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest), // Set keyring-backend to test } - fixture := cmd.DefaultCommandFixture[transaction.Tx]{} - rootCmd, err := cmd.NewRootCmd(fixture, args...) + rootCmd, err := cmd.NewRootCmd[transaction.Tx](args...) require.NoError(t, err) rootCmd.SetArgs(args) require.NoError(t, rootCmd.Execute()) diff --git a/simapp/v2/simdv2/main.go b/simapp/v2/simdv2/main.go index 85fc8c85c7b9..d01a45030cb9 100644 --- a/simapp/v2/simdv2/main.go +++ b/simapp/v2/simdv2/main.go @@ -13,8 +13,7 @@ func main() { // reproduce default cobra behavior so that eager parsing of flags is possible. // see: https://github.com/spf13/cobra/blob/e94f6d0dd9a5e5738dca6bce03c4b1207ffbc0ec/command.go#L1082 args := os.Args[1:] - fixture := cmd.DefaultCommandFixture[transaction.Tx]{} - rootCmd, err := cmd.NewRootCmd(fixture, args...) + rootCmd, err := cmd.NewRootCmd[transaction.Tx](args...) if err != nil { if _, pErr := fmt.Fprintln(os.Stderr, err); pErr != nil { panic(errors.Join(err, pErr)) diff --git a/x/upgrade/depinject.go b/x/upgrade/depinject.go index 2a8305e9bad2..01b93356fdf0 100644 --- a/x/upgrade/depinject.go +++ b/x/upgrade/depinject.go @@ -66,8 +66,12 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { skipUpgradeHeights = make(map[int64]bool) ) - skipUpgrades := cast.ToIntSlice(in.ConfigMap[server.FlagUnsafeSkipUpgrades]) - for _, h := range skipUpgrades { + skipUpgrades, ok := in.ConfigMap[server.FlagUnsafeSkipUpgrades] + if !ok || skipUpgrades == nil { + skipUpgrades = []int{} + } + heights := cast.ToIntSlice(skipUpgrades) // safe to use cast here as we've handled nil case + for _, h := range heights { skipUpgradeHeights[int64(h)] = true } homePath = cast.ToString(in.ConfigMap[flags.FlagHome]) From 20e7ec19cc82537d4dbcdf822558cd6e38afa3e0 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Fri, 25 Oct 2024 17:48:56 -0500 Subject: [PATCH 27/46] fix factory pattern --- .vscode/launch.json | 2 +- scripts/init-simapp-v2.sh | 1 + server/v2/api/grpc/server.go | 10 ++++-- server/v2/api/rest/server.go | 14 +++++--- server/v2/api/rest/server_test.go | 3 +- server/v2/cometbft/server.go | 10 ++++-- server/v2/command_builder.go | 55 ++++++++++++++++++++----------- simapp/v2/simdv2/cmd/commands.go | 3 +- simapp/v2/simdv2/cmd/root_di.go | 39 ++++++++++------------ simapp/v2/simdv2/cmd/testnet.go | 4 +-- x/genutil/v2/types.go | 9 ----- 11 files changed, 82 insertions(+), 68 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index a5e7a729457b..534cffa75662 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -18,7 +18,7 @@ "request": "launch", "mode": "debug", "program": "${workspaceFolder}/simapp/v2/simdv2", - "args": ["start"], + "args": ["config", "home"], "buildFlags": "" }, { diff --git a/scripts/init-simapp-v2.sh b/scripts/init-simapp-v2.sh index 7410b2174746..3997d56db04c 100755 --- a/scripts/init-simapp-v2.sh +++ b/scripts/init-simapp-v2.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -x SIMD_BIN=${SIMD_BIN:=$(which simdv2 2>/dev/null)} diff --git a/server/v2/api/grpc/server.go b/server/v2/api/grpc/server.go index 2be30b565ed3..4768b74ca1c8 100644 --- a/server/v2/api/grpc/server.go +++ b/server/v2/api/grpc/server.go @@ -80,9 +80,13 @@ func New[T transaction.Tx]( return srv, nil } -func (s *Server[T]) WithConfigOptions(opts ...CfgOption) *Server[T] { - s.cfgOptions = append(s.cfgOptions, opts...) - return s +// NewWithConfigOptions creates a new GRPC server with the provided config options. +// It is *not* a fully functional server (since it has been created without dependencies) +// The returned server should only be used to get and set configuration. +func NewWithConfigOptions[T transaction.Tx](opts ...CfgOption) *Server[T] { + return &Server[T]{ + cfgOptions: opts, + } } func (s *Server[T]) StartCmdFlags() *pflag.FlagSet { diff --git a/server/v2/api/rest/server.go b/server/v2/api/rest/server.go index 1c508a2bcdea..327ec9d0d69b 100644 --- a/server/v2/api/rest/server.go +++ b/server/v2/api/rest/server.go @@ -51,6 +51,15 @@ func New[T transaction.Tx]( return srv, nil } +// NewWithConfigOptions creates a new REST server with the provided config options. +// It is *not* a fully functional server (since it has been created without dependencies) +// The returned server should only be used to get and set configuration. +func NewWithConfigOptions[T transaction.Tx](opts ...CfgOption) *Server[T] { + return &Server[T]{ + cfgOptions: opts, + } +} + func (s *Server[T]) Name() string { return ServerName } @@ -85,11 +94,6 @@ func (s *Server[T]) Stop(ctx context.Context) error { return s.httpServer.Shutdown(ctx) } -func (s *Server[T]) WithConfigOptions(opts ...CfgOption) *Server[T] { - s.cfgOptions = append(s.cfgOptions, opts...) - return s -} - func (s *Server[T]) Config() any { if s.config == nil || s.config.Address == "" { cfg := DefaultConfig() diff --git a/server/v2/api/rest/server_test.go b/server/v2/api/rest/server_test.go index 919d5cace5fe..3fb798979a4b 100644 --- a/server/v2/api/rest/server_test.go +++ b/server/v2/api/rest/server_test.go @@ -25,8 +25,7 @@ func TestServerConfig(t *testing.T) { { name: "Custom configuration", setupFunc: func() *Config { - s := &Server[transaction.Tx]{} - s = s.WithConfigOptions(func(config *Config) { + s := NewWithConfigOptions[transaction.Tx](func(config *Config) { config.Enable = false }) return s.Config().(*Config) diff --git a/server/v2/cometbft/server.go b/server/v2/cometbft/server.go index 3ab3cabbb13f..33f7a31f1ca5 100644 --- a/server/v2/cometbft/server.go +++ b/server/v2/cometbft/server.go @@ -161,9 +161,13 @@ func New[T transaction.Tx]( return srv, nil } -func (s *CometBFTServer[T]) WithConfigOptions(opts ...CfgOption) *CometBFTServer[T] { - s.cfgOptions = append(s.cfgOptions, opts...) - return s +// NewWithConfigOptions creates a new CometBFT server with the provided config options. +// It is *not* a fully functional server (since it has been created without dependencies) +// The returned server should only be used to get and set configuration. +func NewWithConfigOptions[T transaction.Tx](opts ...CfgOption) *CometBFTServer[T] { + return &CometBFTServer[T]{ + cfgOptions: opts, + } } func (s *CometBFTServer[T]) Name() string { diff --git a/server/v2/command_builder.go b/server/v2/command_builder.go index b241db7e5065..f352616e2d3b 100644 --- a/server/v2/command_builder.go +++ b/server/v2/command_builder.go @@ -2,6 +2,7 @@ package serverv2 import ( "errors" + "io" "os" "path/filepath" "strings" @@ -20,7 +21,9 @@ type CommandFactory struct { defaultHomeDir string envPrefix string configWriter ConfigWriter - logger log.Logger + loggerFactory func(server.ConfigMap, io.Writer) (log.Logger, error) + + logger log.Logger // TODO remove this field // this viper handle is kept because certain commands in server/v2 fetch a viper instance // from the command context in order to read the config. @@ -96,11 +99,10 @@ func WithConfigWriter(configWriter ConfigWriter) CommandFactoryOption { } } -// SetLogger sets the logger for the command factory. -// If set the logger will be set in the command context in EnhanceCommand. -func WithLogger(logger log.Logger) CommandFactoryOption { +// WithLoggerFactory sets the logger factory for the command factory. +func WithLoggerFactory(loggerFactory func(server.ConfigMap, io.Writer) (log.Logger, error)) CommandFactoryOption { return func(f *CommandFactory) error { - f.logger = logger + f.loggerFactory = loggerFactory return nil } } @@ -113,7 +115,6 @@ func WithLogger(logger log.Logger) CommandFactoryOption { // --home: directory for config and data // // It also sets the environment variable prefix for the viper instance. -// It sets the logger and viper in the command context (if present) func (f *CommandFactory) EnhanceCommand(cmd *cobra.Command) { pflags := cmd.PersistentFlags() pflags.String(FlagLogLevel, "info", "The logging level (trace|debug|info|warn|error|fatal|panic|disabled or '*:,:')") @@ -123,47 +124,61 @@ func (f *CommandFactory) EnhanceCommand(cmd *cobra.Command) { viper.SetEnvPrefix(f.envPrefix) viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_")) viper.AutomaticEnv() - if f.vipr != nil && f.logger != nil { - SetCmdServerContext(cmd, f.vipr, f.logger) - } } -// ParseCommand parses args against the input rootCmd CLI skeleton then returns the target subcommand and -// a fully realized config map. +// EnhanceCommandContext sets the viper and logger in the command context. +func (f *CommandFactory) EnhanceCommandContext(cmd *cobra.Command) { + SetCmdServerContext(cmd, f.vipr, f.logger) +} + +// ParseCommand parses args against the input rootCmd CLI skeleton then returns the target subcommand, +// a fully realized config map, and a properly configured logger. // If `WithConfigWriter` was set in the factory options, the config writer will be used to write the app.toml file. -func (f *CommandFactory) ParseCommand(rootCmd *cobra.Command, args []string) (*cobra.Command, server.ConfigMap, error) { +// Internally a viper instance is created and used to bind the flags to the config map. +// Future invocations of EnhanceCommandContext will set the viper instance and logger in the command context. +func (f *CommandFactory) ParseCommand( + rootCmd *cobra.Command, + args []string, +) (*cobra.Command, server.ConfigMap, log.Logger, error) { f.EnhanceCommand(rootCmd) cmd, _, err := rootCmd.Traverse(args) if err != nil { - return nil, nil, err + return nil, nil, nil, err } if err = cmd.ParseFlags(args); err != nil { // help requested, return the command early if errors.Is(err, pflag.ErrHelp) { - return cmd, nil, nil + return cmd, nil, nil, nil } - return nil, nil, err + return nil, nil, nil, err } home, err := cmd.Flags().GetString(FlagHome) if err != nil { - return nil, nil, err + return nil, nil, nil, err } configDir := filepath.Join(home, "config") if f.configWriter != nil { // create app.toml if it does not already exist if _, err = os.Stat(filepath.Join(configDir, "app.toml")); os.IsNotExist(err) { if err = f.configWriter.WriteConfig(configDir); err != nil { - return nil, nil, err + return nil, nil, nil, err } } } f.vipr, err = ReadConfig(configDir) if err != nil { - return nil, nil, err + return nil, nil, nil, err } if err = f.vipr.BindPFlags(cmd.Flags()); err != nil { - return nil, nil, err + return nil, nil, nil, err + } + + if f.loggerFactory != nil { + f.logger, err = f.loggerFactory(f.vipr.AllSettings(), cmd.OutOrStdout()) + if err != nil { + return nil, nil, nil, err + } } - return cmd, f.vipr.AllSettings(), nil + return cmd, f.vipr.AllSettings(), f.logger, nil } diff --git a/simapp/v2/simdv2/cmd/commands.go b/simapp/v2/simdv2/cmd/commands.go index 7eb9f50ebdbd..7d5db1c258c4 100644 --- a/simapp/v2/simdv2/cmd/commands.go +++ b/simapp/v2/simdv2/cmd/commands.go @@ -66,8 +66,7 @@ func initRootCmd[T transaction.Tx]( // build CLI skeleton for initial config parsing or a client application invocation if deps.simApp == nil { if deps.consensusComponent == nil { - comet := &cometbft.CometBFTServer[T]{} - deps.consensusComponent = comet.WithConfigOptions(initCometConfig()) + deps.consensusComponent = cometbft.NewWithConfigOptions[T](initCometConfig()) } return serverv2.AddCommands[T]( rootCmd, diff --git a/simapp/v2/simdv2/cmd/root_di.go b/simapp/v2/simdv2/cmd/root_di.go index 179a1412728d..793bb72bc041 100644 --- a/simapp/v2/simdv2/cmd/root_di.go +++ b/simapp/v2/simdv2/cmd/root_di.go @@ -19,24 +19,25 @@ import ( func NewRootCmd[T transaction.Tx]( args ...string, ) (*cobra.Command, error) { - cmd := &cobra.Command{Use: "simdv2", SilenceErrors: true} - configWriter, err := initRootCmd(cmd, log.NewNopLogger(), commandDependencies[T]{}) + rootCommand := &cobra.Command{ + Use: "simdv2", + SilenceErrors: true, + } + configWriter, err := initRootCmd(rootCommand, log.NewNopLogger(), commandDependencies[T]{}) if err != nil { return nil, err } - stdHomeDirOption := serverv2.WithStdDefaultHomeDir(".simappv2") - factory, err := serverv2.NewCommandFactory(serverv2.WithConfigWriter(configWriter), stdHomeDirOption) + factory, err := serverv2.NewCommandFactory( + serverv2.WithConfigWriter(configWriter), + serverv2.WithStdDefaultHomeDir(".simappv2"), + serverv2.WithLoggerFactory(serverv2.NewLogger), + ) if err != nil { return nil, err } // returns the target subcommand and a fully realized config map - subCommand, configMap, err := factory.ParseCommand(cmd, args) - if err != nil { - return nil, err - } - // create default logger - logger, err := serverv2.NewLogger(configMap, cmd.OutOrStdout()) + subCommand, configMap, logger, err := factory.ParseCommand(rootCommand, args) if err != nil { return nil, err } @@ -75,23 +76,19 @@ func NewRootCmd[T transaction.Tx]( } } - rootCommand := &cobra.Command{ - Use: "simdv2", - Short: "simulation app", - PersistentPreRunE: rootCommandPersistentPreRun(clientCtx), - } - factory, err = serverv2.NewCommandFactory(stdHomeDirOption, serverv2.WithLogger(logger)) - if err != nil { - return nil, err - } - factory.EnhanceCommand(rootCommand) - commandDeps := commandDependencies[T]{ globalAppConfig: configMap, txConfig: clientCtx.TxConfig, moduleManager: moduleManager, simApp: simApp, } + rootCommand = &cobra.Command{ + Use: "simdv2", + Short: "simulation app", + SilenceErrors: true, + PersistentPreRunE: rootCommandPersistentPreRun(clientCtx), + } + factory.EnhanceCommandContext(rootCommand) _, err = initRootCmd(rootCommand, logger, commandDeps) if err != nil { return nil, err diff --git a/simapp/v2/simdv2/cmd/testnet.go b/simapp/v2/simdv2/cmd/testnet.go index d51a90249668..46a19c039c86 100644 --- a/simapp/v2/simdv2/cmd/testnet.go +++ b/simapp/v2/simdv2/cmd/testnet.go @@ -335,9 +335,9 @@ func initTestnetFiles[T transaction.Tx]( serverCfg := serverv2.DefaultServerConfig() serverCfg.MinGasPrices = args.minGasPrices - cometServer := (&cometbft.CometBFTServer[T]{}).WithConfigOptions(cometbft.OverwriteDefaultConfigTomlConfig(nodeConfig)) + cometServer := cometbft.NewWithConfigOptions[T](cometbft.OverwriteDefaultConfigTomlConfig(nodeConfig)) storeServer := &store.Server[T]{} - grpcServer := (&grpc.Server[T]{}).WithConfigOptions(grpc.OverwriteDefaultConfig(grpcConfig)) + grpcServer := grpc.NewWithConfigOptions[T](grpc.OverwriteDefaultConfig(grpcConfig)) server := serverv2.NewServer[T](serverCfg, cometServer, storeServer, grpcServer) err = server.WriteConfig(filepath.Join(nodeDir, "config")) if err != nil { diff --git a/x/genutil/v2/types.go b/x/genutil/v2/types.go index fbf288365a57..1509f09f59b8 100644 --- a/x/genutil/v2/types.go +++ b/x/genutil/v2/types.go @@ -1,20 +1,11 @@ package v2 import ( - "context" "encoding/json" sdk "github.com/cosmos/cosmos-sdk/types" ) -// AppExporter is a function that dumps all app state to -// JSON-serializable structure and returns the current validator set. -type AppExporter func( - ctx context.Context, - height int64, - jailAllowedAddrs []string, -) (ExportedApp, error) - // ExportedApp represents an exported app state, along with // validators, consensus params and latest app height. type ExportedApp struct { From 94d30f51e9f6df15bf81909502e532d583e7ab5f Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Fri, 25 Oct 2024 17:51:30 -0500 Subject: [PATCH 28/46] rm redundant --- simapp/v2/simdv2/cmd/root_di.go | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/simapp/v2/simdv2/cmd/root_di.go b/simapp/v2/simdv2/cmd/root_di.go index 793bb72bc041..a615a3155df8 100644 --- a/simapp/v2/simdv2/cmd/root_di.go +++ b/simapp/v2/simdv2/cmd/root_di.go @@ -43,19 +43,20 @@ func NewRootCmd[T transaction.Tx]( } var ( - autoCliOpts autocli.AppOptions - moduleManager *runtime.MM[T] - clientCtx client.Context - simApp *simapp.SimApp[T] - ) - if isAppRequired(subCommand) { - // server construction - simApp, err = simapp.NewSimApp[T]( + autoCliOpts autocli.AppOptions + moduleManager *runtime.MM[T] + clientCtx client.Context + simApp *simapp.SimApp[T] + depinjectConfig = depinject.Configs( depinject.Configs( depinject.Supply(logger, runtime.GlobalConfig(configMap)), depinject.Provide(ProvideClientContext), ), - &autoCliOpts, &moduleManager, &clientCtx) + ) + ) + if isAppRequired(subCommand) { + // server construction + simApp, err = simapp.NewSimApp[T](depinjectConfig, &autoCliOpts, &moduleManager, &clientCtx) if err != nil { return nil, err } @@ -64,11 +65,7 @@ func NewRootCmd[T transaction.Tx]( if err = depinject.Inject( depinject.Configs( simapp.AppConfig(), - depinject.Provide(ProvideClientContext), - depinject.Supply( - logger, - runtime.GlobalConfig(configMap), - ), + depinjectConfig, ), &autoCliOpts, &moduleManager, &clientCtx, ); err != nil { From ff0fa66112e74a9530acea1ee1d341e49946f1b0 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Fri, 25 Oct 2024 17:53:01 -0500 Subject: [PATCH 29/46] revert .vscode change --- .vscode/launch.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 534cffa75662..a5e7a729457b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -18,7 +18,7 @@ "request": "launch", "mode": "debug", "program": "${workspaceFolder}/simapp/v2/simdv2", - "args": ["config", "home"], + "args": ["start"], "buildFlags": "" }, { From 9e60b5ee8323811b595595cf538ead64d059ae59 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Fri, 25 Oct 2024 17:59:14 -0500 Subject: [PATCH 30/46] add call --- simapp/v2/app_di.go | 2 +- simapp/v2/simdv2/cmd/root_di.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/simapp/v2/app_di.go b/simapp/v2/app_di.go index 0191fcbe2d51..87500cdc3210 100644 --- a/simapp/v2/app_di.go +++ b/simapp/v2/app_di.go @@ -178,7 +178,7 @@ func NewSimApp[T transaction.Tx]( app.store = storeBuilder.Get() if app.store == nil { - return nil, fmt.Errorf("store builder not return a db") + return nil, fmt.Errorf("store builder did not return a db") } /**** Module Options ****/ diff --git a/simapp/v2/simdv2/cmd/root_di.go b/simapp/v2/simdv2/cmd/root_di.go index a615a3155df8..27b778bd491f 100644 --- a/simapp/v2/simdv2/cmd/root_di.go +++ b/simapp/v2/simdv2/cmd/root_di.go @@ -85,6 +85,7 @@ func NewRootCmd[T transaction.Tx]( SilenceErrors: true, PersistentPreRunE: rootCommandPersistentPreRun(clientCtx), } + factory.EnhanceCommand(rootCommand) factory.EnhanceCommandContext(rootCommand) _, err = initRootCmd(rootCommand, logger, commandDeps) if err != nil { From 3a8351691ead8aef3812167bc68d6b46d31bc2b9 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Fri, 25 Oct 2024 17:59:57 -0500 Subject: [PATCH 31/46] rm comment --- simapp/v2/simdv2/cmd/root_di.go | 1 - 1 file changed, 1 deletion(-) diff --git a/simapp/v2/simdv2/cmd/root_di.go b/simapp/v2/simdv2/cmd/root_di.go index 27b778bd491f..18414cedf254 100644 --- a/simapp/v2/simdv2/cmd/root_di.go +++ b/simapp/v2/simdv2/cmd/root_di.go @@ -36,7 +36,6 @@ func NewRootCmd[T transaction.Tx]( return nil, err } - // returns the target subcommand and a fully realized config map subCommand, configMap, logger, err := factory.ParseCommand(rootCommand, args) if err != nil { return nil, err From b21b82502095af8d60380854727b2af08430ddcf Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Fri, 25 Oct 2024 18:00:19 -0500 Subject: [PATCH 32/46] rm verbose --- scripts/init-simapp-v2.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/init-simapp-v2.sh b/scripts/init-simapp-v2.sh index 3997d56db04c..7410b2174746 100755 --- a/scripts/init-simapp-v2.sh +++ b/scripts/init-simapp-v2.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash -set -x SIMD_BIN=${SIMD_BIN:=$(which simdv2 2>/dev/null)} From ce56ae9ff1621f9e36695c764928779e150b77d5 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Mon, 28 Oct 2024 09:44:30 -0500 Subject: [PATCH 33/46] rm annotation, add helper command to server/v2 --- server/v2/commands.go | 38 +++++++++++++++++++++++++++++---- simapp/v2/simdv2/cmd/config.go | 30 -------------------------- simapp/v2/simdv2/cmd/root_di.go | 2 +- x/genutil/v2/cli/export.go | 7 +++--- 4 files changed, 38 insertions(+), 39 deletions(-) diff --git a/server/v2/commands.go b/server/v2/commands.go index 544e18a83553..02a1b498c5af 100644 --- a/server/v2/commands.go +++ b/server/v2/commands.go @@ -6,6 +6,7 @@ import ( "os" "os/signal" "runtime/pprof" + "slices" "strings" "syscall" @@ -31,7 +32,6 @@ func AddCommands[T transaction.Tx]( srv := NewServer(globalServerConfig, components...) cmds := srv.CLICommands() startCmd := createStartCommand(srv, globalAppConfig, logger) - // TODO necessary? won't the parent context be inherited? startCmd.SetContext(rootCmd.Context()) cmds.Commands = append(cmds.Commands, startCmd) rootCmd.AddCommand(cmds.Commands...) @@ -69,9 +69,8 @@ func createStartCommand[T transaction.Tx]( flags := server.StartFlags() cmd := &cobra.Command{ - Use: "start", - Short: "Run the application", - Annotations: map[string]string{"needs-app": "true"}, + Use: "start", + Short: "Run the application", RunE: func(cmd *cobra.Command, args []string) error { ctx, cancelFn := context.WithCancel(cmd.Context()) go func() { @@ -170,3 +169,34 @@ func topLevelCmd(ctx context.Context, use, short string) *cobra.Command { return cmd } + +// appBuildingCommands are the commands which need a full application to be built +var appBuildingCommands = [][]string{ + {"start"}, + {"genesis", "export"}, +} + +// IsAppRequired returns true if the command requires a full app to be built +// by recursively checking the `Use` property of `cmd` and its parents. +// By default, the commands in `appBuildingCommands` are considered to require +// a full app to be built. They are "start" and "genesis export". +// Additional commands can be passed as arguments to this function. +func IsAppRequired(cmd *cobra.Command, required ...[]string) bool { + m := map[string]bool{} + cmds := append(appBuildingCommands, required...) + for _, c := range cmds { + slices.Reverse(c) + m[strings.Join(c, "")] = true + } + cmdPath := make([]string, 0, 5) // Pre-allocate with reasonable capacity + for { + cmdPath = append(cmdPath, cmd.Use) + if _, ok := m[strings.Join(cmdPath, "")]; ok { + return true + } + if cmd.Parent() == nil { + return false + } + cmd = cmd.Parent() + } +} diff --git a/simapp/v2/simdv2/cmd/config.go b/simapp/v2/simdv2/cmd/config.go index be82d9edf564..16cb19db93e7 100644 --- a/simapp/v2/simdv2/cmd/config.go +++ b/simapp/v2/simdv2/cmd/config.go @@ -1,12 +1,10 @@ package cmd import ( - "slices" "strings" "time" cmtcfg "github.com/cometbft/cometbft/config" - "github.com/spf13/cobra" "cosmossdk.io/core/transaction" serverv2 "cosmossdk.io/server/v2" @@ -106,31 +104,3 @@ func initCometOptions[T transaction.Tx]() cometbft.ServerOptions[T] { return serverOptions } - -// appBuildingCommands are the commands which need a full SimApp to be built -var appBuildingCommands = [][]string{ - {"start"}, - {"genesis", "export"}, -} - -// isAppRequired returns true if the command requires a full app to be built -// by recursively checking the command and its parents, and comparing it with -// the appBuildingCommands. -func isAppRequired(cmd *cobra.Command) bool { - m := map[string]bool{} - for _, c := range appBuildingCommands { - slices.Reverse(c) - m[strings.Join(c, "")] = true - } - cmdPath := make([]string, 0, 5) // Pre-allocate with reasonable capacity - for { - cmdPath = append(cmdPath, cmd.Use) - if _, ok := m[strings.Join(cmdPath, "")]; ok { - return true - } - if cmd.Parent() == nil { - return false - } - cmd = cmd.Parent() - } -} diff --git a/simapp/v2/simdv2/cmd/root_di.go b/simapp/v2/simdv2/cmd/root_di.go index 18414cedf254..b8abed3d85d7 100644 --- a/simapp/v2/simdv2/cmd/root_di.go +++ b/simapp/v2/simdv2/cmd/root_di.go @@ -53,7 +53,7 @@ func NewRootCmd[T transaction.Tx]( ), ) ) - if isAppRequired(subCommand) { + if serverv2.IsAppRequired(subCommand) { // server construction simApp, err = simapp.NewSimApp[T](depinjectConfig, &autoCliOpts, &moduleManager, &clientCtx) if err != nil { diff --git a/x/genutil/v2/cli/export.go b/x/genutil/v2/cli/export.go index 7802b062bf1e..c53236d49329 100644 --- a/x/genutil/v2/cli/export.go +++ b/x/genutil/v2/cli/export.go @@ -23,10 +23,9 @@ const ( // ExportCmd dumps app state to JSON. func ExportCmd(app ExportableApp) *cobra.Command { cmd := &cobra.Command{ - Use: "export", - Short: "Export state to JSON", - Args: cobra.NoArgs, - Annotations: map[string]string{"needs-app": "true"}, + Use: "export", + Short: "Export state to JSON", + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, _ []string) error { config := client.GetConfigFromCmd(cmd) From d3bb0c331ba5a6c3750598c49f43ee27ec0697d7 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Mon, 28 Oct 2024 09:49:08 -0500 Subject: [PATCH 34/46] rf remove redudnancy --- server/v2/command_builder.go | 7 ++++--- simapp/v2/simdv2/cmd/root_di.go | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/server/v2/command_builder.go b/server/v2/command_builder.go index f352616e2d3b..9176cb57cff7 100644 --- a/server/v2/command_builder.go +++ b/server/v2/command_builder.go @@ -115,7 +115,7 @@ func WithLoggerFactory(loggerFactory func(server.ConfigMap, io.Writer) (log.Logg // --home: directory for config and data // // It also sets the environment variable prefix for the viper instance. -func (f *CommandFactory) EnhanceCommand(cmd *cobra.Command) { +func (f *CommandFactory) enhanceCommand(cmd *cobra.Command) { pflags := cmd.PersistentFlags() pflags.String(FlagLogLevel, "info", "The logging level (trace|debug|info|warn|error|fatal|panic|disabled or '*:,:')") pflags.String(FlagLogFormat, "plain", "The logging format (json|plain)") @@ -127,7 +127,8 @@ func (f *CommandFactory) EnhanceCommand(cmd *cobra.Command) { } // EnhanceCommandContext sets the viper and logger in the command context. -func (f *CommandFactory) EnhanceCommandContext(cmd *cobra.Command) { +func (f *CommandFactory) EnchanceRootCommand(cmd *cobra.Command) { + f.enhanceCommand(cmd) SetCmdServerContext(cmd, f.vipr, f.logger) } @@ -140,7 +141,7 @@ func (f *CommandFactory) ParseCommand( rootCmd *cobra.Command, args []string, ) (*cobra.Command, server.ConfigMap, log.Logger, error) { - f.EnhanceCommand(rootCmd) + f.enhanceCommand(rootCmd) cmd, _, err := rootCmd.Traverse(args) if err != nil { return nil, nil, nil, err diff --git a/simapp/v2/simdv2/cmd/root_di.go b/simapp/v2/simdv2/cmd/root_di.go index b8abed3d85d7..d13fab18b16e 100644 --- a/simapp/v2/simdv2/cmd/root_di.go +++ b/simapp/v2/simdv2/cmd/root_di.go @@ -84,8 +84,7 @@ func NewRootCmd[T transaction.Tx]( SilenceErrors: true, PersistentPreRunE: rootCommandPersistentPreRun(clientCtx), } - factory.EnhanceCommand(rootCommand) - factory.EnhanceCommandContext(rootCommand) + factory.EnchanceRootCommand(rootCommand) _, err = initRootCmd(rootCommand, logger, commandDeps) if err != nil { return nil, err From c48172de4bb656e3259a31d715fd61920778ecf7 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Mon, 28 Oct 2024 10:15:32 -0500 Subject: [PATCH 35/46] typos --- server/v2/command_builder.go | 4 ++-- simapp/v2/simdv2/cmd/root_di.go | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/server/v2/command_builder.go b/server/v2/command_builder.go index 9176cb57cff7..1344546e24e5 100644 --- a/server/v2/command_builder.go +++ b/server/v2/command_builder.go @@ -28,7 +28,7 @@ type CommandFactory struct { // this viper handle is kept because certain commands in server/v2 fetch a viper instance // from the command context in order to read the config. // After merging #22267 this is no longer required, and server.ConfigMap can be used instead. - // See issue # + // See issue #22388 vipr *viper.Viper } @@ -127,7 +127,7 @@ func (f *CommandFactory) enhanceCommand(cmd *cobra.Command) { } // EnhanceCommandContext sets the viper and logger in the command context. -func (f *CommandFactory) EnchanceRootCommand(cmd *cobra.Command) { +func (f *CommandFactory) EnhanceRootCommand(cmd *cobra.Command) { f.enhanceCommand(cmd) SetCmdServerContext(cmd, f.vipr, f.logger) } diff --git a/simapp/v2/simdv2/cmd/root_di.go b/simapp/v2/simdv2/cmd/root_di.go index d13fab18b16e..37f818dc8ea1 100644 --- a/simapp/v2/simdv2/cmd/root_di.go +++ b/simapp/v2/simdv2/cmd/root_di.go @@ -47,10 +47,8 @@ func NewRootCmd[T transaction.Tx]( clientCtx client.Context simApp *simapp.SimApp[T] depinjectConfig = depinject.Configs( - depinject.Configs( - depinject.Supply(logger, runtime.GlobalConfig(configMap)), - depinject.Provide(ProvideClientContext), - ), + depinject.Supply(logger, runtime.GlobalConfig(configMap)), + depinject.Provide(ProvideClientContext), ) ) if serverv2.IsAppRequired(subCommand) { @@ -84,7 +82,7 @@ func NewRootCmd[T transaction.Tx]( SilenceErrors: true, PersistentPreRunE: rootCommandPersistentPreRun(clientCtx), } - factory.EnchanceRootCommand(rootCommand) + factory.EnhanceRootCommand(rootCommand) _, err = initRootCmd(rootCommand, logger, commandDeps) if err != nil { return nil, err From 9addef4ecc9d7f1b20a4efe6b95bff77ad0efaec Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Mon, 28 Oct 2024 10:51:04 -0500 Subject: [PATCH 36/46] minor cleanup --- server/v2/commands.go | 17 +++++++++++------ simapp/v2/simdv2/cmd/commands.go | 4 ++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/server/v2/commands.go b/server/v2/commands.go index 02a1b498c5af..aab0e8eb3667 100644 --- a/server/v2/commands.go +++ b/server/v2/commands.go @@ -176,13 +176,18 @@ var appBuildingCommands = [][]string{ {"genesis", "export"}, } -// IsAppRequired returns true if the command requires a full app to be built -// by recursively checking the `Use` property of `cmd` and its parents. -// By default, the commands in `appBuildingCommands` are considered to require -// a full app to be built. They are "start" and "genesis export". -// Additional commands can be passed as arguments to this function. +// IsAppRequired determines if a command requires a full application to be built by +// recursively checking the command hierarchy against known command paths. +// +// The function works by: +// 1. Combining default appBuildingCommands with additional required commands +// 2. Building command paths by traversing up the command tree +// 3. Checking if any known command path matches the current command path +// +// Time Complexity: O(d * p) where d is command depth and p is number of paths +// Space Complexity: O(p) where p is total number of command paths func IsAppRequired(cmd *cobra.Command, required ...[]string) bool { - m := map[string]bool{} + m := make(map[string]bool) cmds := append(appBuildingCommands, required...) for _, c := range cmds { slices.Reverse(c) diff --git a/simapp/v2/simdv2/cmd/commands.go b/simapp/v2/simdv2/cmd/commands.go index 7d5db1c258c4..7755d07579b8 100644 --- a/simapp/v2/simdv2/cmd/commands.go +++ b/simapp/v2/simdv2/cmd/commands.go @@ -52,11 +52,11 @@ func initRootCmd[T transaction.Tx]( rootCmd.AddCommand( genutilcli.InitCmd(deps.moduleManager), + genesisCommand(deps.moduleManager, deps.simApp), + NewTestnetCmd(deps.moduleManager), debug.Cmd(), confixcmd.ConfigCommand(), - NewTestnetCmd(deps.moduleManager), // add keybase, auxiliary RPC, query, genesis, and tx child commands - genesisCommand(deps.moduleManager, deps.simApp), queryCommand(), txCommand(), keys.Commands(), From e9c4005a3cf500d7e118faf64f9ff45dbcc74f83 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Mon, 28 Oct 2024 11:05:45 -0500 Subject: [PATCH 37/46] export two functions --- simapp/v2/simdv2/cmd/commands.go | 8 ++++---- simapp/v2/simdv2/cmd/root_di.go | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/simapp/v2/simdv2/cmd/commands.go b/simapp/v2/simdv2/cmd/commands.go index 7755d07579b8..a1882f0fd052 100644 --- a/simapp/v2/simdv2/cmd/commands.go +++ b/simapp/v2/simdv2/cmd/commands.go @@ -32,9 +32,9 @@ import ( v2 "github.com/cosmos/cosmos-sdk/x/genutil/v2/cli" ) -// commandDependencies is a struct that contains all the dependencies needed to initialize the root command. +// CommandDependencies is a struct that contains all the dependencies needed to initialize the root command. // an alternative design could fetch these even later from the command context -type commandDependencies[T transaction.Tx] struct { +type CommandDependencies[T transaction.Tx] struct { globalAppConfig coreserver.ConfigMap txConfig client.TxConfig moduleManager *runtimev2.MM[T] @@ -42,10 +42,10 @@ type commandDependencies[T transaction.Tx] struct { consensusComponent serverv2.ServerComponent[T] } -func initRootCmd[T transaction.Tx]( +func InitRootCmd[T transaction.Tx]( rootCmd *cobra.Command, logger log.Logger, - deps commandDependencies[T], + deps CommandDependencies[T], ) (serverv2.ConfigWriter, error) { cfg := sdk.GetConfig() cfg.Seal() diff --git a/simapp/v2/simdv2/cmd/root_di.go b/simapp/v2/simdv2/cmd/root_di.go index 37f818dc8ea1..8a16310c45ec 100644 --- a/simapp/v2/simdv2/cmd/root_di.go +++ b/simapp/v2/simdv2/cmd/root_di.go @@ -23,7 +23,7 @@ func NewRootCmd[T transaction.Tx]( Use: "simdv2", SilenceErrors: true, } - configWriter, err := initRootCmd(rootCommand, log.NewNopLogger(), commandDependencies[T]{}) + configWriter, err := InitRootCmd(rootCommand, log.NewNopLogger(), CommandDependencies[T]{}) if err != nil { return nil, err } @@ -70,7 +70,7 @@ func NewRootCmd[T transaction.Tx]( } } - commandDeps := commandDependencies[T]{ + commandDeps := CommandDependencies[T]{ globalAppConfig: configMap, txConfig: clientCtx.TxConfig, moduleManager: moduleManager, @@ -83,7 +83,7 @@ func NewRootCmd[T transaction.Tx]( PersistentPreRunE: rootCommandPersistentPreRun(clientCtx), } factory.EnhanceRootCommand(rootCommand) - _, err = initRootCmd(rootCommand, logger, commandDeps) + _, err = InitRootCmd(rootCommand, logger, commandDeps) if err != nil { return nil, err } From 6d184670f4ca72555baf9e551e9930f2b8afc097 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Mon, 28 Oct 2024 11:20:41 -0500 Subject: [PATCH 38/46] add CODEOWNER entry for server/v2 --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 308c61887003..e360907353d9 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -25,7 +25,7 @@ /runtime/v2/ @julienrbrt @hieuvubk @cosmos/sdk-core-dev /schema/ @aaronc @testinginprod @cosmos/sdk-core-dev /server/ @cosmos/sdk-core-dev -/server/v2/ @julienrbrt @hieuvubk @cosmos/sdk-core-dev +/server/v2/ @julienrbrt @hieuvubk @kocubinski @cosmos/sdk-core-dev /server/v2/stf/ @testinginprod @kocubinski @cosmos/sdk-core-dev /server/v2/appmanager/ @testinginprod @facundomedica @cosmos/sdk-core-dev /server/v2/cometbft/ @facundomedica @sontrinh16 @cosmos/sdk-core-dev From d200520985a1d89c6db5aaf78db50c6349a5df76 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Mon, 28 Oct 2024 13:17:16 -0500 Subject: [PATCH 39/46] add comments --- runtime/v2/config.go | 10 +++++++++- temp.json | 0 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 temp.json diff --git a/runtime/v2/config.go b/runtime/v2/config.go index ef62ddc77ef8..d29481e6ba6d 100644 --- a/runtime/v2/config.go +++ b/runtime/v2/config.go @@ -10,6 +10,10 @@ import ( // 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 @@ -19,7 +23,7 @@ type ModuleConfigMaps map[string]server.ConfigMap // The module config map is a map of flag to value. func ProvideModuleConfigMaps( moduleConfigs []server.ModuleConfigMap, - globalConfig GlobalConfig, + globalConfig server.ConfigMap, ) ModuleConfigMaps { moduleConfigMaps := make(ModuleConfigMaps) for _, moduleConfig := range moduleConfigs { @@ -29,6 +33,10 @@ func ProvideModuleConfigMaps( 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) diff --git a/temp.json b/temp.json new file mode 100644 index 000000000000..e69de29bb2d1 From 13d97714ac9b38eb5f57cf7a9665c4d89a36edf4 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Mon, 28 Oct 2024 13:19:43 -0500 Subject: [PATCH 40/46] mv helper fn --- simapp/v2/app_di.go | 16 ---------------- simapp/v2/app_test.go | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/simapp/v2/app_di.go b/simapp/v2/app_di.go index 87500cdc3210..16ac2a30cba2 100644 --- a/simapp/v2/app_di.go +++ b/simapp/v2/app_di.go @@ -4,8 +4,6 @@ import ( _ "embed" "fmt" - "github.com/spf13/viper" - clienthelpers "cosmossdk.io/client/v2/helpers" "cosmossdk.io/core/registry" "cosmossdk.io/core/server" @@ -192,20 +190,6 @@ func NewSimApp[T transaction.Tx]( return app, nil } -// NewSimAppWithInputs returns a reference to an initialized SimApp. -func NewSimAppWithInputs[T transaction.Tx]( - logger log.Logger, - viper *viper.Viper, -) *SimApp[T] { - app, err := NewSimApp[T](depinject.Configs( - depinject.Supply(logger, runtime.GlobalConfig(viper.AllSettings()))), - ) - if err != nil { - panic(err) - } - return app -} - // AppCodec returns SimApp's app codec. // // NOTE: This is solely to be used for testing purposes as it may be desirable diff --git a/simapp/v2/app_test.go b/simapp/v2/app_test.go index 80805abc7f36..82d3361c6443 100644 --- a/simapp/v2/app_test.go +++ b/simapp/v2/app_test.go @@ -16,8 +16,10 @@ import ( "cosmossdk.io/core/server" "cosmossdk.io/core/store" "cosmossdk.io/core/transaction" + "cosmossdk.io/depinject" "cosmossdk.io/log" sdkmath "cosmossdk.io/math" + "cosmossdk.io/runtime/v2" serverv2 "cosmossdk.io/server/v2" serverv2store "cosmossdk.io/server/v2/store" "cosmossdk.io/store/v2/db" @@ -39,7 +41,7 @@ func NewTestApp(t *testing.T) (*SimApp[transaction.Tx], context.Context) { vp.Set(serverv2store.FlagAppDBBackend, string(db.DBTypeGoLevelDB)) vp.Set(serverv2.FlagHome, t.TempDir()) - app := NewSimAppWithInputs[transaction.Tx](logger, vp) + app := newSimAppWithInputs[transaction.Tx](logger, vp) genesis := app.ModuleManager().DefaultGenesis() privVal := mock.NewPV() @@ -103,6 +105,20 @@ func NewTestApp(t *testing.T) (*SimApp[transaction.Tx], context.Context) { return app, ctx } +// newSimAppWithInputs returns a reference to an initialized SimApp. +func newSimAppWithInputs[T transaction.Tx]( + logger log.Logger, + viper *viper.Viper, +) *SimApp[T] { + app, err := NewSimApp[T](depinject.Configs( + depinject.Supply(logger, runtime.GlobalConfig(viper.AllSettings()))), + ) + if err != nil { + panic(err) + } + return app +} + func MoveNextBlock(t *testing.T, app *SimApp[transaction.Tx], ctx context.Context) { t.Helper() From 1cadeeb071cc0ed87d8bf4323f640b42e3dabf70 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Mon, 28 Oct 2024 13:21:15 -0500 Subject: [PATCH 41/46] rm helper fn --- simapp/v2/app_test.go | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/simapp/v2/app_test.go b/simapp/v2/app_test.go index 82d3361c6443..c3c51489a7e5 100644 --- a/simapp/v2/app_test.go +++ b/simapp/v2/app_test.go @@ -41,7 +41,11 @@ func NewTestApp(t *testing.T) (*SimApp[transaction.Tx], context.Context) { vp.Set(serverv2store.FlagAppDBBackend, string(db.DBTypeGoLevelDB)) vp.Set(serverv2.FlagHome, t.TempDir()) - app := newSimAppWithInputs[transaction.Tx](logger, vp) + app, err := NewSimApp[transaction.Tx](depinject.Configs( + depinject.Supply(logger, runtime.GlobalConfig(vp.AllSettings()))), + ) + require.NoError(t, err) + genesis := app.ModuleManager().DefaultGenesis() privVal := mock.NewPV() @@ -105,20 +109,6 @@ func NewTestApp(t *testing.T) (*SimApp[transaction.Tx], context.Context) { return app, ctx } -// newSimAppWithInputs returns a reference to an initialized SimApp. -func newSimAppWithInputs[T transaction.Tx]( - logger log.Logger, - viper *viper.Viper, -) *SimApp[T] { - app, err := NewSimApp[T](depinject.Configs( - depinject.Supply(logger, runtime.GlobalConfig(viper.AllSettings()))), - ) - if err != nil { - panic(err) - } - return app -} - func MoveNextBlock(t *testing.T, app *SimApp[transaction.Tx], ctx context.Context) { t.Helper() From 6472136bc74426bb9bd104d3835b6dba4728948a Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Mon, 28 Oct 2024 13:22:47 -0500 Subject: [PATCH 42/46] fix --- runtime/v2/config.go | 2 +- temp.json | 0 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 temp.json diff --git a/runtime/v2/config.go b/runtime/v2/config.go index d29481e6ba6d..4cddadd7be20 100644 --- a/runtime/v2/config.go +++ b/runtime/v2/config.go @@ -23,7 +23,7 @@ type ModuleConfigMaps map[string]server.ConfigMap // The module config map is a map of flag to value. func ProvideModuleConfigMaps( moduleConfigs []server.ModuleConfigMap, - globalConfig server.ConfigMap, + globalConfig GlobalConfig, ) ModuleConfigMaps { moduleConfigMaps := make(ModuleConfigMaps) for _, moduleConfig := range moduleConfigs { diff --git a/temp.json b/temp.json deleted file mode 100644 index e69de29bb2d1..000000000000 From 9c38df29b6960182237e8457eb525fbd3d0ceea5 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Mon, 28 Oct 2024 13:29:55 -0500 Subject: [PATCH 43/46] grpcgateway fix --- server/v2/api/grpcgateway/server.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/server/v2/api/grpcgateway/server.go b/server/v2/api/grpcgateway/server.go index 3ee58338e3cb..7fba8ce1be20 100644 --- a/server/v2/api/grpcgateway/server.go +++ b/server/v2/api/grpcgateway/server.go @@ -11,6 +11,7 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/runtime" "google.golang.org/grpc" + "cosmossdk.io/core/server" "cosmossdk.io/core/transaction" "cosmossdk.io/log" serverv2 "cosmossdk.io/server/v2" @@ -34,7 +35,13 @@ type Server[T transaction.Tx] struct { } // New creates a new gRPC-gateway server. -func New[T transaction.Tx](grpcSrv *grpc.Server, ir jsonpb.AnyResolver, cfgOptions ...CfgOption) *Server[T] { +func New[T transaction.Tx]( + logger log.Logger, + config server.ConfigMap, + grpcSrv *grpc.Server, + ir jsonpb.AnyResolver, + cfgOptions ...CfgOption, +) (*Server[T], error) { // The default JSON marshaller used by the gRPC-Gateway is unable to marshal non-nullable non-scalar fields. // Using the gogo/gateway package with the gRPC-Gateway WithMarshaler option fixes the scalar field marshaling issue. marshalerOption := &gateway.JSONPb{ @@ -44,7 +51,7 @@ func New[T transaction.Tx](grpcSrv *grpc.Server, ir jsonpb.AnyResolver, cfgOptio AnyResolver: ir, } - return &Server[T]{ + s := &Server[T]{ gRPCSrv: grpcSrv, gRPCGatewayRouter: runtime.NewServeMux( // Custom marshaler option is required for gogo proto @@ -60,6 +67,20 @@ func New[T transaction.Tx](grpcSrv *grpc.Server, ir jsonpb.AnyResolver, cfgOptio ), cfgOptions: cfgOptions, } + + serverCfg := s.Config().(*Config) + if len(config) > 0 { + if err := serverv2.UnmarshalSubConfig(config, s.Name(), &serverCfg); err != nil { + return s, fmt.Errorf("failed to unmarshal config: %w", err) + } + } + + // TODO: register the gRPC-Gateway routes + + s.logger = logger.With(log.ModuleKey, s.Name()) + s.config = serverCfg + + return s, nil } func (s *Server[T]) Name() string { From 7014d0d804f266562c0cdfc584d9bf01196c740c Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Mon, 28 Oct 2024 13:31:05 -0500 Subject: [PATCH 44/46] rename file --- server/v2/{command_builder.go => command_factory.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename server/v2/{command_builder.go => command_factory.go} (100%) diff --git a/server/v2/command_builder.go b/server/v2/command_factory.go similarity index 100% rename from server/v2/command_builder.go rename to server/v2/command_factory.go From 6272619cdb52f75b39bb372c32963eb870e0f661 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Mon, 28 Oct 2024 13:37:47 -0500 Subject: [PATCH 45/46] typos and exports --- server/v2/command_factory.go | 4 +-- simapp/v2/simdv2/cmd/commands.go | 50 ++++++++++++++++---------------- simapp/v2/simdv2/cmd/root_di.go | 10 +++---- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/server/v2/command_factory.go b/server/v2/command_factory.go index 1344546e24e5..a9f544a2f3b8 100644 --- a/server/v2/command_factory.go +++ b/server/v2/command_factory.go @@ -107,7 +107,7 @@ func WithLoggerFactory(loggerFactory func(server.ConfigMap, io.Writer) (log.Logg } } -// EnhanceCommand adds the following flags to the command: +// enhanceCommand adds the following flags to the command: // // --log-level: The logging level (trace|debug|info|warn|error|fatal|panic|disabled or '*:,:') // --log-format: The logging format (json|plain) @@ -126,7 +126,7 @@ func (f *CommandFactory) enhanceCommand(cmd *cobra.Command) { viper.AutomaticEnv() } -// EnhanceCommandContext sets the viper and logger in the command context. +// EnhanceRootCommand sets the viper and logger in the command context. func (f *CommandFactory) EnhanceRootCommand(cmd *cobra.Command) { f.enhanceCommand(cmd) SetCmdServerContext(cmd, f.vipr, f.logger) diff --git a/simapp/v2/simdv2/cmd/commands.go b/simapp/v2/simdv2/cmd/commands.go index a1882f0fd052..c001db4dff92 100644 --- a/simapp/v2/simdv2/cmd/commands.go +++ b/simapp/v2/simdv2/cmd/commands.go @@ -35,11 +35,11 @@ import ( // CommandDependencies is a struct that contains all the dependencies needed to initialize the root command. // an alternative design could fetch these even later from the command context type CommandDependencies[T transaction.Tx] struct { - globalAppConfig coreserver.ConfigMap - txConfig client.TxConfig - moduleManager *runtimev2.MM[T] - simApp *simapp.SimApp[T] - consensusComponent serverv2.ServerComponent[T] + GlobalConfig coreserver.ConfigMap + TxConfig client.TxConfig + ModuleManager *runtimev2.MM[T] + SimApp *simapp.SimApp[T] + Consensus serverv2.ServerComponent[T] } func InitRootCmd[T transaction.Tx]( @@ -51,9 +51,9 @@ func InitRootCmd[T transaction.Tx]( cfg.Seal() rootCmd.AddCommand( - genutilcli.InitCmd(deps.moduleManager), - genesisCommand(deps.moduleManager, deps.simApp), - NewTestnetCmd(deps.moduleManager), + genutilcli.InitCmd(deps.ModuleManager), + genesisCommand(deps.ModuleManager, deps.SimApp), + NewTestnetCmd(deps.ModuleManager), debug.Cmd(), confixcmd.ConfigCommand(), // add keybase, auxiliary RPC, query, genesis, and tx child commands @@ -64,16 +64,16 @@ func InitRootCmd[T transaction.Tx]( ) // build CLI skeleton for initial config parsing or a client application invocation - if deps.simApp == nil { - if deps.consensusComponent == nil { - deps.consensusComponent = cometbft.NewWithConfigOptions[T](initCometConfig()) + if deps.SimApp == nil { + if deps.Consensus == nil { + deps.Consensus = cometbft.NewWithConfigOptions[T](initCometConfig()) } return serverv2.AddCommands[T]( rootCmd, logger, - deps.globalAppConfig, + deps.GlobalConfig, initServerConfig(), - deps.consensusComponent, + deps.Consensus, &grpc.Server[T]{}, &serverstore.Server[T]{}, &telemetry.Server[T]{}, @@ -82,39 +82,39 @@ func InitRootCmd[T transaction.Tx]( } // build full app! - simApp := deps.simApp - grpcServer, err := grpc.New[T](logger, simApp.InterfaceRegistry(), simApp.QueryHandlers(), simApp, deps.globalAppConfig) + simApp := deps.SimApp + grpcServer, err := grpc.New[T](logger, simApp.InterfaceRegistry(), simApp.QueryHandlers(), simApp, deps.GlobalConfig) if err != nil { return nil, err } // store component (not a server) - storeComponent, err := serverstore.New[T](simApp.Store(), deps.globalAppConfig) + storeComponent, err := serverstore.New[T](simApp.Store(), deps.GlobalConfig) if err != nil { return nil, err } - restServer, err := rest.New[T](simApp.App.AppManager, logger, deps.globalAppConfig) + restServer, err := rest.New[T](simApp.App.AppManager, logger, deps.GlobalConfig) if err != nil { return nil, err } // consensus component - if deps.consensusComponent == nil { - deps.consensusComponent, err = cometbft.New( + if deps.Consensus == nil { + deps.Consensus, err = cometbft.New( logger, simApp.Name(), simApp.Store(), simApp.App.AppManager, simApp.App.QueryHandlers(), simApp.App.SchemaDecoderResolver(), - &genericTxDecoder[T]{deps.txConfig}, - deps.globalAppConfig, + &genericTxDecoder[T]{deps.TxConfig}, + deps.GlobalConfig, initCometOptions[T](), ) if err != nil { return nil, err } } - telemetryServer, err := telemetry.New[T](deps.globalAppConfig, logger) + telemetryServer, err := telemetry.New[T](deps.GlobalConfig, logger) if err != nil { return nil, err } @@ -123,9 +123,9 @@ func InitRootCmd[T transaction.Tx]( return serverv2.AddCommands[T]( rootCmd, logger, - deps.globalAppConfig, + deps.GlobalConfig, initServerConfig(), - deps.consensusComponent, + deps.Consensus, grpcServer, storeComponent, telemetryServer, @@ -194,7 +194,7 @@ func txCommand() *cobra.Command { return cmd } -func rootCommandPersistentPreRun(clientCtx client.Context) func(*cobra.Command, []string) error { +func RootCommandPersistentPreRun(clientCtx client.Context) func(*cobra.Command, []string) error { return func(cmd *cobra.Command, args []string) error { // set the default command outputs cmd.SetOut(cmd.OutOrStdout()) diff --git a/simapp/v2/simdv2/cmd/root_di.go b/simapp/v2/simdv2/cmd/root_di.go index 8a16310c45ec..0bbae702becb 100644 --- a/simapp/v2/simdv2/cmd/root_di.go +++ b/simapp/v2/simdv2/cmd/root_di.go @@ -71,16 +71,16 @@ func NewRootCmd[T transaction.Tx]( } commandDeps := CommandDependencies[T]{ - globalAppConfig: configMap, - txConfig: clientCtx.TxConfig, - moduleManager: moduleManager, - simApp: simApp, + GlobalConfig: configMap, + TxConfig: clientCtx.TxConfig, + ModuleManager: moduleManager, + SimApp: simApp, } rootCommand = &cobra.Command{ Use: "simdv2", Short: "simulation app", SilenceErrors: true, - PersistentPreRunE: rootCommandPersistentPreRun(clientCtx), + PersistentPreRunE: RootCommandPersistentPreRun(clientCtx), } factory.EnhanceRootCommand(rootCommand) _, err = InitRootCmd(rootCommand, logger, commandDeps) From e7603cf0843d88fc8e47261b5d9bcf2e3db5c5aa Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Mon, 28 Oct 2024 14:04:31 -0500 Subject: [PATCH 46/46] configurable homedir in ClientCtx, remove global var --- simapp/v2/app_di.go | 12 ------------ simapp/v2/simdv2/cmd/depinject.go | 10 ++++++++-- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/simapp/v2/app_di.go b/simapp/v2/app_di.go index 16ac2a30cba2..5fa97c224161 100644 --- a/simapp/v2/app_di.go +++ b/simapp/v2/app_di.go @@ -4,7 +4,6 @@ import ( _ "embed" "fmt" - clienthelpers "cosmossdk.io/client/v2/helpers" "cosmossdk.io/core/registry" "cosmossdk.io/core/server" "cosmossdk.io/core/transaction" @@ -27,9 +26,6 @@ import ( _ "github.com/cosmos/cosmos-sdk/x/genutil" ) -// DefaultNodeHome default home directories for the application daemon -var DefaultNodeHome string - // SimApp extends an ABCI application, but with most of its parameters exported. // They are exported for convenience in creating helper functions, as object // capabilities aren't needed for testing. @@ -47,14 +43,6 @@ type SimApp[T transaction.Tx] struct { StakingKeeper *stakingkeeper.Keeper } -func init() { - var err error - DefaultNodeHome, err = clienthelpers.GetNodeHomeDirectory(".simappv2") - if err != nil { - panic(err) - } -} - // AppConfig returns the default app config. func AppConfig() depinject.Config { return depinject.Configs( diff --git a/simapp/v2/simdv2/cmd/depinject.go b/simapp/v2/simdv2/cmd/depinject.go index a59c7f1fc2ef..f59140f29399 100644 --- a/simapp/v2/simdv2/cmd/depinject.go +++ b/simapp/v2/simdv2/cmd/depinject.go @@ -5,7 +5,8 @@ import ( "cosmossdk.io/core/address" "cosmossdk.io/core/registry" - "cosmossdk.io/simapp/v2" + "cosmossdk.io/runtime/v2" + serverv2 "cosmossdk.io/server/v2" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/config" @@ -18,6 +19,7 @@ import ( // ProvideClientContext is a depinject Provider function which assembles and returns a client.Context. func ProvideClientContext( + configMap runtime.GlobalConfig, appCodec codec.Codec, interfaceRegistry codectypes.InterfaceRegistry, txConfigOpts tx.ConfigOptions, @@ -31,6 +33,10 @@ func ProvideClientContext( if !ok { panic("registry.AminoRegistrar must be an *codec.LegacyAmino instance for legacy ClientContext") } + homeDir, ok := configMap[serverv2.FlagHome].(string) + if !ok { + panic("server.ConfigMap must contain a string value for serverv2.FlagHome") + } clientCtx := client.Context{}. WithCodec(appCodec). @@ -41,7 +47,7 @@ func ProvideClientContext( WithAddressCodec(addressCodec). WithValidatorAddressCodec(validatorAddressCodec). WithConsensusAddressCodec(consensusAddressCodec). - WithHomeDir(simapp.DefaultNodeHome). + WithHomeDir(homeDir). WithViper("") // uses by default the binary name as prefix // Read the config to overwrite the default values with the values from the config file