From fd7cdd6b7ab6b29be2abd4ad263d49b876ef851f Mon Sep 17 00:00:00 2001 From: Deepto Date: Fri, 8 Jul 2022 12:37:58 +0530 Subject: [PATCH] fix: removed deprecated sdk.DBBackend variable (#12355) ## Description Closes: #11410 #11241 --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) --- CHANGELOG.md | 4 +++ server/util.go | 4 +-- server/util_test.go | 76 --------------------------------------------- types/utils.go | 9 +----- 4 files changed, 6 insertions(+), 87 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6174a6eda918..b0f29ae9ef19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] + +### API Breaking Changes + +* (types) [\#12355](https://github.com/cosmos/cosmos-sdk/pull/12355) Remove the compile-time `types.DBbackend` variable. Removes usage of the same in server/util.go ### Features * (cli) [#12028](https://github.com/cosmos/cosmos-sdk/pull/12028) Add the `tendermint key-migrate` to perform Tendermint v0.35 DB key migration. diff --git a/server/util.go b/server/util.go index a201442025a1..ed0d8db04f60 100644 --- a/server/util.go +++ b/server/util.go @@ -365,9 +365,7 @@ func WaitForQuitSignals() ErrorCode { // GetAppDBBackend gets the backend type to use for the application DBs. func GetAppDBBackend(opts types.AppOptions) dbm.BackendType { rv := cast.ToString(opts.Get("app-db-backend")) - if len(rv) == 0 { - rv = sdk.DBBackend - } + if len(rv) == 0 { rv = cast.ToString(opts.Get("db-backend")) } diff --git a/server/util_test.go b/server/util_test.go index 37e23e8d5f94..c3bd0f9063cd 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -11,10 +11,8 @@ import ( "testing" "github.com/spf13/cobra" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" tmcfg "github.com/tendermint/tendermint/config" - dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -22,7 +20,6 @@ import ( "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/simapp" - "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" ) @@ -450,76 +447,3 @@ func (m mapGetter) Get(key string) interface{} { } var _ servertypes.AppOptions = mapGetter{} - -func TestGetAppDBBackend(t *testing.T) { - origDBBackend := types.DBBackend - defer func() { - types.DBBackend = origDBBackend - }() - tests := []struct { - name string - dbBack string - opts mapGetter - exp dbm.BackendType - }{ - { - name: "nothing set", - dbBack: "", - opts: mapGetter{}, - exp: dbm.GoLevelDBBackend, - }, - - { - name: "only db-backend set", - dbBack: "", - opts: mapGetter{"db-backend": "db-backend value 1"}, - exp: dbm.BackendType("db-backend value 1"), - }, - { - name: "only DBBackend set", - dbBack: "DBBackend value 2", - opts: mapGetter{}, - exp: dbm.BackendType("DBBackend value 2"), - }, - { - name: "only app-db-backend set", - dbBack: "", - opts: mapGetter{"app-db-backend": "app-db-backend value 3"}, - exp: dbm.BackendType("app-db-backend value 3"), - }, - - { - name: "app-db-backend and db-backend set", - dbBack: "", - opts: mapGetter{"db-backend": "db-backend value 4", "app-db-backend": "app-db-backend value 5"}, - exp: dbm.BackendType("app-db-backend value 5"), - }, - { - name: "app-db-backend and DBBackend set", - dbBack: "DBBackend value 6", - opts: mapGetter{"app-db-backend": "app-db-backend value 7"}, - exp: dbm.BackendType("app-db-backend value 7"), - }, - { - name: "db-backend and DBBackend set", - dbBack: "DBBackend value 8", - opts: mapGetter{"db-backend": "db-backend value 9"}, - exp: dbm.BackendType("DBBackend value 8"), - }, - - { - name: "all of app-db-backend db-backend DBBackend set", - dbBack: "DBBackend value 10", - opts: mapGetter{"db-backend": "db-backend value 11", "app-db-backend": "app-db-backend value 12"}, - exp: dbm.BackendType("app-db-backend value 12"), - }, - } - - for _, tc := range tests { - t.Run(tc.name, func(st *testing.T) { - types.DBBackend = tc.dbBack - act := server.GetAppDBBackend(tc.opts) - assert.Equal(st, tc.exp, act) - }) - } -} diff --git a/types/utils.go b/types/utils.go index 50074f2b052d..7f10ce396c86 100644 --- a/types/utils.go +++ b/types/utils.go @@ -12,16 +12,9 @@ import ( var ( // This is set at compile time. Could be cleveldb, defaults is goleveldb. - DBBackend = "" // Deprecated: Use tendermint config's DBBackend value instead. - backend = dbm.GoLevelDBBackend + backend = dbm.GoLevelDBBackend ) -func init() { - if len(DBBackend) != 0 { - backend = dbm.BackendType(DBBackend) - } -} - // SortedJSON takes any JSON and returns it sorted by keys. Also, all white-spaces // are removed. // This method can be used to canonicalize JSON to be returned by GetSignBytes,