Skip to content

Commit

Permalink
Merge PR #3792: Use DBBackend set at compile time
Browse files Browse the repository at this point in the history
* use DBBackend set at compile time

Closes: #3719

* Refresh changelog

* Tweak Makefile
  • Loading branch information
alessio authored and cwgoes committed Mar 4, 2019
1 parent c7f6a3e commit 3e82a8b
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 54 deletions.
58 changes: 38 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,24 @@ PACKAGES_NOSIMULATION=$(shell go list ./... | grep -v '/simulation')
PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation')
VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
COMMIT := $(shell git log -1 --format='%H')
BUILD_TAGS = netgo
CAT := $(if $(filter $(OS),Windows_NT),type,cat)
BUILD_FLAGS = -tags "$(BUILD_TAGS)" -ldflags \
'-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X github.com/cosmos/cosmos-sdk/version.VendorDirHash=$(shell $(CAT) vendor-deps) \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(BUILD_TAGS)"'
LEDGER_ENABLED ?= true
GOTOOLS = \
github.com/golang/dep/cmd/dep \
github.com/alecthomas/gometalinter \
github.com/rakyll/statik
GOBIN ?= $(GOPATH)/bin

all: devtools vendor-deps install test_lint test

# The below include contains the tools target.
include scripts/Makefile

########################################
### CI

ci: devtools vendor-deps install test_cover test_lint test

########################################
### Build/Install
# process build tags

build_tags = netgo
ifeq ($(LEDGER_ENABLED),true)
ifeq ($(OS),Windows_NT)
GCCEXE = $(shell where gcc.exe 2> NUL)
ifeq ($(GCCEXE),)
$(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
BUILD_TAGS += ledger
build_tags += ledger
endif
else
UNAME_S = $(shell uname -s)
Expand All @@ -46,12 +30,46 @@ ifeq ($(LEDGER_ENABLED),true)
ifeq ($(GCC),)
$(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
BUILD_TAGS += ledger
build_tags += ledger
endif
endif
endif
endif

ifeq ($(WITH_CLEVELDB),yes)
build_tags += gcc
endif
build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))

# process linker flags

ldflags = -X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X github.com/cosmos/cosmos-sdk/version.VendorDirHash=$(shell $(CAT) vendor-deps) \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags)"

ifeq ($(WITH_CLEVELDB),yes)
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb
endif
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))

BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'

all: devtools vendor-deps install test_lint test

# The below include contains the tools target.
include scripts/Makefile

########################################
### CI

ci: devtools vendor-deps install test_cover test_lint test

########################################
### Build/Install

build:
ifeq ($(OS),Windows_NT)
go build $(BUILD_FLAGS) -o build/gaiad.exe ./cmd/gaia/cmd/gaiad
Expand Down
3 changes: 3 additions & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ tags.

### SDK

* [\#3719](https://github.com/cosmos/cosmos-sdk/issues/3719) DBBackend can now be set at compile time.
Defaults: goleveldb. Supported: cleveldb.

### Tendermint

<!------------------------------- IMPROVEMENTS ------------------------------->
Expand Down
12 changes: 6 additions & 6 deletions cmd/gaia/app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func BenchmarkFullGaiaSimulation(b *testing.B) {

var db dbm.DB
dir, _ := ioutil.TempDir("", "goleveldb-gaia-sim")
db, _ = dbm.NewGoLevelDB("Simulation", dir)
db, _ = sdk.NewLevelDB("Simulation", dir)
defer func() {
db.Close()
os.RemoveAll(dir)
Expand Down Expand Up @@ -347,7 +347,7 @@ func TestFullGaiaSimulation(t *testing.T) {
}
var db dbm.DB
dir, _ := ioutil.TempDir("", "goleveldb-gaia-sim")
db, _ = dbm.NewGoLevelDB("Simulation", dir)
db, _ = sdk.NewLevelDB("Simulation", dir)
defer func() {
db.Close()
os.RemoveAll(dir)
Expand Down Expand Up @@ -388,7 +388,7 @@ func TestGaiaImportExport(t *testing.T) {
}
var db dbm.DB
dir, _ := ioutil.TempDir("", "goleveldb-gaia-sim")
db, _ = dbm.NewGoLevelDB("Simulation", dir)
db, _ = sdk.NewLevelDB("Simulation", dir)
defer func() {
db.Close()
os.RemoveAll(dir)
Expand Down Expand Up @@ -421,7 +421,7 @@ func TestGaiaImportExport(t *testing.T) {
fmt.Printf("Importing genesis...\n")

newDir, _ := ioutil.TempDir("", "goleveldb-gaia-sim-2")
newDB, _ := dbm.NewGoLevelDB("Simulation-2", dir)
newDB, _ := sdk.NewLevelDB("Simulation-2", dir)
defer func() {
newDB.Close()
os.RemoveAll(newDir)
Expand Down Expand Up @@ -483,7 +483,7 @@ func TestGaiaSimulationAfterImport(t *testing.T) {
logger = log.NewNopLogger()
}
dir, _ := ioutil.TempDir("", "goleveldb-gaia-sim")
db, _ := dbm.NewGoLevelDB("Simulation", dir)
db, _ := sdk.NewLevelDB("Simulation", dir)
defer func() {
db.Close()
os.RemoveAll(dir)
Expand Down Expand Up @@ -525,7 +525,7 @@ func TestGaiaSimulationAfterImport(t *testing.T) {
fmt.Printf("Importing genesis...\n")

newDir, _ := ioutil.TempDir("", "goleveldb-gaia-sim-2")
newDB, _ := dbm.NewGoLevelDB("Simulation-2", dir)
newDB, _ := sdk.NewLevelDB("Simulation-2", dir)
defer func() {
newDB.Close()
os.RemoveAll(newDir)
Expand Down
2 changes: 1 addition & 1 deletion cmd/gaia/cmd/gaiadebug/hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func runHackCmd(cmd *cobra.Command, args []string) error {

// load the app
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
db, err := dbm.NewGoLevelDB("gaia", dataDir)
db, err := sdk.NewLevelDB("gaia", dataDir)
if err != nil {
fmt.Println(err)
os.Exit(1)
Expand Down
8 changes: 4 additions & 4 deletions cmd/gaia/cmd/gaiareplay/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
bcm "github.com/tendermint/tendermint/blockchain"
cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/proxy"
tmsm "github.com/tendermint/tendermint/state"
tm "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
"github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
)

var (
Expand Down Expand Up @@ -72,22 +72,22 @@ func run(rootDir string) {
// App DB
// appDB := dbm.NewMemDB()
fmt.Println("Opening app database")
appDB, err := dbm.NewGoLevelDB("application", dataDir)
appDB, err := sdk.NewLevelDB("application", dataDir)
if err != nil {
panic(err)
}

// TM DB
// tmDB := dbm.NewMemDB()
fmt.Println("Opening tendermint state database")
tmDB, err := dbm.NewGoLevelDB("state", dataDir)
tmDB, err := sdk.NewLevelDB("state", dataDir)
if err != nil {
panic(err)
}

// Blockchain DB
fmt.Println("Opening blockstore database")
bcDB, err := dbm.NewGoLevelDB("blockstore", dataDir)
bcDB, err := sdk.NewLevelDB("blockstore", dataDir)
if err != nil {
panic(err)
}
Expand Down
39 changes: 19 additions & 20 deletions crypto/keys/lazy_keybase.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import (

"github.com/tendermint/tendermint/crypto"
cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tendermint/libs/db"

"github.com/cosmos/cosmos-sdk/crypto/keys/hd"
"github.com/cosmos/cosmos-sdk/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

var _ Keybase = lazyKeybase{}
Expand All @@ -28,7 +27,7 @@ func New(name, dir string) Keybase {
}

func (lkb lazyKeybase) List() ([]Info, error) {
db, err := dbm.NewGoLevelDB(lkb.name, lkb.dir)
db, err := sdk.NewLevelDB(lkb.name, lkb.dir)
if err != nil {
return nil, err
}
Expand All @@ -38,7 +37,7 @@ func (lkb lazyKeybase) List() ([]Info, error) {
}

func (lkb lazyKeybase) Get(name string) (Info, error) {
db, err := dbm.NewGoLevelDB(lkb.name, lkb.dir)
db, err := sdk.NewLevelDB(lkb.name, lkb.dir)
if err != nil {
return nil, err
}
Expand All @@ -47,8 +46,8 @@ func (lkb lazyKeybase) Get(name string) (Info, error) {
return newDbKeybase(db).Get(name)
}

func (lkb lazyKeybase) GetByAddress(address types.AccAddress) (Info, error) {
db, err := dbm.NewGoLevelDB(lkb.name, lkb.dir)
func (lkb lazyKeybase) GetByAddress(address sdk.AccAddress) (Info, error) {
db, err := sdk.NewLevelDB(lkb.name, lkb.dir)
if err != nil {
return nil, err
}
Expand All @@ -58,7 +57,7 @@ func (lkb lazyKeybase) GetByAddress(address types.AccAddress) (Info, error) {
}

func (lkb lazyKeybase) Delete(name, passphrase string, skipPass bool) error {
db, err := dbm.NewGoLevelDB(lkb.name, lkb.dir)
db, err := sdk.NewLevelDB(lkb.name, lkb.dir)
if err != nil {
return err
}
Expand All @@ -68,7 +67,7 @@ func (lkb lazyKeybase) Delete(name, passphrase string, skipPass bool) error {
}

func (lkb lazyKeybase) Sign(name, passphrase string, msg []byte) ([]byte, crypto.PubKey, error) {
db, err := dbm.NewGoLevelDB(lkb.name, lkb.dir)
db, err := sdk.NewLevelDB(lkb.name, lkb.dir)
if err != nil {
return nil, nil, err
}
Expand All @@ -78,7 +77,7 @@ func (lkb lazyKeybase) Sign(name, passphrase string, msg []byte) ([]byte, crypto
}

func (lkb lazyKeybase) CreateMnemonic(name string, language Language, passwd string, algo SigningAlgo) (info Info, seed string, err error) {
db, err := dbm.NewGoLevelDB(lkb.name, lkb.dir)
db, err := sdk.NewLevelDB(lkb.name, lkb.dir)
if err != nil {
return nil, "", err
}
Expand All @@ -88,7 +87,7 @@ func (lkb lazyKeybase) CreateMnemonic(name string, language Language, passwd str
}

func (lkb lazyKeybase) CreateAccount(name, mnemonic, bip39Passwd, encryptPasswd string, account uint32, index uint32) (Info, error) {
db, err := dbm.NewGoLevelDB(lkb.name, lkb.dir)
db, err := sdk.NewLevelDB(lkb.name, lkb.dir)
if err != nil {
return nil, err
}
Expand All @@ -98,7 +97,7 @@ func (lkb lazyKeybase) CreateAccount(name, mnemonic, bip39Passwd, encryptPasswd
}

func (lkb lazyKeybase) Derive(name, mnemonic, bip39Passwd, encryptPasswd string, params hd.BIP44Params) (Info, error) {
db, err := dbm.NewGoLevelDB(lkb.name, lkb.dir)
db, err := sdk.NewLevelDB(lkb.name, lkb.dir)
if err != nil {
return nil, err
}
Expand All @@ -108,7 +107,7 @@ func (lkb lazyKeybase) Derive(name, mnemonic, bip39Passwd, encryptPasswd string,
}

func (lkb lazyKeybase) CreateLedger(name string, algo SigningAlgo, account uint32, index uint32) (info Info, err error) {
db, err := dbm.NewGoLevelDB(lkb.name, lkb.dir)
db, err := sdk.NewLevelDB(lkb.name, lkb.dir)
if err != nil {
return nil, err
}
Expand All @@ -118,7 +117,7 @@ func (lkb lazyKeybase) CreateLedger(name string, algo SigningAlgo, account uint3
}

func (lkb lazyKeybase) CreateOffline(name string, pubkey crypto.PubKey) (info Info, err error) {
db, err := dbm.NewGoLevelDB(lkb.name, lkb.dir)
db, err := sdk.NewLevelDB(lkb.name, lkb.dir)
if err != nil {
return nil, err
}
Expand All @@ -128,7 +127,7 @@ func (lkb lazyKeybase) CreateOffline(name string, pubkey crypto.PubKey) (info In
}

func (lkb lazyKeybase) CreateMulti(name string, pubkey crypto.PubKey) (info Info, err error) {
db, err := dbm.NewGoLevelDB(lkb.name, lkb.dir)
db, err := sdk.NewLevelDB(lkb.name, lkb.dir)
if err != nil {
return nil, err
}
Expand All @@ -138,7 +137,7 @@ func (lkb lazyKeybase) CreateMulti(name string, pubkey crypto.PubKey) (info Info
}

func (lkb lazyKeybase) Update(name, oldpass string, getNewpass func() (string, error)) error {
db, err := dbm.NewGoLevelDB(lkb.name, lkb.dir)
db, err := sdk.NewLevelDB(lkb.name, lkb.dir)
if err != nil {
return err
}
Expand All @@ -148,7 +147,7 @@ func (lkb lazyKeybase) Update(name, oldpass string, getNewpass func() (string, e
}

func (lkb lazyKeybase) Import(name string, armor string) (err error) {
db, err := dbm.NewGoLevelDB(lkb.name, lkb.dir)
db, err := sdk.NewLevelDB(lkb.name, lkb.dir)
if err != nil {
return err
}
Expand All @@ -158,7 +157,7 @@ func (lkb lazyKeybase) Import(name string, armor string) (err error) {
}

func (lkb lazyKeybase) ImportPubKey(name string, armor string) (err error) {
db, err := dbm.NewGoLevelDB(lkb.name, lkb.dir)
db, err := sdk.NewLevelDB(lkb.name, lkb.dir)
if err != nil {
return err
}
Expand All @@ -168,7 +167,7 @@ func (lkb lazyKeybase) ImportPubKey(name string, armor string) (err error) {
}

func (lkb lazyKeybase) Export(name string) (armor string, err error) {
db, err := dbm.NewGoLevelDB(lkb.name, lkb.dir)
db, err := sdk.NewLevelDB(lkb.name, lkb.dir)
if err != nil {
return "", err
}
Expand All @@ -178,7 +177,7 @@ func (lkb lazyKeybase) Export(name string) (armor string, err error) {
}

func (lkb lazyKeybase) ExportPubKey(name string) (armor string, err error) {
db, err := dbm.NewGoLevelDB(lkb.name, lkb.dir)
db, err := sdk.NewLevelDB(lkb.name, lkb.dir)
if err != nil {
return "", err
}
Expand All @@ -188,7 +187,7 @@ func (lkb lazyKeybase) ExportPubKey(name string) (armor string, err error) {
}

func (lkb lazyKeybase) ExportPrivateKeyObject(name string, passphrase string) (crypto.PrivKey, error) {
db, err := dbm.NewGoLevelDB(lkb.name, lkb.dir)
db, err := sdk.NewLevelDB(lkb.name, lkb.dir)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion server/constructors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path/filepath"

sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log"
Expand All @@ -24,7 +25,7 @@ type (

func openDB(rootDir string) (dbm.DB, error) {
dataDir := filepath.Join(rootDir, "data")
db, err := dbm.NewGoLevelDB("application", dataDir)
db, err := sdk.NewLevelDB("application", dataDir)
return db, err
}

Expand Down
Loading

0 comments on commit 3e82a8b

Please sign in to comment.