Skip to content

Commit

Permalink
Refactoring to depend on nodeDB interface
Browse files Browse the repository at this point in the history
  • Loading branch information
rohanspersonalgit committed Feb 21, 2022
1 parent 26345cb commit 47ee803
Show file tree
Hide file tree
Showing 26 changed files with 5,395 additions and 4,237 deletions.
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

0 comments on commit 47ee803

Please sign in to comment.