Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

support customize db opener in StartCmd #1615

Merged
merged 5 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

* (rpc) [#1613](https://github.com/evmos/ethermint/pull/1613) Change the default json-rpc listen address to localhost.

### Improvements

* (cli) [#]() Support customize db opener in `StartCmd`.
yihuang marked this conversation as resolved.
Show resolved Hide resolved

## [v0.21.0-rc1] - 2022-1-13

### State Machine Breaking
Expand Down
2 changes: 1 addition & 1 deletion cmd/ethermintd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
33 changes: 25 additions & 8 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,26 @@ import (
ethermint "github.com/evmos/ethermint/types"
)

type DBOpener func(rootDir string, backendType dbm.BackendType) (dbm.DB, error)

// StartOptions defines options that can be customized in `StartCmd`
type StartOptions struct {
AppCreator types.AppCreator
DefaultNodeHome string
DBOpener DBOpener
}

func NewDefaultStartOptions(appCreator types.AppCreator, defaultNodeHome string) StartOptions {
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
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",
Expand Down Expand Up @@ -119,7 +136,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.AppCreator)
}

serverCtx.Logger.Info("Unlocking keyring")
Expand All @@ -136,7 +153,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
Expand All @@ -147,7 +164,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")
Expand Down Expand Up @@ -211,7 +228,7 @@ func startStandAlone(ctx *server.Context, appCreator types.AppCreator) error {
transport := ctx.Viper.GetString(srvflags.Transport)
home := ctx.Viper.GetString(flags.FlagHome)

db, err := openDB(home, server.GetAppDBBackend(ctx.Viper))
db, err := opts.DBOpener(home, server.GetAppDBBackend(ctx.Viper))
if err != nil {
return err
}
Expand Down Expand Up @@ -269,7 +286,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
Expand Down Expand Up @@ -300,7 +317,7 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, appCreator ty
}()
}

db, err := openDB(home, server.GetAppDBBackend(ctx.Viper))
db, err := opts.DBOpener(home, server.GetAppDBBackend(ctx.Viper))
if err != nil {
logger.Error("failed to open DB", "error", err.Error())
return err
Expand Down Expand Up @@ -330,7 +347,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 {
Expand Down
9 changes: 4 additions & 5 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
Expand All @@ -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(),
Expand Down