Skip to content

Commit

Permalink
Revert "feat: decouple cosmos-db (backport #874) (#887)"
Browse files Browse the repository at this point in the history
This reverts commit e019f74.
  • Loading branch information
tac0turtle committed Mar 6, 2024
1 parent e691ee9 commit f9e0be0
Show file tree
Hide file tree
Showing 31 changed files with 262 additions and 856 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ linters:
disable-all: true
enable:
- bodyclose
- depguard
- dogsled
- errcheck
- exportloopref
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ format:

# look into .golangci.yml for enabling / disabling linters
golangci_lint_cmd=golangci-lint
golangci_version=v1.55.2
golangci_version=v1.51.2

lint:
@echo "--> Running linter"
Expand Down
11 changes: 5 additions & 6 deletions basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import (
"testing"

"cosmossdk.io/log"
db "github.com/cosmos/cosmos-db"
iavlrand "github.com/cosmos/iavl/internal/rand"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

dbm "github.com/cosmos/iavl/db"
iavlrand "github.com/cosmos/iavl/internal/rand"
)

func TestBasic(t *testing.T) {
Expand Down Expand Up @@ -237,7 +236,7 @@ func TestUnit(t *testing.T) {
expectRemove(t11, 3, "((1 2) (4 5))")
}

func TestRemove(_ *testing.T) {
func TestRemove(t *testing.T) {
keyLen, dataLen := 16, 40

size := 10000
Expand Down Expand Up @@ -433,7 +432,7 @@ func TestIterateRange(t *testing.T) {
}

func TestPersistence(t *testing.T) {
db := dbm.NewMemDB()
db := db.NewMemDB()

// Create some random key value pairs
records := make(map[string]string)
Expand Down Expand Up @@ -496,7 +495,7 @@ func TestProof(t *testing.T) {
}

func TestTreeProof(t *testing.T) {
db := dbm.NewMemDB()
db := db.NewMemDB()
tree := NewMutableTree(db, 100, false, log.NewNopLogger())
hash := tree.Hash()
assert.Equal(t, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", hex.EncodeToString(hash))
Expand Down
2 changes: 1 addition & 1 deletion batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package iavl
import (
"sync"

dbm "github.com/cosmos/iavl/db"
dbm "github.com/cosmos/cosmos-db"
)

// BatchWithFlusher is a wrapper
Expand Down
9 changes: 4 additions & 5 deletions batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import (
"path/filepath"
"testing"

dbm "github.com/cosmos/cosmos-db"
"github.com/stretchr/testify/require"

dbm "github.com/cosmos/iavl/db"
)

func cleanupDBDir(dir, name string) {
Expand All @@ -28,16 +27,16 @@ func makeKey(n uint16) []byte {
}

func TestBatchWithFlusher(t *testing.T) {
testedBackends := []string{
"goleveldb",
testedBackends := []dbm.BackendType{
dbm.GoLevelDBBackend,
}

for _, backend := range testedBackends {
testBatchWithFlusher(t, backend)
}
}

func testBatchWithFlusher(t *testing.T, backend string) {
func testBatchWithFlusher(t *testing.T, backend dbm.BackendType) {
name := fmt.Sprintf("test_%x", randstr(12))
dir := t.TempDir()
db, err := dbm.NewDB(name, backend, dir)
Expand Down
16 changes: 8 additions & 8 deletions benchmarks/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"cosmossdk.io/log"
"github.com/stretchr/testify/require"

db "github.com/cosmos/cosmos-db"
"github.com/cosmos/iavl"
dbm "github.com/cosmos/iavl/db"
)

const historySize = 20
Expand All @@ -26,7 +26,7 @@ func randBytes(length int) []byte {
return key
}

func prepareTree(b *testing.B, db dbm.DB, size, keyLen, dataLen int) (*iavl.MutableTree, [][]byte) {
func prepareTree(b *testing.B, db db.DB, size, keyLen, dataLen int) (*iavl.MutableTree, [][]byte) {
t := iavl.NewMutableTree(db, size, false, log.NewNopLogger())
keys := make([][]byte, size)

Expand Down Expand Up @@ -147,7 +147,7 @@ func runIterationSlow(b *testing.B, t *iavl.MutableTree, expectedSize int) {
}
}

func iterate(b *testing.B, itr dbm.Iterator, expectedSize int) {
func iterate(b *testing.B, itr db.Iterator, expectedSize int) {
b.StartTimer()
keyValuePairs := make([][][]byte, 0, expectedSize)
for i := 0; i < expectedSize && itr.Valid(); i++ {
Expand Down Expand Up @@ -259,7 +259,7 @@ func BenchmarkRandomBytes(b *testing.B) {
}

type benchmark struct {
dbType string
dbType db.BackendType
initSize, blockSize int
keyLen, dataLen int
}
Expand Down Expand Up @@ -330,7 +330,7 @@ func runBenchmarks(b *testing.B, benchmarks []benchmark) {

// prepare a dir for the db and cleanup afterwards
dirName := fmt.Sprintf("./%s-db", prefix)
if bb.dbType == "rocksdb" {
if bb.dbType == db.RocksDBBackend {
_ = os.Mkdir(dirName, 0o755)
}

Expand All @@ -343,11 +343,11 @@ func runBenchmarks(b *testing.B, benchmarks []benchmark) {

// note that "" leads to nil backing db!
var (
d dbm.DB
d db.DB
err error
)
if bb.dbType != "nodb" {
d, err = dbm.NewDB("test", bb.dbType, dirName)
d, err = db.NewDB("test", bb.dbType, dirName)

if err != nil {
if strings.Contains(err.Error(), "unknown db_backend") {
Expand Down Expand Up @@ -376,7 +376,7 @@ func memUseMB() float64 {
return mb
}

func runSuite(b *testing.B, d dbm.DB, initSize, blockSize, keyLen, dataLen int) {
func runSuite(b *testing.B, d db.DB, initSize, blockSize, keyLen, dataLen int) {
// measure mem usage
runtime.GC()
init := memUseMB()
Expand Down
8 changes: 3 additions & 5 deletions benchmarks/cosmos-exim/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import (

"cosmossdk.io/log"
tmdb "github.com/cosmos/cosmos-db"

"github.com/cosmos/iavl"
idbm "github.com/cosmos/iavl/db"
)

// stores is the list of stores in the CosmosHub database
Expand Down Expand Up @@ -93,7 +91,7 @@ func runExport(dbPath string) (int64, map[string][]*iavl.ExportNode, error) {
if err != nil {
return 0, nil, err
}
tree := iavl.NewMutableTree(idbm.NewWrapper(tmdb.NewPrefixDB(ldb, []byte("s/k:main/"))), 0, false, log.NewNopLogger())
tree := iavl.NewMutableTree(tmdb.NewPrefixDB(ldb, []byte("s/k:main/")), 0, false, log.NewNopLogger())
version, err := tree.LoadVersion(0)
if err != nil {
return 0, nil, err
Expand All @@ -105,7 +103,7 @@ func runExport(dbPath string) (int64, map[string][]*iavl.ExportNode, error) {
totalStats := Stats{}
for _, name := range stores {
db := tmdb.NewPrefixDB(ldb, []byte("s/k:"+name+"/"))
tree := iavl.NewMutableTree(idbm.NewWrapper(db), 0, false, log.NewNopLogger())
tree := iavl.NewMutableTree(db, 0, false, log.NewNopLogger())

stats := Stats{}
export := make([]*iavl.ExportNode, 0, 100000)
Expand Down Expand Up @@ -170,7 +168,7 @@ func runImport(version int64, exports map[string][]*iavl.ExportNode) error {
if err != nil {
return err
}
newTree := iavl.NewMutableTree(idbm.NewWrapper(newDB), 0, false, log.NewNopLogger())
newTree := iavl.NewMutableTree(newDB, 0, false, log.NewNopLogger())
importer, err := newTree.Import(version)
if err != nil {
return err
Expand Down
3 changes: 1 addition & 2 deletions cmd/iaviewer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
dbm "github.com/cosmos/cosmos-db"

"github.com/cosmos/iavl"
idbm "github.com/cosmos/iavl/db"
)

// TODO: make this configurable?
Expand Down Expand Up @@ -123,7 +122,7 @@ func ReadTree(dir string, version int, prefix []byte) (*iavl.MutableTree, error)
db = dbm.NewPrefixDB(db, prefix)
}

tree := iavl.NewMutableTree(idbm.NewWrapper(db), DefaultCacheSize, false, log.NewLogger(os.Stdout))
tree := iavl.NewMutableTree(db, DefaultCacheSize, false, log.NewLogger(os.Stdout))
ver, err := tree.LoadVersion(int64(version))
fmt.Printf("Got version: %d\n", ver)
return tree, err
Expand Down
Loading

0 comments on commit f9e0be0

Please sign in to comment.