Skip to content

Commit

Permalink
Remove all cmn from tendermint in IavlStore (#157)
Browse files Browse the repository at this point in the history
* Remove all cmn fromtendermint in IavlStore

- Remove all instances of cmn in iavl store

Signed-off-by: Marko Baricevic <[email protected]>

* lint error

* change log pending

* change to Errorf

* use tm-cmn

* change db to tm-cmn db

* gofmt

* changelog change

* pr comment changes
  • Loading branch information
tac0turtle authored Jul 18, 2019
1 parent c834d31 commit db2a828
Show file tree
Hide file tree
Showing 24 changed files with 234 additions and 155 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ linters:
- gochecknoinits
- scopelint
- stylecheck

# linters-settings:
# govet:
# check-shadowing: true
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ Special thanks to external contributors on this release:
### BREAKING CHANGES

### IMPROVEMENTS

- [/#46](https://github.com/tendermint/iavl/issues/46) Removal of all instances of cmn from tendermint in Ival repo
2 changes: 1 addition & 1 deletion basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tm-cmn/db"
)

func TestBasic(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"

"github.com/tendermint/iavl"
db "github.com/tendermint/tendermint/libs/db"
db "github.com/tendermint/tm-cmn/db"
)

const historySize = 20
Expand Down
2 changes: 1 addition & 1 deletion cmd/iaviewer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"

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

// TODO: make this configurable?
Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Basic usage of MutableTree.
//
// import "github.com/tendermint/iavl"
// import "github.com/tendermint/tendermint/libs/db"
// import "github.com/tendermint/tm-cmn/db"
// ...
//
// tree := iavl.NewMutableTree(db.NewMemDB(), 128)
Expand Down
24 changes: 5 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,10 @@ module github.com/tendermint/iavl
go 1.12

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/etcd-io/bbolt v1.3.3 // indirect
github.com/go-kit/kit v0.6.0 // indirect
github.com/go-logfmt/logfmt v0.4.0 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/gogo/protobuf v1.1.1 // indirect
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf // indirect
github.com/jmhodges/levigo v0.0.0-20161115193449-c42d9e0ca023 // indirect
github.com/onsi/ginkgo v1.7.0 // indirect
github.com/onsi/gomega v1.4.3 // indirect
github.com/pkg/errors v0.8.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.2.2
github.com/syndtr/goleveldb v0.0.0-20181105012736-f9080354173f // indirect
github.com/pkg/errors v0.8.1
github.com/stretchr/testify v1.3.0
github.com/tendermint/go-amino v0.14.1
github.com/tendermint/tendermint v0.31.7
go.etcd.io/bbolt v1.3.3 // indirect
golang.org/x/crypto v0.0.0-20181126093934-9eb0be3963ea
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 // indirect
github.com/tendermint/tendermint v0.32.1
github.com/tendermint/tm-cmn v0.0.0-20190716080004-dfcde30d5acb
golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a
)
126 changes: 106 additions & 20 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion immutable_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strings"

dbm "github.com/tendermint/tendermint/libs/db"
dbm "github.com/tendermint/tm-cmn/db"
)

// ImmutableTree is a container for an immutable AVL+ ImmutableTree. Changes are performed by
Expand Down
17 changes: 9 additions & 8 deletions mutable_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"fmt"
"sort"

cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tendermint/libs/db"
"github.com/pkg/errors"

dbm "github.com/tendermint/tm-cmn/db"
)

// ErrVersionDoesNotExist is returned if a requested version does not exist.
Expand Down Expand Up @@ -427,13 +428,13 @@ func (tree *MutableTree) SaveVersion() ([]byte, int64, error) {
// longer be accessed.
func (tree *MutableTree) DeleteVersion(version int64) error {
if version == 0 {
return cmn.NewError("version must be greater than 0")
return errors.New("version must be greater than 0")
}
if version == tree.version {
return cmn.NewError("cannot delete latest saved version (%d)", version)
return errors.Errorf("cannot delete latest saved version (%d)", version)
}
if _, ok := tree.versions[version]; !ok {
return cmn.ErrorWrap(ErrVersionDoesNotExist, "")
return errors.Wrap(ErrVersionDoesNotExist, "")
}

tree.ndb.DeleteVersion(version, true)
Expand All @@ -448,16 +449,16 @@ func (tree *MutableTree) DeleteVersion(version int64) error {
// longer be accessed.
func (tree *MutableTree) deleteVersionsFrom(version int64) error {
if version <= 0 {
return cmn.NewError("version must be greater than 0")
return errors.New("version must be greater than 0")
}
newLatestVersion := version - 1
lastestVersion := tree.ndb.getLatestVersion()
for ; version <= lastestVersion; version++ {
if version == tree.version {
return cmn.NewError("cannot delete latest saved version (%d)", version)
return errors.Errorf("cannot delete latest saved version (%d)", version)
}
if _, ok := tree.versions[version]; !ok {
return cmn.ErrorWrap(ErrVersionDoesNotExist, "")
return errors.Wrap(ErrVersionDoesNotExist, "")
}
tree.ndb.DeleteVersion(version, false)
delete(tree.versions, version)
Expand Down
53 changes: 27 additions & 26 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"fmt"
"io"

"github.com/pkg/errors"

amino "github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/crypto/tmhash"
cmn "github.com/tendermint/tendermint/libs/common"
)

// Node represents a node in a Tree.
Expand Down Expand Up @@ -43,30 +44,30 @@ func NewNode(key []byte, value []byte, version int64) *Node {
//
// The new node doesn't have its hash saved or set. The caller must set it
// afterwards.
func MakeNode(buf []byte) (*Node, cmn.Error) {
func MakeNode(buf []byte) (*Node, error) {

// Read node header (height, size, version, key).
height, n, cause := amino.DecodeInt8(buf)
if cause != nil {
return nil, cmn.ErrorWrap(cause, "decoding node.height")
return nil, errors.Wrap(cause, "decoding node.height")
}
buf = buf[n:]

size, n, cause := amino.DecodeVarint(buf)
if cause != nil {
return nil, cmn.ErrorWrap(cause, "decoding node.size")
return nil, errors.Wrap(cause, "decoding node.size")
}
buf = buf[n:]

ver, n, cause := amino.DecodeVarint(buf)
if cause != nil {
return nil, cmn.ErrorWrap(cause, "decoding node.version")
return nil, errors.Wrap(cause, "decoding node.version")
}
buf = buf[n:]

key, n, cause := amino.DecodeByteSlice(buf)
if cause != nil {
return nil, cmn.ErrorWrap(cause, "decoding node.key")
return nil, errors.Wrap(cause, "decoding node.key")
}
buf = buf[n:]

Expand All @@ -82,19 +83,19 @@ func MakeNode(buf []byte) (*Node, cmn.Error) {
if node.isLeaf() {
val, _, cause := amino.DecodeByteSlice(buf)
if cause != nil {
return nil, cmn.ErrorWrap(cause, "decoding node.value")
return nil, errors.Wrap(cause, "decoding node.value")
}
node.value = val
} else { // Read children.
leftHash, n, cause := amino.DecodeByteSlice(buf)
if cause != nil {
return nil, cmn.ErrorWrap(cause, "deocding node.leftHash")
return nil, errors.Wrap(cause, "deocding node.leftHash")
}
buf = buf[n:]

rightHash, _, cause := amino.DecodeByteSlice(buf)
if cause != nil {
return nil, cmn.ErrorWrap(cause, "decoding node.rightHash")
return nil, errors.Wrap(cause, "decoding node.rightHash")
}
node.leftHash = leftHash
node.rightHash = rightHash
Expand Down Expand Up @@ -231,45 +232,45 @@ func (node *Node) hashWithCount() ([]byte, int64) {

// Writes the node's hash to the given io.Writer. This function expects
// child hashes to be already set.
func (node *Node) writeHashBytes(w io.Writer) cmn.Error {
func (node *Node) writeHashBytes(w io.Writer) error {
err := amino.EncodeInt8(w, node.height)
if err != nil {
return cmn.ErrorWrap(err, "writing height")
return errors.Wrap(err, "writing height")
}
err = amino.EncodeVarint(w, node.size)
if err != nil {
return cmn.ErrorWrap(err, "writing size")
return errors.Wrap(err, "writing size")
}
err = amino.EncodeVarint(w, node.version)
if err != nil {
return cmn.ErrorWrap(err, "writing version")
return errors.Wrap(err, "writing version")
}

// Key is not written for inner nodes, unlike writeBytes.

if node.isLeaf() {
err = amino.EncodeByteSlice(w, node.key)
if err != nil {
return cmn.ErrorWrap(err, "writing key")
return errors.Wrap(err, "writing key")
}
// Indirection needed to provide proofs without values.
// (e.g. proofLeafNode.ValueHash)
valueHash := tmhash.Sum(node.value)
err = amino.EncodeByteSlice(w, valueHash)
if err != nil {
return cmn.ErrorWrap(err, "writing value")
return errors.Wrap(err, "writing value")
}
} else {
if node.leftHash == nil || node.rightHash == nil {
panic("Found an empty child hash")
}
err = amino.EncodeByteSlice(w, node.leftHash)
if err != nil {
return cmn.ErrorWrap(err, "writing left hash")
return errors.Wrap(err, "writing left hash")
}
err = amino.EncodeByteSlice(w, node.rightHash)
if err != nil {
return cmn.ErrorWrap(err, "writing right hash")
return errors.Wrap(err, "writing right hash")
}
}

Expand All @@ -278,7 +279,7 @@ func (node *Node) writeHashBytes(w io.Writer) cmn.Error {

// Writes the node's hash to the given io.Writer.
// This function has the side-effect of calling hashWithCount.
func (node *Node) writeHashBytesRecursively(w io.Writer) (hashCount int64, err cmn.Error) {
func (node *Node) writeHashBytesRecursively(w io.Writer) (hashCount int64, err error) {
if node.leftNode != nil {
leftHash, leftCount := node.leftNode.hashWithCount()
node.leftHash = leftHash
Expand All @@ -295,47 +296,47 @@ func (node *Node) writeHashBytesRecursively(w io.Writer) (hashCount int64, err c
}

// Writes the node as a serialized byte slice to the supplied io.Writer.
func (node *Node) writeBytes(w io.Writer) cmn.Error {
func (node *Node) writeBytes(w io.Writer) error {
var cause error
cause = amino.EncodeInt8(w, node.height)
if cause != nil {
return cmn.ErrorWrap(cause, "writing height")
return errors.Wrap(cause, "writing height")
}
cause = amino.EncodeVarint(w, node.size)
if cause != nil {
return cmn.ErrorWrap(cause, "writing size")
return errors.Wrap(cause, "writing size")
}
cause = amino.EncodeVarint(w, node.version)
if cause != nil {
return cmn.ErrorWrap(cause, "writing version")
return errors.Wrap(cause, "writing version")
}

// Unlike writeHashBytes, key is written for inner nodes.
cause = amino.EncodeByteSlice(w, node.key)
if cause != nil {
return cmn.ErrorWrap(cause, "writing key")
return errors.Wrap(cause, "writing key")
}

if node.isLeaf() {
cause = amino.EncodeByteSlice(w, node.value)
if cause != nil {
return cmn.ErrorWrap(cause, "writing value")
return errors.Wrap(cause, "writing value")
}
} else {
if node.leftHash == nil {
panic("node.leftHash was nil in writeBytes")
}
cause = amino.EncodeByteSlice(w, node.leftHash)
if cause != nil {
return cmn.ErrorWrap(cause, "writing left hash")
return errors.Wrap(cause, "writing left hash")
}

if node.rightHash == nil {
panic("node.rightHash was nil in writeBytes")
}
cause = amino.EncodeByteSlice(w, node.rightHash)
if cause != nil {
return cmn.ErrorWrap(cause, "writing right hash")
return errors.Wrap(cause, "writing right hash")
}
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion nodedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"sync"

"github.com/tendermint/tendermint/crypto/tmhash"
dbm "github.com/tendermint/tendermint/libs/db"
dbm "github.com/tendermint/tm-cmn/db"
)

const (
Expand Down
6 changes: 4 additions & 2 deletions proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"bytes"
"fmt"

"github.com/pkg/errors"

"github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/crypto/tmhash"
cmn "github.com/tendermint/tendermint/libs/common"
cmn "github.com/tendermint/tm-cmn/common"
)

var (
Expand Down Expand Up @@ -153,7 +155,7 @@ func (node *Node) pathToLeaf(t *ImmutableTree, key []byte, path *PathToLeaf) (*N
if bytes.Equal(node.key, key) {
return node, nil
}
return node, cmn.NewError("key does not exist")
return node, errors.New("key does not exist")
}

if bytes.Compare(key, node.key) < 0 {
Expand Down
Loading

0 comments on commit db2a828

Please sign in to comment.