Skip to content

Commit

Permalink
chore: use default db backend among the available ones (#212)
Browse files Browse the repository at this point in the history
* chore: use default db backend among the available ones

* chore: bump up iavl, tm-db
  • Loading branch information
Woosang Son authored Apr 6, 2021
1 parent 4bc528a commit 4183d64
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 15 deletions.
18 changes: 15 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"os"
"path/filepath"
"time"

"github.com/line/tm-db/v2/metadb"
)

const (
Expand All @@ -23,6 +25,8 @@ const (

// DefaultLogLevel defines a default log level as INFO.
DefaultLogLevel = "info"

DefaultDBBackend = "goleveldb"
)

// NOTE: Most of the structs & relevant comments + the
Expand Down Expand Up @@ -218,8 +222,16 @@ type BaseConfig struct { //nolint: maligned
FilterPeers bool `mapstructure:"filter_peers"` // false
}

// DefaultBaseConfig returns a default base configuration for a Tendermint node
// DefaultBaseConfig returns a default base configuration for a Ostracon node
func DefaultBaseConfig() BaseConfig {
dbs := metadb.AvailableDBBackends()
defaultDBBackend := DefaultDBBackend
for _, b := range dbs {
defaultDBBackend = string(b)
if defaultDBBackend == DefaultDBBackend {
break
}
}
return BaseConfig{
Genesis: defaultGenesisJSONPath,
PrivValidatorKey: defaultPrivValKeyPath,
Expand All @@ -232,12 +244,12 @@ func DefaultBaseConfig() BaseConfig {
LogFormat: LogFormatPlain,
FastSyncMode: true,
FilterPeers: false,
DBBackend: "goleveldb",
DBBackend: defaultDBBackend,
DBPath: "data",
}
}

// TestBaseConfig returns a base configuration for testing a Tendermint node
// TestBaseConfig returns a base configuration for testing a Ostracon node
func TestBaseConfig() BaseConfig {
cfg := DefaultBaseConfig()
cfg.chainID = "tendermint_test"
Expand Down
4 changes: 2 additions & 2 deletions evidence/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ func (evpool *Pool) listEvidence(prefixKey byte, maxBytes int64) ([]types.Eviden
evList tmproto.EvidenceList // used for calculating the bytes size
)

iter, err := tmdb.IteratePrefix(evpool.evidenceStore, []byte{prefixKey})
iter, err := evpool.evidenceStore.PrefixIterator([]byte{prefixKey})
if err != nil {
return nil, totalSize, fmt.Errorf("database error: %v", err)
}
Expand Down Expand Up @@ -459,7 +459,7 @@ func (evpool *Pool) listEvidence(prefixKey byte, maxBytes int64) ([]types.Eviden
}

func (evpool *Pool) removeExpiredPendingEvidence() (int64, time.Time) {
iter, err := tmdb.IteratePrefix(evpool.evidenceStore, []byte{baseKeyPending})
iter, err := evpool.evidenceStore.PrefixIterator([]byte{baseKeyPending})
if err != nil {
evpool.logger.Error("Unable to iterate over pending evidence", "err", err)
return evpool.State().LastBlockHeight, evpool.State().LastBlockTime
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ require (
github.com/gorilla/websocket v1.4.2
github.com/gtank/merlin v0.1.1
github.com/libp2p/go-buffer-pool v0.0.2
github.com/line/iavl/v2 v2.0.0-init.1.0.20210325055816-6304f1fd2f09
github.com/line/tm-db/v2 v2.0.0-init.1.0.20210325025547-0ea105c02281
github.com/line/iavl/v2 v2.0.0-init.1.0.20210406065347-cfd73e5acce0
github.com/line/tm-db/v2 v2.0.0-init.1.0.20210406062110-9424ca70955a
github.com/minio/highwayhash v1.0.1
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.8.0
Expand Down
14 changes: 10 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,14 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51 h1:0JZ+dUmQeA8IIVUMzysrX4/AKuQwWhV2dYQuPZdvdSQ=
github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64=
github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0=
github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64=
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojtoVVWjGfOF9635RETekkoH6Cc9SX0A=
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052/go.mod h1:UbMTZqLaRiH3MsBH8va0n7s1pQYcu3uTb8G4tygF4Zg=
github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870 h1:E2s37DuLxFhQDg5gKsWoLBOB0n+ZW8s599zru8FJ2/Y=
github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870/go.mod h1:5tD+neXqOorC30/tWg0LCSkrqj/AR6gu8yY8/fpw1q0=
github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 h1:7HZCaLC5+BZpmbhCOZJ293Lz68O7PYrF2EzeiFMwCLk=
github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4/go.mod h1:5tD+neXqOorC30/tWg0LCSkrqj/AR6gu8yY8/fpw1q0=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
Expand Down Expand Up @@ -319,11 +323,13 @@ github.com/libp2p/go-buffer-pool v0.0.2 h1:QNK2iAFa8gjAe1SPz6mHSMuCcjs+X1wlHzeOS
github.com/libp2p/go-buffer-pool v0.0.2/go.mod h1:MvaB6xw5vOrDl8rYZGLFdKAuk/hRoRZd1Vi32+RXyFM=
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
github.com/line/iavl/v2 v2.0.0-init.1.0.20210325055816-6304f1fd2f09 h1:11L4wU4iYYRfOP20qo7909Q0gkd1NG8GOjSPu3Bblcg=
github.com/line/iavl/v2 v2.0.0-init.1.0.20210325055816-6304f1fd2f09/go.mod h1:lOUXCMWnB9G5wDfungP5nhnHAFgVBwB0/iqFhH44OIs=
github.com/line/gorocksdb v0.0.0-20210406043732-d4bea34b6d55 h1:cXVtMiJkvQ4kn0pxM2svH1ncJbFgQsLHtnFC9qJj2VM=
github.com/line/gorocksdb v0.0.0-20210406043732-d4bea34b6d55/go.mod h1:DHRJroSL7NaRkpvocRx3OtRsleXVsYSxBI9SfHFlTQ0=
github.com/line/iavl/v2 v2.0.0-init.1.0.20210406065347-cfd73e5acce0 h1:Pcp/mxkvFmasaiPi9DS2ZXCKOalfDGtBKYjdswmF0nI=
github.com/line/iavl/v2 v2.0.0-init.1.0.20210406065347-cfd73e5acce0/go.mod h1:Z2UTxsbKefd7bnEywGNxxmVYYGy9Ecd4nd1IZyR0bQM=
github.com/line/ostracon v0.34.9-0.20210315041958-2a1f43c788f5/go.mod h1:1THU+kF+6fxLaNYQKcdNyLCO6t9LnqSMaExDMiLozbM=
github.com/line/tm-db/v2 v2.0.0-init.1.0.20210325025547-0ea105c02281 h1:HwehzGvsgPHND01825UbjjiKgwfbqIYFAnvn6OheLQs=
github.com/line/tm-db/v2 v2.0.0-init.1.0.20210325025547-0ea105c02281/go.mod h1:TiTwPFffNAqep0nV0YWaxPjElbCp6yG4K8SCxy69mE4=
github.com/line/tm-db/v2 v2.0.0-init.1.0.20210406062110-9424ca70955a h1:qSt/WwORC5+nVRnNqx+A0oo5gOCsoVJ0HmHF5Db1YvY=
github.com/line/tm-db/v2 v2.0.0-init.1.0.20210406062110-9424ca70955a/go.mod h1:wmkyPabXjtVZ1dvRofmurjaceghywtCSYGqFuFS+TbI=
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=
Expand Down
8 changes: 4 additions & 4 deletions state/txindex/kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func (txi *TxIndex) match(

switch {
case c.Op == query.OpEqual:
it, err := tmdb.IteratePrefix(txi.store, startKeyBz)
it, err := txi.store.PrefixIterator(startKeyBz)
if err != nil {
panic(err)
}
Expand All @@ -430,7 +430,7 @@ func (txi *TxIndex) match(
case c.Op == query.OpExists:
// XXX: can't use startKeyBz here because c.Operand is nil
// (e.g. "account.owner/<nil>/" won't match w/ a single row)
it, err := tmdb.IteratePrefix(txi.store, startKey(c.CompositeKey))
it, err := txi.store.PrefixIterator(startKey(c.CompositeKey))
if err != nil {
panic(err)
}
Expand All @@ -454,7 +454,7 @@ func (txi *TxIndex) match(
// XXX: startKey does not apply here.
// For example, if startKey = "account.owner/an/" and search query = "account.owner CONTAINS an"
// we can't iterate with prefix "account.owner/an/" because we might miss keys like "account.owner/Ulan/"
it, err := tmdb.IteratePrefix(txi.store, startKey(c.CompositeKey))
it, err := txi.store.PrefixIterator(startKey(c.CompositeKey))
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -534,7 +534,7 @@ func (txi *TxIndex) matchRange(
lowerBound := r.lowerBoundValue()
upperBound := r.upperBoundValue()

it, err := tmdb.IteratePrefix(txi.store, startKey)
it, err := txi.store.PrefixIterator(startKey)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 4183d64

Please sign in to comment.