From b6fc7787ad15f3c93ad0628747ef1f0888011907 Mon Sep 17 00:00:00 2001 From: itsdevbear Date: Fri, 16 Feb 2024 12:30:27 -0500 Subject: [PATCH 1/7] bet --- client/pruning/main.go | 3 ++- client/snapshot/cmd.go | 3 ++- client/snapshot/export.go | 3 ++- client/snapshot/restore.go | 3 ++- server/cmt_cmds.go | 2 +- server/rollback.go | 2 +- server/start.go | 44 +++++++++++++++++++++----------------- server/types/app.go | 2 +- server/util.go | 4 ++-- server/util_test.go | 17 ++++++++------- 10 files changed, 46 insertions(+), 37 deletions(-) diff --git a/client/pruning/main.go b/client/pruning/main.go index db23564a1d2a..5f6fdae3bf30 100644 --- a/client/pruning/main.go +++ b/client/pruning/main.go @@ -14,6 +14,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" + "github.com/cosmos/cosmos-sdk/server/types" servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/version" ) @@ -22,7 +23,7 @@ const FlagAppDBBackend = "app-db-backend" // Cmd prunes the sdk root multi store history versions based on the pruning options // specified by command flags. -func Cmd(appCreator servertypes.AppCreator) *cobra.Command { +func Cmd[T types.Application](appCreator servertypes.AppCreator[T]) *cobra.Command { cmd := &cobra.Command{ Use: "prune [pruning-method]", Short: "Prune app history states by keeping the recent heights and deleting old heights", diff --git a/client/snapshot/cmd.go b/client/snapshot/cmd.go index af7853eb2354..a44338896934 100644 --- a/client/snapshot/cmd.go +++ b/client/snapshot/cmd.go @@ -3,11 +3,12 @@ package snapshot import ( "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/server/types" servertypes "github.com/cosmos/cosmos-sdk/server/types" ) // Cmd returns the snapshots group command -func Cmd(appCreator servertypes.AppCreator) *cobra.Command { +func Cmd[T types.Application](appCreator servertypes.AppCreator[T]) *cobra.Command { cmd := &cobra.Command{ Use: "snapshots", Short: "Manage local snapshots", diff --git a/client/snapshot/export.go b/client/snapshot/export.go index 87c5f02e91c9..599a7c2ffe3a 100644 --- a/client/snapshot/export.go +++ b/client/snapshot/export.go @@ -6,11 +6,12 @@ import ( "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/server" + "github.com/cosmos/cosmos-sdk/server/types" servertypes "github.com/cosmos/cosmos-sdk/server/types" ) // ExportSnapshotCmd returns a command to take a snapshot of the application state -func ExportSnapshotCmd(appCreator servertypes.AppCreator) *cobra.Command { +func ExportSnapshotCmd[T types.Application](appCreator servertypes.AppCreator[T]) *cobra.Command { cmd := &cobra.Command{ Use: "export", Short: "Export app state to snapshot store", diff --git a/client/snapshot/restore.go b/client/snapshot/restore.go index e1833da6b7af..331e5642db09 100644 --- a/client/snapshot/restore.go +++ b/client/snapshot/restore.go @@ -10,11 +10,12 @@ import ( "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/server" + "github.com/cosmos/cosmos-sdk/server/types" servertypes "github.com/cosmos/cosmos-sdk/server/types" ) // RestoreSnapshotCmd returns a command to restore a snapshot -func RestoreSnapshotCmd(appCreator servertypes.AppCreator) *cobra.Command { +func RestoreSnapshotCmd[T types.Application](appCreator servertypes.AppCreator[T]) *cobra.Command { cmd := &cobra.Command{ Use: "restore ", Short: "Restore app state from local snapshot", diff --git a/server/cmt_cmds.go b/server/cmt_cmds.go index bd6be4dd4314..a565ebfa831b 100644 --- a/server/cmt_cmds.go +++ b/server/cmt_cmds.go @@ -356,7 +356,7 @@ func parseOptionalHeight(heightStr string) (*int64, error) { return &tmp, nil } -func BootstrapStateCmd(appCreator types.AppCreator) *cobra.Command { +func BootstrapStateCmd[T types.Application](appCreator types.AppCreator[T]) *cobra.Command { cmd := &cobra.Command{ Use: "bootstrap-state", Short: "Bootstrap CometBFT state at an arbitrary block height using a light client", diff --git a/server/rollback.go b/server/rollback.go index 1597e5c7b654..7dd58bcedf64 100644 --- a/server/rollback.go +++ b/server/rollback.go @@ -10,7 +10,7 @@ import ( ) // NewRollbackCmd creates a command to rollback CometBFT and multistore state by one height. -func NewRollbackCmd(appCreator types.AppCreator) *cobra.Command { +func NewRollbackCmd[T types.Application](appCreator types.AppCreator[T]) *cobra.Command { var removeBlock bool cmd := &cobra.Command{ diff --git a/server/start.go b/server/start.go index d972ed3e5413..ef38010fdb89 100644 --- a/server/start.go +++ b/server/start.go @@ -108,26 +108,28 @@ const ( ) // StartCmdOptions defines options that can be customized in `StartCmdWithOptions`, -type StartCmdOptions struct { +type StartCmdOptions[T types.Application] struct { // DBOpener can be used to customize db opening, for example customize db options or support different db backends, // default to the builtin db opener. DBOpener func(rootDir string, backendType dbm.BackendType) (dbm.DB, error) // PostSetup can be used to setup extra services under the same cancellable context, // it's not called in stand-alone mode, only for in-process mode. - PostSetup func(svrCtx *Context, clientCtx client.Context, ctx context.Context, g *errgroup.Group) error + PostSetup func(app T, svrCtx *Context, clientCtx client.Context, ctx context.Context, g *errgroup.Group) error + // PostSetupStandalone can be used to setup extra services under the same cancellable context, + PostSetupStandalone func(app T, clientCtx client.Context, ctx context.Context, g *errgroup.Group) // AddFlags add custom flags to start cmd AddFlags func(cmd *cobra.Command) } // StartCmd runs the service passed in, either stand-alone or in-process with // CometBFT. -func StartCmd(appCreator types.AppCreator) *cobra.Command { - return StartCmdWithOptions(appCreator, StartCmdOptions{}) +func StartCmd[T types.Application](appCreator types.AppCreator[T]) *cobra.Command { + return StartCmdWithOptions(appCreator, StartCmdOptions[T]{}) } // StartCmdWithOptions runs the service passed in, either stand-alone or in-process with // CometBFT. -func StartCmdWithOptions(appCreator types.AppCreator, opts StartCmdOptions) *cobra.Command { +func StartCmdWithOptions[T types.Application](appCreator types.AppCreator[T], opts StartCmdOptions[T]) *cobra.Command { if opts.DBOpener == nil { opts.DBOpener = OpenDB } @@ -199,13 +201,13 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. return cmd } -func start(svrCtx *Context, clientCtx client.Context, appCreator types.AppCreator, withCmt bool, opts StartCmdOptions) error { +func start[T types.Application](svrCtx *Context, clientCtx client.Context, appCreator types.AppCreator[T], withCmt bool, opts StartCmdOptions[T]) error { svrCfg, err := getAndValidateConfig(svrCtx) if err != nil { return err } - app, appCleanupFn, err := startApp(svrCtx, appCreator, opts) + app, appCleanupFn, err := startApp[T](svrCtx, appCreator, opts) if err != nil { return err } @@ -219,12 +221,12 @@ func start(svrCtx *Context, clientCtx client.Context, appCreator types.AppCreato emitServerInfoMetrics() if !withCmt { - return startStandAlone(svrCtx, svrCfg, clientCtx, app, metrics, opts) + return startStandAlone[T](svrCtx, svrCfg, clientCtx, app, metrics, opts) } - return startInProcess(svrCtx, svrCfg, clientCtx, app, metrics, opts) + return startInProcess[T](svrCtx, svrCfg, clientCtx, app, metrics, opts) } -func startStandAlone(svrCtx *Context, svrCfg serverconfig.Config, clientCtx client.Context, app types.Application, metrics *telemetry.Metrics, opts StartCmdOptions) error { +func startStandAlone[T types.Application](svrCtx *Context, svrCfg serverconfig.Config, clientCtx client.Context, app T, metrics *telemetry.Metrics, opts StartCmdOptions[T]) error { addr := svrCtx.Viper.GetString(flagAddress) transport := svrCtx.Viper.GetString(flagTransport) @@ -287,8 +289,8 @@ func startStandAlone(svrCtx *Context, svrCfg serverconfig.Config, clientCtx clie return g.Wait() } -func startInProcess(svrCtx *Context, svrCfg serverconfig.Config, clientCtx client.Context, app types.Application, - metrics *telemetry.Metrics, opts StartCmdOptions, +func startInProcess[T types.Application](svrCtx *Context, svrCfg serverconfig.Config, clientCtx client.Context, app T, + metrics *telemetry.Metrics, opts StartCmdOptions[T], ) error { cmtCfg := svrCtx.Config home := cmtCfg.RootDir @@ -334,7 +336,7 @@ func startInProcess(svrCtx *Context, svrCfg serverconfig.Config, clientCtx clien } if opts.PostSetup != nil { - if err := opts.PostSetup(svrCtx, clientCtx, ctx, g); err != nil { + if err := opts.PostSetup(app, svrCtx, clientCtx, ctx, g); err != nil { return err } } @@ -585,7 +587,7 @@ func getCtx(svrCtx *Context, block bool) (*errgroup.Group, context.Context) { return g, ctx } -func startApp(svrCtx *Context, appCreator types.AppCreator, opts StartCmdOptions) (app types.Application, cleanupFn func(), err error) { +func startApp[T types.Application](svrCtx *Context, appCreator types.AppCreator[T], opts StartCmdOptions[T]) (app T, cleanupFn func(), err error) { traceWriter, traceCleanupFn, err := SetupTraceWriter(svrCtx.Logger, svrCtx.Viper.GetString(flagTraceStore)) if err != nil { return app, traceCleanupFn, err @@ -598,7 +600,9 @@ func startApp(svrCtx *Context, appCreator types.AppCreator, opts StartCmdOptions } if isTestnet, ok := svrCtx.Viper.Get(KeyIsTestnet).(bool); ok && isTestnet { - app, err = testnetify(svrCtx, home, appCreator, db, traceWriter) + var appPtr *T + appPtr, err = testnetify[T](svrCtx, home, appCreator, db, traceWriter) + app = *appPtr if err != nil { return app, traceCleanupFn, err } @@ -618,8 +622,8 @@ func startApp(svrCtx *Context, appCreator types.AppCreator, opts StartCmdOptions // InPlaceTestnetCreator utilizes the provided chainID and operatorAddress as well as the local private validator key to // control the network represented in the data folder. This is useful to create testnets nearly identical to your // mainnet environment. -func InPlaceTestnetCreator(testnetAppCreator types.AppCreator) *cobra.Command { - opts := StartCmdOptions{} +func InPlaceTestnetCreator[T types.Application](testnetAppCreator types.AppCreator[T]) *cobra.Command { + opts := StartCmdOptions[T]{} if opts.DBOpener == nil { opts.DBOpener = OpenDB } @@ -711,7 +715,7 @@ you want to test the upgrade handler itself. // testnetify modifies both state and blockStore, allowing the provided operator address and local validator key to control the network // that the state in the data folder represents. The chainID of the local genesis file is modified to match the provided chainID. -func testnetify(ctx *Context, home string, testnetAppCreator types.AppCreator, db dbm.DB, traceWriter io.WriteCloser) (types.Application, error) { +func testnetify[T types.Application](ctx *Context, home string, testnetAppCreator types.AppCreator[T], db dbm.DB, traceWriter io.WriteCloser) (*T, error) { config := ctx.Config newChainID, ok := ctx.Viper.Get(KeyNewChainID).(string) @@ -925,11 +929,11 @@ func testnetify(ctx *Context, home string, testnetAppCreator types.AppCreator, d return nil, err } - return testnetApp, err + return &testnetApp, err } // addStartNodeFlags should be added to any CLI commands that start the network. -func addStartNodeFlags(cmd *cobra.Command, opts StartCmdOptions) { +func addStartNodeFlags[T types.Application](cmd *cobra.Command, opts StartCmdOptions[T]) { cmd.Flags().Bool(flagWithComet, true, "Run abci app embedded in-process with CometBFT") cmd.Flags().String(flagAddress, "tcp://127.0.0.1:26658", "Listen address") cmd.Flags().String(flagTransport, "socket", "Transport protocol: socket, grpc") diff --git a/server/types/app.go b/server/types/app.go index 3b5feab3c0ca..c0b4a30309fc 100644 --- a/server/types/app.go +++ b/server/types/app.go @@ -66,7 +66,7 @@ type ( // AppCreator is a function that allows us to lazily initialize an // application using various configurations. - AppCreator func(log.Logger, dbm.DB, io.Writer, AppOptions) Application + AppCreator[T Application] func(log.Logger, dbm.DB, io.Writer, AppOptions) T // ModuleInitFlags takes a start command and adds modules specific init flags. ModuleInitFlags func(startCmd *cobra.Command) diff --git a/server/util.go b/server/util.go index a64b8339b1d6..54d075c40617 100644 --- a/server/util.go +++ b/server/util.go @@ -324,7 +324,7 @@ func interceptConfigs(rootViper *viper.Viper, customAppTemplate string, customCo } // add server commands -func AddCommands(rootCmd *cobra.Command, appCreator types.AppCreator, addStartFlags types.ModuleInitFlags) { +func AddCommands[T types.Application](rootCmd *cobra.Command, appCreator types.AppCreator[T], addStartFlags types.ModuleInitFlags) { cometCmd := &cobra.Command{ Use: "comet", Aliases: []string{"cometbft", "tendermint"}, @@ -355,7 +355,7 @@ func AddCommands(rootCmd *cobra.Command, appCreator types.AppCreator, addStartFl } // AddTestnetCreatorCommand allows chains to create a testnet from the state existing in their node's data directory. -func AddTestnetCreatorCommand(rootCmd *cobra.Command, appCreator types.AppCreator, addStartFlags types.ModuleInitFlags) { +func AddTestnetCreatorCommand[T types.Application](rootCmd *cobra.Command, appCreator types.AppCreator[T], addStartFlags types.ModuleInitFlags) { testnetCreateCmd := InPlaceTestnetCreator(appCreator) addStartFlags(testnetCreateCmd) rootCmd.AddCommand(testnetCreateCmd) diff --git a/server/util_test.go b/server/util_test.go index 3d79b24fc6c4..78de7cb8d51f 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -20,6 +20,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/config" + "github.com/cosmos/cosmos-sdk/server/types" servertypes "github.com/cosmos/cosmos-sdk/server/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/module" @@ -50,7 +51,7 @@ func TestGetAppDBBackend(t *testing.T) { func TestInterceptConfigsPreRunHandlerCreatesConfigFilesWhenMissing(t *testing.T) { tempDir := t.TempDir() - cmd := server.StartCmd(nil) + cmd := server.StartCmd[types.Application](nil) cmd.PersistentFlags().String(flags.FlagHome, "/foobar", "") if err := cmd.PersistentFlags().Set(flags.FlagHome, tempDir); err != nil { t.Fatalf("Could not set home flag [%T] %v", err, err) @@ -129,7 +130,7 @@ func TestInterceptConfigsPreRunHandlerReadsConfigToml(t *testing.T) { t.Fatalf("Failed closing config.toml: %v", err) } - cmd := server.StartCmd(nil) + cmd := server.StartCmd[types.Application](nil) cmd.PersistentFlags().String(flags.FlagHome, "/foobar", "") if err := cmd.PersistentFlags().Set(flags.FlagHome, tempDir); err != nil { t.Fatalf("Could not set home flag [%T] %v", err, err) @@ -172,7 +173,7 @@ func TestInterceptConfigsPreRunHandlerReadsAppToml(t *testing.T) { if err := writer.Close(); err != nil { t.Fatalf("Failed closing app.toml: %v", err) } - cmd := server.StartCmd(nil) + cmd := server.StartCmd[types.Application](nil) cmd.PersistentFlags().String(flags.FlagHome, tempDir, "") cmd.PreRunE = preRunETestImpl @@ -194,7 +195,7 @@ func TestInterceptConfigsPreRunHandlerReadsAppToml(t *testing.T) { func TestInterceptConfigsPreRunHandlerReadsFlags(t *testing.T) { const testAddr = "tcp://127.1.2.3:12345" tempDir := t.TempDir() - cmd := server.StartCmd(nil) + cmd := server.StartCmd[types.Application](nil) cmd.PersistentFlags().String(flags.FlagHome, "/foobar", "") if err := cmd.PersistentFlags().Set(flags.FlagHome, tempDir); err != nil { t.Fatalf("Could not set home flag [%T] %v", err, err) @@ -224,7 +225,7 @@ func TestInterceptConfigsPreRunHandlerReadsFlags(t *testing.T) { func TestInterceptConfigsPreRunHandlerReadsEnvVars(t *testing.T) { const testAddr = "tcp://127.1.2.3:12345" tempDir := t.TempDir() - cmd := server.StartCmd(nil) + cmd := server.StartCmd[types.Application](nil) cmd.PersistentFlags().String(flags.FlagHome, "/foobar", "") if err := cmd.PersistentFlags().Set(flags.FlagHome, tempDir); err != nil { t.Fatalf("Could not set home flag [%T] %v", err, err) @@ -314,7 +315,7 @@ func newPrecedenceCommon(t *testing.T) precedenceCommon { }) // Set up the command object that is used in this test - retval.cmd = server.StartCmd(nil) + retval.cmd = server.StartCmd[types.Application](nil) retval.cmd.PersistentFlags().String(flags.FlagHome, tempDir, "") retval.cmd.PreRunE = preRunETestImpl @@ -431,7 +432,7 @@ func TestInterceptConfigsWithBadPermissions(t *testing.T) { if err := os.Mkdir(subDir, 0o600); err != nil { t.Fatalf("Failed to create sub directory: %v", err) } - cmd := server.StartCmd(nil) + cmd := server.StartCmd[types.Application](nil) cmd.PersistentFlags().String(flags.FlagHome, "/foobar", "") if err := cmd.PersistentFlags().Set(flags.FlagHome, subDir); err != nil { t.Fatalf("Could not set home flag [%T] %v", err, err) @@ -471,7 +472,7 @@ func TestEmptyMinGasPrices(t *testing.T) { require.NoError(t, err) // Run StartCmd. - cmd = server.StartCmd(nil) + cmd = server.StartCmd[types.Application](nil) cmd.PersistentFlags().String(flags.FlagHome, tempDir, "") cmd.PreRunE = func(cmd *cobra.Command, _ []string) error { ctx, err := server.InterceptConfigsAndCreateContext(cmd, "", nil, cmtcfg.DefaultConfig()) From 15454f698f4b88f64bd8c57cf838f83ce4e08e05 Mon Sep 17 00:00:00 2001 From: itsdevbear Date: Fri, 16 Feb 2024 12:31:54 -0500 Subject: [PATCH 2/7] add standalone --- server/start.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/start.go b/server/start.go index ef38010fdb89..31af1898b18d 100644 --- a/server/start.go +++ b/server/start.go @@ -116,7 +116,7 @@ type StartCmdOptions[T types.Application] struct { // it's not called in stand-alone mode, only for in-process mode. PostSetup func(app T, svrCtx *Context, clientCtx client.Context, ctx context.Context, g *errgroup.Group) error // PostSetupStandalone can be used to setup extra services under the same cancellable context, - PostSetupStandalone func(app T, clientCtx client.Context, ctx context.Context, g *errgroup.Group) + PostSetupStandalone func(app T, svrCtx *Context, clientCtx client.Context, ctx context.Context, g *errgroup.Group) error // AddFlags add custom flags to start cmd AddFlags func(cmd *cobra.Command) } @@ -273,6 +273,12 @@ func startStandAlone[T types.Application](svrCtx *Context, svrCfg serverconfig.C return err } + if opts.PostSetup != nil { + if err := opts.PostSetupStandalone(app, svrCtx, clientCtx, ctx, g); err != nil { + return err + } + } + g.Go(func() error { if err := svr.Start(); err != nil { svrCtx.Logger.Error("failed to start out-of-process ABCI server", "err", err) From 1a0ec346bd5775b563b3da53bbfe04a1492c28ab Mon Sep 17 00:00:00 2001 From: itsdevbear Date: Fri, 16 Feb 2024 14:31:05 -0500 Subject: [PATCH 3/7] bet --- CHANGELOG.md | 1 + client/pruning/main.go | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f691b0c9f60..df256ecc361c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i ### Improvements +* (server) [#18950](https://github.com/cosmos/cosmos-sdk/pull/19455) Allow calling back into the application struct in PostSetup. * (client/keys) [#18950](https://github.com/cosmos/cosmos-sdk/pull/18950) Improve ` keys add`, ` keys import` and ` keys rename` by checking name validation. * (client/keys) [#18745](https://github.com/cosmos/cosmos-sdk/pull/18745) Improve ` keys export` and ` keys mnemonic` by adding --yes option to skip interactive confirmation. * (client/keys) [#18743](https://github.com/cosmos/cosmos-sdk/pull/18743) Improve ` keys add -i` by hiding inputting of bip39 passphrase. diff --git a/client/pruning/main.go b/client/pruning/main.go index 5f6fdae3bf30..3db413b4c614 100644 --- a/client/pruning/main.go +++ b/client/pruning/main.go @@ -14,7 +14,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" - "github.com/cosmos/cosmos-sdk/server/types" servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/version" ) @@ -23,7 +22,7 @@ const FlagAppDBBackend = "app-db-backend" // Cmd prunes the sdk root multi store history versions based on the pruning options // specified by command flags. -func Cmd[T types.Application](appCreator servertypes.AppCreator[T]) *cobra.Command { +func Cmd[T servertypes.Application](appCreator servertypes.AppCreator[T]) *cobra.Command { cmd := &cobra.Command{ Use: "prune [pruning-method]", Short: "Prune app history states by keeping the recent heights and deleting old heights", From 2461cff1f577addf36c1382aadbf636e918f1aff Mon Sep 17 00:00:00 2001 From: itsdevbear Date: Fri, 16 Feb 2024 14:32:22 -0500 Subject: [PATCH 4/7] code ql --- server/start.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/start.go b/server/start.go index 31af1898b18d..d5af6dba9e37 100644 --- a/server/start.go +++ b/server/start.go @@ -608,10 +608,10 @@ func startApp[T types.Application](svrCtx *Context, appCreator types.AppCreator[ if isTestnet, ok := svrCtx.Viper.Get(KeyIsTestnet).(bool); ok && isTestnet { var appPtr *T appPtr, err = testnetify[T](svrCtx, home, appCreator, db, traceWriter) - app = *appPtr if err != nil { return app, traceCleanupFn, err } + app = *appPtr } else { app = appCreator(svrCtx.Logger, db, traceWriter, svrCtx.Viper) } From 3cf059bb25cbfb94a8c89225da722c393e9eab09 Mon Sep 17 00:00:00 2001 From: itsdevbear Date: Fri, 16 Feb 2024 14:33:03 -0500 Subject: [PATCH 5/7] fix changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df256ecc361c..d863bdcc56f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,7 +56,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i ### Improvements -* (server) [#18950](https://github.com/cosmos/cosmos-sdk/pull/19455) Allow calling back into the application struct in PostSetup. +* (server) [#19455](https://github.com/cosmos/cosmos-sdk/pull/19455) Allow calling back into the application struct in PostSetup. * (client/keys) [#18950](https://github.com/cosmos/cosmos-sdk/pull/18950) Improve ` keys add`, ` keys import` and ` keys rename` by checking name validation. * (client/keys) [#18745](https://github.com/cosmos/cosmos-sdk/pull/18745) Improve ` keys export` and ` keys mnemonic` by adding --yes option to skip interactive confirmation. * (client/keys) [#18743](https://github.com/cosmos/cosmos-sdk/pull/18743) Improve ` keys add -i` by hiding inputting of bip39 passphrase. From 68e94305627b9c4dab47b9f8f43f4d4239e65311 Mon Sep 17 00:00:00 2001 From: itsdevbear Date: Fri, 16 Feb 2024 15:09:01 -0500 Subject: [PATCH 6/7] bet --- client/snapshot/cmd.go | 3 +-- client/snapshot/export.go | 3 +-- client/snapshot/restore.go | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/client/snapshot/cmd.go b/client/snapshot/cmd.go index a44338896934..03b9ae9aae65 100644 --- a/client/snapshot/cmd.go +++ b/client/snapshot/cmd.go @@ -3,12 +3,11 @@ package snapshot import ( "github.com/spf13/cobra" - "github.com/cosmos/cosmos-sdk/server/types" servertypes "github.com/cosmos/cosmos-sdk/server/types" ) // Cmd returns the snapshots group command -func Cmd[T types.Application](appCreator servertypes.AppCreator[T]) *cobra.Command { +func Cmd[T servertypes.Application](appCreator servertypes.AppCreator[T]) *cobra.Command { cmd := &cobra.Command{ Use: "snapshots", Short: "Manage local snapshots", diff --git a/client/snapshot/export.go b/client/snapshot/export.go index 599a7c2ffe3a..61f1951bbafe 100644 --- a/client/snapshot/export.go +++ b/client/snapshot/export.go @@ -6,12 +6,11 @@ import ( "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/server" - "github.com/cosmos/cosmos-sdk/server/types" servertypes "github.com/cosmos/cosmos-sdk/server/types" ) // ExportSnapshotCmd returns a command to take a snapshot of the application state -func ExportSnapshotCmd[T types.Application](appCreator servertypes.AppCreator[T]) *cobra.Command { +func ExportSnapshotCmd[T servertypes.Application](appCreator servertypes.AppCreator[T]) *cobra.Command { cmd := &cobra.Command{ Use: "export", Short: "Export app state to snapshot store", diff --git a/client/snapshot/restore.go b/client/snapshot/restore.go index 331e5642db09..c1f5b21f214c 100644 --- a/client/snapshot/restore.go +++ b/client/snapshot/restore.go @@ -10,12 +10,11 @@ import ( "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/server" - "github.com/cosmos/cosmos-sdk/server/types" servertypes "github.com/cosmos/cosmos-sdk/server/types" ) // RestoreSnapshotCmd returns a command to restore a snapshot -func RestoreSnapshotCmd[T types.Application](appCreator servertypes.AppCreator[T]) *cobra.Command { +func RestoreSnapshotCmd[T servertypes.Application](appCreator servertypes.AppCreator[T]) *cobra.Command { cmd := &cobra.Command{ Use: "restore ", Short: "Restore app state from local snapshot", From ca37db569a35877c8f27203c80f76a66816e132b Mon Sep 17 00:00:00 2001 From: itsdevbear Date: Wed, 21 Feb 2024 01:47:20 -0500 Subject: [PATCH 7/7] fix lint --- server/util_test.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/server/util_test.go b/server/util_test.go index 78de7cb8d51f..1ae28c83f49d 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -20,7 +20,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/config" - "github.com/cosmos/cosmos-sdk/server/types" servertypes "github.com/cosmos/cosmos-sdk/server/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/module" @@ -51,7 +50,7 @@ func TestGetAppDBBackend(t *testing.T) { func TestInterceptConfigsPreRunHandlerCreatesConfigFilesWhenMissing(t *testing.T) { tempDir := t.TempDir() - cmd := server.StartCmd[types.Application](nil) + cmd := server.StartCmd[servertypes.Application](nil) cmd.PersistentFlags().String(flags.FlagHome, "/foobar", "") if err := cmd.PersistentFlags().Set(flags.FlagHome, tempDir); err != nil { t.Fatalf("Could not set home flag [%T] %v", err, err) @@ -130,7 +129,7 @@ func TestInterceptConfigsPreRunHandlerReadsConfigToml(t *testing.T) { t.Fatalf("Failed closing config.toml: %v", err) } - cmd := server.StartCmd[types.Application](nil) + cmd := server.StartCmd[servertypes.Application](nil) cmd.PersistentFlags().String(flags.FlagHome, "/foobar", "") if err := cmd.PersistentFlags().Set(flags.FlagHome, tempDir); err != nil { t.Fatalf("Could not set home flag [%T] %v", err, err) @@ -173,7 +172,7 @@ func TestInterceptConfigsPreRunHandlerReadsAppToml(t *testing.T) { if err := writer.Close(); err != nil { t.Fatalf("Failed closing app.toml: %v", err) } - cmd := server.StartCmd[types.Application](nil) + cmd := server.StartCmd[servertypes.Application](nil) cmd.PersistentFlags().String(flags.FlagHome, tempDir, "") cmd.PreRunE = preRunETestImpl @@ -195,7 +194,7 @@ func TestInterceptConfigsPreRunHandlerReadsAppToml(t *testing.T) { func TestInterceptConfigsPreRunHandlerReadsFlags(t *testing.T) { const testAddr = "tcp://127.1.2.3:12345" tempDir := t.TempDir() - cmd := server.StartCmd[types.Application](nil) + cmd := server.StartCmd[servertypes.Application](nil) cmd.PersistentFlags().String(flags.FlagHome, "/foobar", "") if err := cmd.PersistentFlags().Set(flags.FlagHome, tempDir); err != nil { t.Fatalf("Could not set home flag [%T] %v", err, err) @@ -225,7 +224,7 @@ func TestInterceptConfigsPreRunHandlerReadsFlags(t *testing.T) { func TestInterceptConfigsPreRunHandlerReadsEnvVars(t *testing.T) { const testAddr = "tcp://127.1.2.3:12345" tempDir := t.TempDir() - cmd := server.StartCmd[types.Application](nil) + cmd := server.StartCmd[servertypes.Application](nil) cmd.PersistentFlags().String(flags.FlagHome, "/foobar", "") if err := cmd.PersistentFlags().Set(flags.FlagHome, tempDir); err != nil { t.Fatalf("Could not set home flag [%T] %v", err, err) @@ -315,7 +314,7 @@ func newPrecedenceCommon(t *testing.T) precedenceCommon { }) // Set up the command object that is used in this test - retval.cmd = server.StartCmd[types.Application](nil) + retval.cmd = server.StartCmd[servertypes.Application](nil) retval.cmd.PersistentFlags().String(flags.FlagHome, tempDir, "") retval.cmd.PreRunE = preRunETestImpl @@ -432,7 +431,7 @@ func TestInterceptConfigsWithBadPermissions(t *testing.T) { if err := os.Mkdir(subDir, 0o600); err != nil { t.Fatalf("Failed to create sub directory: %v", err) } - cmd := server.StartCmd[types.Application](nil) + cmd := server.StartCmd[servertypes.Application](nil) cmd.PersistentFlags().String(flags.FlagHome, "/foobar", "") if err := cmd.PersistentFlags().Set(flags.FlagHome, subDir); err != nil { t.Fatalf("Could not set home flag [%T] %v", err, err) @@ -472,7 +471,7 @@ func TestEmptyMinGasPrices(t *testing.T) { require.NoError(t, err) // Run StartCmd. - cmd = server.StartCmd[types.Application](nil) + cmd = server.StartCmd[servertypes.Application](nil) cmd.PersistentFlags().String(flags.FlagHome, tempDir, "") cmd.PreRunE = func(cmd *cobra.Command, _ []string) error { ctx, err := server.InterceptConfigsAndCreateContext(cmd, "", nil, cmtcfg.DefaultConfig())