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

Refactoring to depend on nodeDB interface #21

Closed
Show file tree
Hide file tree
Changes from all 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
18 changes: 14 additions & 4 deletions basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ func TestBasic(t *testing.T) {
if up {
t.Error("Did not expect an update (should have been create)")
}
tree.SaveVersion()
tree.SaveVersion()
err = tree.DeleteVersion(int64(1))
if err != nil{
t.Errorf("should lol")
}
proof, rangeProof, err := tree.GetVersionedWithProof([]byte("1"), int64(1))
print(proof)
print(rangeProof)
up = tree.Set([]byte("2"), []byte("two"))
if up {
t.Error("Did not expect an update (should have been create)")
Expand Down Expand Up @@ -423,23 +432,23 @@ func TestIterateRange(t *testing.T) {

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

ndb := NewNodeDb(db, 0, nil)
// Create some random key value pairs
records := make(map[string]string)
for i := 0; i < 10000; i++ {
records[randstr(20)] = randstr(20)
}

// Construct some tree and save it
t1, err := NewMutableTree(db, 0)
t1, err := NewMutableTree(ndb)
require.NoError(t, err)
for key, value := range records {
t1.Set([]byte(key), []byte(value))
}
t1.SaveVersion()

// Load a tree
t2, err := NewMutableTree(db, 0)
t2, err := NewMutableTree(ndb)
require.NoError(t, err)
t2.Load()
for key, value := range records {
Expand Down Expand Up @@ -483,7 +492,8 @@ func TestProof(t *testing.T) {

func TestTreeProof(t *testing.T) {
db := db.NewMemDB()
tree, err := NewMutableTree(db, 100)
ndb := NewNodeDb(db, 100, nil)
tree, err := NewMutableTree(ndb)
require.NoError(t, err)
assert.Equal(t, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", hex.EncodeToString(tree.Hash()))

Expand Down
3 changes: 2 additions & 1 deletion benchmarks/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ func randBytes(length int) []byte {
}

func prepareTree(b *testing.B, db db.DB, size, keyLen, dataLen int) (*iavl.MutableTree, [][]byte) {
t, err := iavl.NewMutableTreeWithOpts(db, size, nil)
ndb := iavl.NewNodeDb(db, size, nil)
t, err := iavl.NewMutableTreeWithOpts(ndb)
require.NoError(b, err)
keys := make([][]byte, size)

Expand Down
9 changes: 6 additions & 3 deletions benchmarks/cosmos-exim/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ func runExport(dbPath string) (int64, map[string][]*iavl.ExportNode, error) {
if err != nil {
return 0, nil, err
}
tree, err := iavl.NewMutableTree(tmdb.NewPrefixDB(ldb, []byte("s/k:main/")), 0)
ndb := iavl.NewNodeDb(tmdb.NewPrefixDB(ldb, []byte("s/k:main/")), 0, nil)
tree, err := iavl.NewMutableTree(ndb)
if err != nil {
return 0, nil, err
}
Expand All @@ -106,7 +107,8 @@ 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, err := iavl.NewMutableTree(db, 0)
ndb := iavl.NewNodeDb(db, 0, nil)
tree, err := iavl.NewMutableTree(ndb)
if err != nil {
return 0, nil, err
}
Expand Down Expand Up @@ -171,7 +173,8 @@ func runImport(version int64, exports map[string][]*iavl.ExportNode) error {
if err != nil {
return err
}
newTree, err := iavl.NewMutableTree(newDB, 0)
ndb := iavl.NewNodeDb(newDB, 0, nil)
newTree, err := iavl.NewMutableTree(ndb)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/iaviewer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"crypto/sha256"
"encoding/hex"
"fmt"
"github.com/cosmos/iavl"
"os"
"strconv"
"strings"

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

Expand Down Expand Up @@ -112,8 +112,9 @@ func ReadTree(dir string, version int, prefix []byte) (*iavl.MutableTree, error)
if len(prefix) != 0 {
db = dbm.NewPrefixDB(db, prefix)
}
ndb := iavl.NewNodeDb(db, DefaultCacheSize, nil)

tree, err := iavl.NewMutableTree(db, DefaultCacheSize)
tree, err := iavl.NewMutableTree(ndb)
if err != nil {
return nil, err
}
Expand Down
Loading