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

Commit

Permalink
Merge branch 'main' into fix_blk_number_in_trace
Browse files Browse the repository at this point in the history
  • Loading branch information
fedekunze authored Jan 20, 2023
2 parents e67f579 + f1337aa commit 36bb123
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,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.
* (rpc) [#1611](https://github.com/evmos/ethermint/pull/1611) Add missing next fee in fee history, fix wrong oldestBlock and align earliest input as ethereum.

### Improvements

* (cli) [#1615](https://github.com/evmos/ethermint/pull/1615) Support customize db opener in `StartCmd`.

## [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
41 changes: 30 additions & 11 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
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

0 comments on commit 36bb123

Please sign in to comment.