From da11e561b730552310d7f5e263e5915ef625ad02 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 16 Aug 2023 20:29:41 +0200 Subject: [PATCH] fix: use correct config key for db_backend (#17406) Co-authored-by: Kevin Yang <5478483+k-yang@users.noreply.github.com> --- CHANGELOG.md | 1 + server/config/toml.go | 3 +-- server/util.go | 2 +- server/util_test.go | 11 +++++++++++ tools/confix/data/v0.47-app.toml | 10 ++++------ tools/confix/data/v0.50-app.toml | 6 ++---- 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2c84f254f3cd..c711041cdd687 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +* (server) [#17181](https://github.com/cosmos/cosmos-sdk/pull/17181) Fix `db_backend` lookup fallback from `config.toml`. * (runtime) [#17284](https://github.com/cosmos/cosmos-sdk/pull/17284) Properly allow to combine depinject-enabled modules and non-depinject-enabled modules in app v2. * (baseapp) [#17251](https://github.com/cosmos/cosmos-sdk/pull/17251) VerifyVoteExtensions and ExtendVote initialize their own contexts/states, allowing VerifyVoteExtensions being called without ExtendVote. * (x/auth) [#17209](https://github.com/cosmos/cosmos-sdk/pull/17209) Internal error on AccountInfo when account's public key is not set. diff --git a/server/config/toml.go b/server/config/toml.go index 903303073a668..8c0a615cd9551 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -83,8 +83,7 @@ iavl-disable-fastnode = {{ .BaseConfig.IAVLDisableFastNode }} # AppDBBackend defines the database backend type to use for the application and snapshots DBs. # An empty string indicates that a fallback will be used. -# First fallback is the deprecated compile-time types.DBBackend value. -# Second fallback (if the types.DBBackend also isn't set), is the db-backend value set in CometBFT's config.toml. +# The fallback is the db_backend value set in CometBFT's config.toml. app-db-backend = "{{ .BaseConfig.AppDBBackend }}" ############################################################################### diff --git a/server/util.go b/server/util.go index 4570ecd331368..521a61d410900 100644 --- a/server/util.go +++ b/server/util.go @@ -403,7 +403,7 @@ func ListenForQuitSignals(g *errgroup.Group, block bool, cancelFn context.Cancel func GetAppDBBackend(opts types.AppOptions) dbm.BackendType { rv := cast.ToString(opts.Get("app-db-backend")) if len(rv) == 0 { - rv = cast.ToString(opts.Get("db-backend")) + rv = cast.ToString(opts.Get("db_backend")) } // Cosmos SDK has migrated to cosmos-db which does not support all the backends which tm-db supported diff --git a/server/util_test.go b/server/util_test.go index 9f88823808936..1ca5c0dab9c5c 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -11,7 +11,9 @@ import ( "testing" cmtcfg "github.com/cometbft/cometbft/config" + db "github.com/cosmos/cosmos-db" "github.com/spf13/cobra" + "github.com/spf13/viper" "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/client" @@ -37,6 +39,15 @@ func preRunETestImpl(cmd *cobra.Command, args []string) error { return errCanceledInPreRun } +func TestGetAppDBBackend(t *testing.T) { + v := viper.New() + require.Equal(t, server.GetAppDBBackend(v), db.GoLevelDBBackend) + v.Set("db_backend", "dbtype1") // value from CometBFT config + require.Equal(t, server.GetAppDBBackend(v), db.BackendType("dbtype1")) + v.Set("app-db-backend", "dbtype2") // value from app.toml + require.Equal(t, server.GetAppDBBackend(v), db.BackendType("dbtype2")) +} + func TestInterceptConfigsPreRunHandlerCreatesConfigFilesWhenMissing(t *testing.T) { tempDir := t.TempDir() cmd := server.StartCmd(nil) diff --git a/tools/confix/data/v0.47-app.toml b/tools/confix/data/v0.47-app.toml index c45f5f246bddf..c1f239f98e40c 100644 --- a/tools/confix/data/v0.47-app.toml +++ b/tools/confix/data/v0.47-app.toml @@ -72,8 +72,7 @@ iavl-lazy-loading = false # AppDBBackend defines the database backend type to use for the application and snapshots DBs. # An empty string indicates that a fallback will be used. -# First fallback is the deprecated compile-time types.DBBackend value. -# Second fallback (if the types.DBBackend also isn't set), is the db-backend value set in Tendermint's config.toml. +# The fallback is the db_backend value set in Tendermint's config.toml. app-db-backend = "" ############################################################################### @@ -107,8 +106,7 @@ prometheus-retention-time = 0 # # Example: # [["chain_id", "cosmoshub-1"]] -global-labels = [ -] +global-labels = [] ############################################################################### ### API Configuration ### @@ -236,7 +234,7 @@ streamers = [] [streamers] [streamers.file] -keys = ["*", ] +keys = ["*"] write_dir = "" prefix = "" @@ -268,4 +266,4 @@ max-txs = "5000" query_gas_limit = 300000 # This is the number of wasm vm instances we keep cached in memory for speed-up # Warning: this is currently unstable and may lead to crashes, best to keep for 0 unless testing locally -lru_size = 0 \ No newline at end of file +lru_size = 0 diff --git a/tools/confix/data/v0.50-app.toml b/tools/confix/data/v0.50-app.toml index 5e01e120d8b09..7de64885d5152 100644 --- a/tools/confix/data/v0.50-app.toml +++ b/tools/confix/data/v0.50-app.toml @@ -72,8 +72,7 @@ iavl-disable-fastnode = false # AppDBBackend defines the database backend type to use for the application and snapshots DBs. # An empty string indicates that a fallback will be used. -# First fallback is the deprecated compile-time types.DBBackend value. -# Second fallback (if the types.DBBackend also isn't set), is the db-backend value set in CometBFT's config.toml. +# The fallback is the db_backend value set in CometBFT's config.toml. app-db-backend = "" ############################################################################### @@ -107,8 +106,7 @@ prometheus-retention-time = 0 # # Example: # [["chain_id", "cosmoshub-1"]] -global-labels = [ -] +global-labels = [] ############################################################################### ### API Configuration ###