diff --git a/CHANGELOG.md b/CHANGELOG.md index eadf3227..788ac667 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,13 +42,13 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (feemarket) [#1509](https://github.com/evmos/ethermint/pull/1509) Deprecate usage of x/params in x/feemarket * (evm) [#1472](https://github.com/evmos/ethermint/pull/1472) Deprecate x/params usage in x/evm -* (deps) [#1575](https://github.com/evmos/ethermint/pull/1575) bump ibc-go to [`v6.1.0`] -* (deps) [#1168](https://github.com/evmos/ethermint/pull/1168) Upgrade Cosmos SDK to [`v0.46.6`] +* (deps) [#1575](https://github.com/evmos/ethermint/pull/1575) bump ibc-go to [`v6.1.0`](https://github.com/cosmos/ibc-go/releases/tag/v6.1.0) ### Improvements -* (evm) [#1582](https://github.com/evmos/ethermint/pull/1582) cleanup `evm` files -* (evm) [#1544](https://github.com/evmos/ethermint/pull/1544) Migrate deprecated event emitting to new TypedEvent +* (cli) [#1615](https://github.com/evmos/ethermint/pull/1615) Support customize db opener in `StartCmd`. +* (evm) [#1582](https://github.com/evmos/ethermint/pull/1582) Cleanup `evm` files +* (evm) [#1544](https://github.com/evmos/ethermint/pull/1544) Migrate deprecated event emitting to new `TypedEvent` * (deps) [#1532](https://github.com/evmos/ethermint/pull/1532) Upgrade Go-Ethereum version to [`v1.10.26`](https://github.com/ethereum/go-ethereum/releases/tag/v1.10.26). ### Bug Fixes diff --git a/cmd/ethermintd/root.go b/cmd/ethermintd/root.go index 18478c06..5474ac57 100644 --- a/cmd/ethermintd/root.go +++ b/cmd/ethermintd/root.go @@ -130,7 +130,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { ) a := appCreator{encodingConfig} - server.AddCommands(rootCmd, app.DefaultNodeHome, a.newApp, a.appExport, addModuleInitFlags) + server.AddCommands(rootCmd, server.NewDefaultStartOptions(a.newApp, app.DefaultNodeHome), a.appExport, addModuleInitFlags) // add keybase, auxiliary RPC, query, and tx child commands rootCmd.AddCommand( diff --git a/server/start.go b/server/start.go index 96c03d96..6236dd9c 100644 --- a/server/start.go +++ b/server/start.go @@ -68,9 +68,28 @@ import ( ethermint "github.com/evmos/ethermint/types" ) +// DBOpener is a function to open `application.db`, potentially with customized options. +type DBOpener func(opts types.AppOptions, rootDir string, backend dbm.BackendType) (dbm.DB, error) + +// StartOptions defines options that can be customized in `StartCmd` +type StartOptions struct { + AppCreator types.AppCreator + DefaultNodeHome string + DBOpener DBOpener +} + +// NewDefaultStartOptions use the default db opener provided in tm-db. +func NewDefaultStartOptions(appCreator types.AppCreator, defaultNodeHome string) StartOptions { + return StartOptions{ + AppCreator: appCreator, + DefaultNodeHome: defaultNodeHome, + DBOpener: openDB, + } +} + // StartCmd runs the service passed in, either stand-alone or in-process with // Tendermint. -func StartCmd(appCreator types.AppCreator, defaultNodeHome string) *cobra.Command { +func StartCmd(opts StartOptions) *cobra.Command { cmd := &cobra.Command{ Use: "start", Short: "Run the full node", @@ -119,7 +138,7 @@ which accepts a path for the resulting pprof file. withTM, _ := cmd.Flags().GetBool(srvflags.WithTendermint) if !withTM { serverCtx.Logger.Info("starting ABCI without Tendermint") - return startStandAlone(serverCtx, appCreator) + return startStandAlone(serverCtx, opts) } serverCtx.Logger.Info("Unlocking keyring") @@ -136,7 +155,7 @@ which accepts a path for the resulting pprof file. serverCtx.Logger.Info("starting ABCI with Tendermint") // amino is needed here for backwards compatibility of REST routes - err = startInProcess(serverCtx, clientCtx, appCreator) + err = startInProcess(serverCtx, clientCtx, opts) errCode, ok := err.(server.ErrorCode) if !ok { return err @@ -147,7 +166,7 @@ which accepts a path for the resulting pprof file. }, } - cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory") + cmd.Flags().String(flags.FlagHome, opts.DefaultNodeHome, "The application home directory") cmd.Flags().Bool(srvflags.WithTendermint, true, "Run abci app embedded in-process with tendermint") cmd.Flags().String(srvflags.Address, "tcp://0.0.0.0:26658", "Listen address") cmd.Flags().String(srvflags.Transport, "socket", "Transport protocol: socket, grpc") @@ -206,12 +225,12 @@ which accepts a path for the resulting pprof file. return cmd } -func startStandAlone(ctx *server.Context, appCreator types.AppCreator) error { +func startStandAlone(ctx *server.Context, opts StartOptions) error { addr := ctx.Viper.GetString(srvflags.Address) transport := ctx.Viper.GetString(srvflags.Transport) home := ctx.Viper.GetString(flags.FlagHome) - db, err := openDB(home, server.GetAppDBBackend(ctx.Viper)) + db, err := opts.DBOpener(ctx.Viper, home, server.GetAppDBBackend(ctx.Viper)) if err != nil { return err } @@ -228,7 +247,7 @@ func startStandAlone(ctx *server.Context, appCreator types.AppCreator) error { return err } - app := appCreator(ctx.Logger, db, traceWriter, ctx.Viper) + app := opts.AppCreator(ctx.Logger, db, traceWriter, ctx.Viper) config, err := config.GetConfig(ctx.Viper) if err != nil { @@ -269,7 +288,7 @@ func startStandAlone(ctx *server.Context, appCreator types.AppCreator) error { } // legacyAminoCdc is used for the legacy REST API -func startInProcess(ctx *server.Context, clientCtx client.Context, appCreator types.AppCreator) (err error) { +func startInProcess(ctx *server.Context, clientCtx client.Context, opts StartOptions) (err error) { cfg := ctx.Config home := cfg.RootDir logger := ctx.Logger @@ -300,7 +319,7 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, appCreator ty }() } - db, err := openDB(home, server.GetAppDBBackend(ctx.Viper)) + db, err := opts.DBOpener(ctx.Viper, home, server.GetAppDBBackend(ctx.Viper)) if err != nil { logger.Error("failed to open DB", "error", err.Error()) return err @@ -330,7 +349,7 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, appCreator ty return err } - app := appCreator(ctx.Logger, db, traceWriter, ctx.Viper) + app := opts.AppCreator(ctx.Logger, db, traceWriter, ctx.Viper) nodeKey, err := p2p.LoadOrGenNodeKey(cfg.NodeKeyFile()) if err != nil { @@ -625,7 +644,7 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, appCreator ty return server.WaitForQuitSignals() } -func openDB(rootDir string, backendType dbm.BackendType) (dbm.DB, error) { +func openDB(_ types.AppOptions, rootDir string, backendType dbm.BackendType) (dbm.DB, error) { dataDir := filepath.Join(rootDir, "data") return dbm.NewDB("application", backendType, dataDir) } diff --git a/server/util.go b/server/util.go index fa3a19e5..6657f990 100644 --- a/server/util.go +++ b/server/util.go @@ -38,8 +38,7 @@ import ( // AddCommands adds server commands func AddCommands( rootCmd *cobra.Command, - defaultNodeHome string, - appCreator types.AppCreator, + opts StartOptions, appExport types.AppExporter, addStartFlags types.ModuleInitFlags, ) { @@ -57,15 +56,15 @@ func AddCommands( tmcmd.ResetStateCmd, ) - startCmd := StartCmd(appCreator, defaultNodeHome) + startCmd := StartCmd(opts) addStartFlags(startCmd) rootCmd.AddCommand( startCmd, tendermintCmd, - sdkserver.ExportCmd(appExport, defaultNodeHome), + sdkserver.ExportCmd(appExport, opts.DefaultNodeHome), version.NewVersionCommand(), - sdkserver.NewRollbackCmd(appCreator, defaultNodeHome), + sdkserver.NewRollbackCmd(opts.AppCreator, opts.DefaultNodeHome), // custom tx indexer command NewIndexTxCmd(),