From 828379ed18c130c45d3a0cb60df46d72fb92abdd Mon Sep 17 00:00:00 2001 From: HuangYi Date: Thu, 4 Aug 2022 17:05:43 +0800 Subject: [PATCH 1/4] support dynamic app db backend --- CHANGELOG.md | 1 + Makefile | 25 ++++++++++++++++++------- cmd/ethermintd/root.go | 5 +++++ server/start.go | 3 +++ 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf0f42bd71..271171cc90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements * (feemarket) [\#1165](https://github.com/evmos/ethermint/pull/1165) Add hint in specs about different gas terminology for gas in Cosmos and Ethereum. +* (cli) []() Add custom app db backend flag. ### Bug Fixes diff --git a/Makefile b/Makefile index 726d3586ff..763fcf96f3 100755 --- a/Makefile +++ b/Makefile @@ -15,6 +15,9 @@ HTTPS_GIT := https://github.com/evmos/ethermint.git PROJECT_NAME = $(shell git remote get-url origin | xargs basename -s .git) DOCKER := $(shell which docker) DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf:1.0.0-rc8 +# RocksDB is a native dependency, so we don't assume the library is installed. +# Instead, it must be explicitly enabled and we warn when it is not. +ENABLE_ROCKSDB ?= false export GO111MODULE = on @@ -49,9 +52,6 @@ ifeq ($(LEDGER_ENABLED),true) endif endif -ifeq (cleveldb,$(findstring cleveldb,$(COSMOS_BUILD_OPTIONS))) - build_tags += gcc -endif build_tags += $(BUILD_TAGS) build_tags := $(strip $(build_tags)) @@ -69,23 +69,31 @@ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=ethermint \ -X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" \ -X github.com/tendermint/tendermint/version.TMCoreSemVer=$(TMVERSION) +ifeq ($(ENABLE_ROCKSDB),true) + BUILD_TAGS += rocksdb_build + test_tags += rocksdb_build +else + $(warning RocksDB support is disabled; to build and test with RocksDB support, set ENABLE_ROCKSDB=true) +endif + # DB backend selection ifeq (cleveldb,$(findstring cleveldb,$(COSMOS_BUILD_OPTIONS))) - ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb + BUILD_TAGS += gcc endif ifeq (badgerdb,$(findstring badgerdb,$(COSMOS_BUILD_OPTIONS))) - ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=badgerdb + BUILD_TAGS += badgerdb endif # handle rocksdb ifeq (rocksdb,$(findstring rocksdb,$(COSMOS_BUILD_OPTIONS))) + ifneq ($(ENABLE_ROCKSDB),true) + $(error Cannot use RocksDB backend unless ENABLE_ROCKSDB=true) + endif CGO_ENABLED=1 BUILD_TAGS += rocksdb - ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=rocksdb endif # handle boltdb ifeq (boltdb,$(findstring boltdb,$(COSMOS_BUILD_OPTIONS))) BUILD_TAGS += boltdb - ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=boltdb endif ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS))) @@ -94,6 +102,9 @@ endif ldflags += $(LDFLAGS) ldflags := $(strip $(ldflags)) +build_tags += $(BUILD_TAGS) +build_tags := $(strip $(build_tags)) + BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)' # check for nostrip option ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS))) diff --git a/cmd/ethermintd/root.go b/cmd/ethermintd/root.go index 96c106ee7c..d7ec96ba81 100644 --- a/cmd/ethermintd/root.go +++ b/cmd/ethermintd/root.go @@ -210,6 +210,11 @@ func (a appCreator) newApp(logger tmlog.Logger, db dbm.DB, traceStore io.Writer, } snapshotDir := filepath.Join(cast.ToString(appOpts.Get(flags.FlagHome)), "data", "snapshots") + err = os.MkdirAll(snapshotDir, os.ModePerm) + if err != nil { + panic(err) + } + snapshotDB, err := dbm.NewDB("metadata", sdkserver.GetAppDBBackend(appOpts), snapshotDir) if err != nil { panic(err) diff --git a/server/start.go b/server/start.go index 22162e05b7..64bca681f5 100644 --- a/server/start.go +++ b/server/start.go @@ -45,6 +45,8 @@ import ( srvflags "github.com/evmos/ethermint/server/flags" ) +const FlagAppDBBackend = "app-db-backend" + // StartCmd runs the service passed in, either stand-alone or in-process with // Tendermint. func StartCmd(appCreator types.AppCreator, defaultNodeHome string) *cobra.Command { @@ -141,6 +143,7 @@ which accepts a path for the resulting pprof file. cmd.Flags().Uint64(server.FlagPruningInterval, 0, "Height interval at which pruned heights are removed from disk (ignored if pruning is not 'custom')") cmd.Flags().Uint(server.FlagInvCheckPeriod, 0, "Assert registered invariants every N blocks") cmd.Flags().Uint64(server.FlagMinRetainBlocks, 0, "Minimum block height offset during ABCI commit to prune Tendermint blocks") + cmd.Flags().String(FlagAppDBBackend, "", "The type of database for application and snapshots databases") cmd.Flags().Bool(srvflags.GRPCEnable, true, "Define if the gRPC server should be enabled") cmd.Flags().String(srvflags.GRPCAddress, serverconfig.DefaultGRPCAddress, "the gRPC server address to listen on") From 6676b74657d1956002ca6a9f527f8eb2baa67daf Mon Sep 17 00:00:00 2001 From: HuangYi Date: Fri, 5 Aug 2022 14:22:41 +0800 Subject: [PATCH 2/4] address pr reviews --- CHANGELOG.md | 2 +- cmd/ethermintd/root.go | 3 +-- server/flags/flags.go | 3 ++- server/start.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 271171cc90..39b7b35f6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,7 +50,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements * (feemarket) [\#1165](https://github.com/evmos/ethermint/pull/1165) Add hint in specs about different gas terminology for gas in Cosmos and Ethereum. -* (cli) []() Add custom app db backend flag. +* (cli) [#1226](https://github.com/evmos/ethermint/pull/1226) Add custom app db backend flag. ### Bug Fixes diff --git a/cmd/ethermintd/root.go b/cmd/ethermintd/root.go index d7ec96ba81..5e17d8de06 100644 --- a/cmd/ethermintd/root.go +++ b/cmd/ethermintd/root.go @@ -210,8 +210,7 @@ func (a appCreator) newApp(logger tmlog.Logger, db dbm.DB, traceStore io.Writer, } snapshotDir := filepath.Join(cast.ToString(appOpts.Get(flags.FlagHome)), "data", "snapshots") - err = os.MkdirAll(snapshotDir, os.ModePerm) - if err != nil { + if err = os.MkdirAll(snapshotDir, os.ModePerm); err != nil { panic(err) } diff --git a/server/flags/flags.go b/server/flags/flags.go index dc98e86ada..9e1f29d72b 100644 --- a/server/flags/flags.go +++ b/server/flags/flags.go @@ -7,13 +7,14 @@ import ( "github.com/spf13/viper" ) -// Tendermint full-node start flags +// Tendermint/cosmos-sdk full-node start flags const ( WithTendermint = "with-tendermint" Address = "address" Transport = "transport" TraceStore = "trace-store" CPUProfile = "cpu-profile" + AppDBBackend = "app-db-backend" ) // GRPC-related flags. diff --git a/server/start.go b/server/start.go index 64bca681f5..84353dfea4 100644 --- a/server/start.go +++ b/server/start.go @@ -143,7 +143,7 @@ which accepts a path for the resulting pprof file. cmd.Flags().Uint64(server.FlagPruningInterval, 0, "Height interval at which pruned heights are removed from disk (ignored if pruning is not 'custom')") cmd.Flags().Uint(server.FlagInvCheckPeriod, 0, "Assert registered invariants every N blocks") cmd.Flags().Uint64(server.FlagMinRetainBlocks, 0, "Minimum block height offset during ABCI commit to prune Tendermint blocks") - cmd.Flags().String(FlagAppDBBackend, "", "The type of database for application and snapshots databases") + cmd.Flags().String(srvflags.AppDBBackend, "", "The type of database for application and snapshots databases") cmd.Flags().Bool(srvflags.GRPCEnable, true, "Define if the gRPC server should be enabled") cmd.Flags().String(srvflags.GRPCAddress, serverconfig.DefaultGRPCAddress, "the gRPC server address to listen on") From 57ef02c253938509f068c56c88dd3cba048051a2 Mon Sep 17 00:00:00 2001 From: HuangYi Date: Fri, 5 Aug 2022 14:23:33 +0800 Subject: [PATCH 3/4] add comment --- server/flags/flags.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/flags/flags.go b/server/flags/flags.go index 9e1f29d72b..67fb0cc791 100644 --- a/server/flags/flags.go +++ b/server/flags/flags.go @@ -14,7 +14,8 @@ const ( Transport = "transport" TraceStore = "trace-store" CPUProfile = "cpu-profile" - AppDBBackend = "app-db-backend" + // The type of database for application and snapshots databases + AppDBBackend = "app-db-backend" ) // GRPC-related flags. From 2d4757fa893c0f4538a5fec7bcbbcdc3f41d6b22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?= <31522760+fedekunze@users.noreply.github.com> Date: Fri, 5 Aug 2022 11:27:18 +0200 Subject: [PATCH 4/4] Update server/start.go --- server/start.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/server/start.go b/server/start.go index 84353dfea4..c4e979f309 100644 --- a/server/start.go +++ b/server/start.go @@ -45,8 +45,6 @@ import ( srvflags "github.com/evmos/ethermint/server/flags" ) -const FlagAppDBBackend = "app-db-backend" - // StartCmd runs the service passed in, either stand-alone or in-process with // Tendermint. func StartCmd(appCreator types.AppCreator, defaultNodeHome string) *cobra.Command {