forked from cerc-io/laconicd-deprecated
* support customize db opener in `StartCmd` (#1615) * support customize db opener in `StartCmd` * Update CHANGELOG.md * pass to dbOpener, so we can control different options through cli flags * add comments (cherry picked from commit f1337aa378e70f5ff9c4c4e676450505efbfa682) # Conflicts: # CHANGELOG.md * conflicts Co-authored-by: yihuang <huang@crypto.com> Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
parent
949674e511
commit
64e80be8ee
@ -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
|
* (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
|
* (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) [#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)
|
||||||
* (deps) [#1168](https://github.com/evmos/ethermint/pull/1168) Upgrade Cosmos SDK to [`v0.46.6`]
|
|
||||||
|
|
||||||
### Improvements
|
### Improvements
|
||||||
|
|
||||||
* (evm) [#1582](https://github.com/evmos/ethermint/pull/1582) cleanup `evm` files
|
* (cli) [#1615](https://github.com/evmos/ethermint/pull/1615) Support customize db opener in `StartCmd`.
|
||||||
* (evm) [#1544](https://github.com/evmos/ethermint/pull/1544) Migrate deprecated event emitting to new TypedEvent
|
* (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).
|
* (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
|
### Bug Fixes
|
||||||
|
@ -130,7 +130,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
a := appCreator{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
|
// add keybase, auxiliary RPC, query, and tx child commands
|
||||||
rootCmd.AddCommand(
|
rootCmd.AddCommand(
|
||||||
|
@ -68,9 +68,28 @@ import (
|
|||||||
ethermint "github.com/evmos/ethermint/types"
|
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
|
// StartCmd runs the service passed in, either stand-alone or in-process with
|
||||||
// Tendermint.
|
// Tendermint.
|
||||||
func StartCmd(appCreator types.AppCreator, defaultNodeHome string) *cobra.Command {
|
func StartCmd(opts StartOptions) *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "start",
|
Use: "start",
|
||||||
Short: "Run the full node",
|
Short: "Run the full node",
|
||||||
@ -119,7 +138,7 @@ which accepts a path for the resulting pprof file.
|
|||||||
withTM, _ := cmd.Flags().GetBool(srvflags.WithTendermint)
|
withTM, _ := cmd.Flags().GetBool(srvflags.WithTendermint)
|
||||||
if !withTM {
|
if !withTM {
|
||||||
serverCtx.Logger.Info("starting ABCI without Tendermint")
|
serverCtx.Logger.Info("starting ABCI without Tendermint")
|
||||||
return startStandAlone(serverCtx, appCreator)
|
return startStandAlone(serverCtx, opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
serverCtx.Logger.Info("Unlocking keyring")
|
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")
|
serverCtx.Logger.Info("starting ABCI with Tendermint")
|
||||||
|
|
||||||
// amino is needed here for backwards compatibility of REST routes
|
// 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)
|
errCode, ok := err.(server.ErrorCode)
|
||||||
if !ok {
|
if !ok {
|
||||||
return err
|
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().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.Address, "tcp://0.0.0.0:26658", "Listen address")
|
||||||
cmd.Flags().String(srvflags.Transport, "socket", "Transport protocol: socket, grpc")
|
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
|
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)
|
addr := ctx.Viper.GetString(srvflags.Address)
|
||||||
transport := ctx.Viper.GetString(srvflags.Transport)
|
transport := ctx.Viper.GetString(srvflags.Transport)
|
||||||
home := ctx.Viper.GetString(flags.FlagHome)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -228,7 +247,7 @@ func startStandAlone(ctx *server.Context, appCreator types.AppCreator) error {
|
|||||||
return err
|
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)
|
config, err := config.GetConfig(ctx.Viper)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -269,7 +288,7 @@ func startStandAlone(ctx *server.Context, appCreator types.AppCreator) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// legacyAminoCdc is used for the legacy REST API
|
// 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
|
cfg := ctx.Config
|
||||||
home := cfg.RootDir
|
home := cfg.RootDir
|
||||||
logger := ctx.Logger
|
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 {
|
if err != nil {
|
||||||
logger.Error("failed to open DB", "error", err.Error())
|
logger.Error("failed to open DB", "error", err.Error())
|
||||||
return err
|
return err
|
||||||
@ -330,7 +349,7 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, appCreator ty
|
|||||||
return err
|
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())
|
nodeKey, err := p2p.LoadOrGenNodeKey(cfg.NodeKeyFile())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -625,7 +644,7 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, appCreator ty
|
|||||||
return server.WaitForQuitSignals()
|
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")
|
dataDir := filepath.Join(rootDir, "data")
|
||||||
return dbm.NewDB("application", backendType, dataDir)
|
return dbm.NewDB("application", backendType, dataDir)
|
||||||
}
|
}
|
||||||
|
@ -38,8 +38,7 @@ import (
|
|||||||
// AddCommands adds server commands
|
// AddCommands adds server commands
|
||||||
func AddCommands(
|
func AddCommands(
|
||||||
rootCmd *cobra.Command,
|
rootCmd *cobra.Command,
|
||||||
defaultNodeHome string,
|
opts StartOptions,
|
||||||
appCreator types.AppCreator,
|
|
||||||
appExport types.AppExporter,
|
appExport types.AppExporter,
|
||||||
addStartFlags types.ModuleInitFlags,
|
addStartFlags types.ModuleInitFlags,
|
||||||
) {
|
) {
|
||||||
@ -57,15 +56,15 @@ func AddCommands(
|
|||||||
tmcmd.ResetStateCmd,
|
tmcmd.ResetStateCmd,
|
||||||
)
|
)
|
||||||
|
|
||||||
startCmd := StartCmd(appCreator, defaultNodeHome)
|
startCmd := StartCmd(opts)
|
||||||
addStartFlags(startCmd)
|
addStartFlags(startCmd)
|
||||||
|
|
||||||
rootCmd.AddCommand(
|
rootCmd.AddCommand(
|
||||||
startCmd,
|
startCmd,
|
||||||
tendermintCmd,
|
tendermintCmd,
|
||||||
sdkserver.ExportCmd(appExport, defaultNodeHome),
|
sdkserver.ExportCmd(appExport, opts.DefaultNodeHome),
|
||||||
version.NewVersionCommand(),
|
version.NewVersionCommand(),
|
||||||
sdkserver.NewRollbackCmd(appCreator, defaultNodeHome),
|
sdkserver.NewRollbackCmd(opts.AppCreator, opts.DefaultNodeHome),
|
||||||
|
|
||||||
// custom tx indexer command
|
// custom tx indexer command
|
||||||
NewIndexTxCmd(),
|
NewIndexTxCmd(),
|
||||||
|
Loading…
Reference in New Issue
Block a user