Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: removed deprecated sdk.DBBackend variable #12355

Merged
merged 14 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
# Changelog

## [Unreleased]

* (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
deepto98 marked this conversation as resolved.
Show resolved Hide resolved
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
### Features

* (cli) [#12028](https://github.com/cosmos/cosmos-sdk/pull/12028) Add the `tendermint key-migrate` to perform Tendermint v0.35 DB key migration.
Expand Down
4 changes: 1 addition & 3 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
Expand Down
76 changes: 0 additions & 76 deletions server/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@ 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"
"github.com/cosmos/cosmos-sdk/server"
"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"
)
Expand Down Expand Up @@ -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)
})
}
}
9 changes: 1 addition & 8 deletions types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down