diff --git a/Gopkg.lock b/Gopkg.lock index 943bed303..a4b4f637e 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -32,8 +32,8 @@ [[projects]] name = "github.com/golang/protobuf" packages = ["proto"] - revision = "b4deda0973fb4c70b50d226b1af49f3da59f5265" - version = "v1.1.0" + revision = "925541529c1fa6821df4e44ce2723319eb2be768" + version = "v1.0.0" [[projects]] branch = "master" @@ -91,7 +91,7 @@ "leveldb/table", "leveldb/util" ] - revision = "e2150783cd35f5b607daca48afd8c57ec54cc995" + revision = "0d5a0ceb10cf9ab89fdd744cc8c50a83134f6697" [[projects]] name = "github.com/tendermint/go-amino" @@ -100,15 +100,15 @@ version = "0.10.1" [[projects]] - name = "github.com/tendermint/tmlibs" + name = "github.com/tendermint/tendermint" packages = [ - "common", - "db", - "log", - "test" + "libs/common", + "libs/db", + "libs/log", + "libs/test" ] - revision = "fb7ec62b2925f48de159aeea73b254ae8c58a738" - version = "v0.9.0-rc1" + revision = "5923b6288fe8ce9581936ee97c2bf9cf9c02c2f4" + version = "v0.22.0-rc2" [[projects]] branch = "master" @@ -117,11 +117,11 @@ "ripemd160", "sha3" ] - revision = "027cca12c2d63e3d62b670d901e8a2c95854feec" + revision = "a49355c7e3f8fe157a85be2f77e6e269a0f89602" [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "c21b43815d1d8a9c7d3b1bee6b918c03ccefa0b29d57ac5996084d5084bf1480" + inputs-digest = "ad12afa101079a7f5bcd70176fbbab42fd52e844b6c74c0fcf81315d33053f90" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index cb0a75764..b00a0c141 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -3,12 +3,12 @@ version = "1.1.4" [[constraint]] - version = "0.10.1" + version = "=0.10.1" name = "github.com/tendermint/go-amino" [[constraint]] - version = "0.9.0-rc1" - name = "github.com/tendermint/tmlibs" + version = "=0.22.0-rc2" + name = "github.com/tendermint/tendermint" [prune] go-tests = true diff --git a/basic_test.go b/basic_test.go index 6e05215ee..500c72385 100644 --- a/basic_test.go +++ b/basic_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/tendermint/tmlibs/db" + "github.com/tendermint/tendermint/libs/db" ) func TestBasic(t *testing.T) { diff --git a/benchmarks/bench_test.go b/benchmarks/bench_test.go index f11a4f5fe..820ba8db3 100644 --- a/benchmarks/bench_test.go +++ b/benchmarks/bench_test.go @@ -8,7 +8,7 @@ import ( "testing" "github.com/tendermint/iavl" - db "github.com/tendermint/tmlibs/db" + db "github.com/tendermint/tendermint/libs/db" ) const historySize = 20 diff --git a/doc.go b/doc.go index d6c38c6c0..e35179273 100644 --- a/doc.go +++ b/doc.go @@ -1,7 +1,7 @@ // Basic usage of VersionedTree. // // import "github.com/tendermint/iavl" -// import "github.com/tendermint/tmlibs/db" +// import "github.com/tendermint/tendermint/libs/db" // ... // // tree := iavl.NewVersionedTree(db.NewMemDB(), 128) diff --git a/node.go b/node.go index 45a4e0af2..fd86eff57 100644 --- a/node.go +++ b/node.go @@ -9,8 +9,8 @@ import ( "io" "github.com/tendermint/go-amino" - "github.com/tendermint/iavl/sha256truncated" - cmn "github.com/tendermint/tmlibs/common" + "github.com/tendermint/tendermint/crypto/tmhash" + cmn "github.com/tendermint/tendermint/libs/common" ) // Node represents a node in a Tree. @@ -199,7 +199,7 @@ func (node *Node) _hash() []byte { return node.hash } - h := sha256truncated.New() + h := tmhash.New() buf := new(bytes.Buffer) if err := node.writeHashBytes(buf); err != nil { panic(err) @@ -217,7 +217,7 @@ func (node *Node) hashWithCount() ([]byte, int64) { return node.hash, 0 } - h := sha256truncated.New() + h := tmhash.New() buf := new(bytes.Buffer) hashCount, err := node.writeHashBytesRecursively(buf) if err != nil { @@ -254,7 +254,7 @@ func (node *Node) writeHashBytes(w io.Writer) cmn.Error { } // Indirection needed to provide proofs without values. // (e.g. proofLeafNode.ValueHash) - valueHash := sha256truncated.Hash(node.value) + valueHash := tmhash.Sum(node.value) err = amino.EncodeByteSlice(w, valueHash) if err != nil { return cmn.ErrorWrap(err, "writing value") diff --git a/nodedb.go b/nodedb.go index 65f02edc9..d0d3df19c 100644 --- a/nodedb.go +++ b/nodedb.go @@ -7,7 +7,7 @@ import ( "sort" "sync" - dbm "github.com/tendermint/tmlibs/db" + dbm "github.com/tendermint/tendermint/libs/db" ) var ( diff --git a/proof.go b/proof.go index 8fca31f59..7a600ce1a 100644 --- a/proof.go +++ b/proof.go @@ -5,8 +5,8 @@ import ( "fmt" "github.com/tendermint/go-amino" - "github.com/tendermint/iavl/sha256truncated" - cmn "github.com/tendermint/tmlibs/common" + "github.com/tendermint/tendermint/crypto/tmhash" + cmn "github.com/tendermint/tendermint/libs/common" ) var ( @@ -54,7 +54,7 @@ func (pin proofInnerNode) StringIndented(indent string) string { } func (pin proofInnerNode) Hash(childHash []byte) []byte { - hasher := sha256truncated.New() + hasher := tmhash.New() buf := new(bytes.Buffer) err := amino.EncodeInt8(buf, pin.Height) @@ -113,7 +113,7 @@ func (pln proofLeafNode) StringIndented(indent string) string { } func (pln proofLeafNode) Hash() []byte { - hasher := sha256truncated.New() + hasher := tmhash.New() buf := new(bytes.Buffer) err := amino.EncodeInt8(buf, 0) diff --git a/proof_path.go b/proof_path.go index 29b9ebc76..c578b2af0 100644 --- a/proof_path.go +++ b/proof_path.go @@ -5,7 +5,7 @@ import ( "fmt" "strings" - cmn "github.com/tendermint/tmlibs/common" + cmn "github.com/tendermint/tendermint/libs/common" ) // pathWithLeaf is a path to a leaf node and the leaf node itself. diff --git a/proof_range.go b/proof_range.go index 7daa80006..6f7466984 100644 --- a/proof_range.go +++ b/proof_range.go @@ -5,8 +5,8 @@ import ( "fmt" "strings" - "github.com/tendermint/iavl/sha256truncated" - cmn "github.com/tendermint/tmlibs/common" + "github.com/tendermint/tendermint/crypto/tmhash" + cmn "github.com/tendermint/tendermint/libs/common" ) type RangeProof struct { @@ -63,7 +63,7 @@ func (proof *RangeProof) VerifyItem(i int, key, value []byte) error { if !bytes.Equal(proof.Leaves[i].Key, key) { return cmn.ErrorWrap(ErrInvalidProof, "leaf key not same") } - valueHash := sha256truncated.Hash(value) + valueHash := tmhash.Sum(value) if !bytes.Equal(proof.Leaves[i].ValueHash, valueHash) { return cmn.ErrorWrap(ErrInvalidProof, "leaf value hash not same") } @@ -256,7 +256,7 @@ func (t *Tree) getRangeProof(keyStart, keyEnd []byte, limit int) (proof *RangePr values = append(values, left.value) var leaves = []proofLeafNode{proofLeafNode{ Key: left.key, - ValueHash: sha256truncated.Hash(left.value), + ValueHash: tmhash.Sum(left.value), Version: left.version, }} @@ -328,7 +328,7 @@ func (t *Tree) getRangeProof(keyStart, keyEnd []byte, limit int) (proof *RangePr // Append leaf to leaves. leaves = append(leaves, proofLeafNode{ Key: node.key, - ValueHash: sha256truncated.Hash(node.value), + ValueHash: tmhash.Sum(node.value), Version: node.version, }) // Append value to values. diff --git a/proof_test.go b/proof_test.go index 43c0ce53f..45d5968a3 100644 --- a/proof_test.go +++ b/proof_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/go-amino" - "github.com/tendermint/tmlibs/test" + "github.com/tendermint/tendermint/libs/test" ) func TestTreeGetWithProof(t *testing.T) { diff --git a/sha256truncated/sha256truncated.go b/sha256truncated/sha256truncated.go deleted file mode 100644 index a07efaec9..000000000 --- a/sha256truncated/sha256truncated.go +++ /dev/null @@ -1,50 +0,0 @@ -// Package sha256truncated provides a sha256 hash.Hash whose output is truncated to 20 bytes (160 bits). -// -// This is the default hashing algorithm used by IAVL+ trees. -// -// s256 := sha256.New() // crypto/sha256 -// s256Truncated := New() // this package -// -// // Use like any other hash.Hash ... -// // Contract: -// s256Trunc.Sum(nil) == s256.Sum(nil)[:20] -package sha256truncated - -import ( - "crypto/sha256" - "hash" -) - -const Size = 20 - -// New returns a new hash.Hash computing the truncated to the first 20 bytes SHA256 checksum. -func New() hash.Hash { - return &digest{sha256.New()} -} - -func (d *digest) Sum(in []byte) []byte { - return d.Hash.Sum(in)[:Size] -} - -func (d *digest) Reset() { - d.Hash.Reset() -} - -func (d *digest) Size() int { - return Size -} - -func (d *digest) BlockSize() int { - return d.Hash.BlockSize() -} - -// digest is just a wrapper around sha256 -type digest struct { - hash.Hash -} - -func Hash(input []byte) []byte { - h := New() - h.Write(input) - return h.Sum(nil) -} diff --git a/sha256truncated/sha256truncated_test.go b/sha256truncated/sha256truncated_test.go deleted file mode 100644 index f5b134645..000000000 --- a/sha256truncated/sha256truncated_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package sha256truncated - -import ( - "crypto/sha256" - "testing" - - "github.com/stretchr/testify/require" -) - -func TestSum(t *testing.T) { - // very rudimentary testing here showing the relation between this hasher and sha256; - // assuming sha256 is already well tested - s256 := sha256.New() - s256Trunc := New() - - testStr1 := []byte("show the relation between ...") - testStr2 := []byte("... sha256 and sha256truncated") - - s256.Write(testStr1) - s256Trunc.Write(testStr1) - - s256.Write(testStr2) - s256Trunc.Write(testStr2) - - require.Equal(t, s256Trunc.Sum(nil), s256.Sum(nil)[:Size]) -} - -func TestSize(t *testing.T) { - got := New().Size() - want := Size - require.Equal(t, got, want) -} diff --git a/testutils_test.go b/testutils_test.go index 709c881ea..d39dbe23d 100644 --- a/testutils_test.go +++ b/testutils_test.go @@ -9,8 +9,8 @@ import ( mrand "math/rand" "github.com/tendermint/go-amino" - cmn "github.com/tendermint/tmlibs/common" - "github.com/tendermint/tmlibs/db" + cmn "github.com/tendermint/tendermint/libs/common" + "github.com/tendermint/tendermint/libs/db" ) func dummyPathToLeaf(t *Tree, key []byte) PathToLeaf { diff --git a/tree.go b/tree.go index 436f83e2c..676618b43 100644 --- a/tree.go +++ b/tree.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - dbm "github.com/tendermint/tmlibs/db" + dbm "github.com/tendermint/tendermint/libs/db" ) // Tree is a container for an immutable AVL+ Tree. Changes are performed by diff --git a/tree_fuzz_test.go b/tree_fuzz_test.go index a96d14231..5825f64d1 100644 --- a/tree_fuzz_test.go +++ b/tree_fuzz_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - cmn "github.com/tendermint/tmlibs/common" - "github.com/tendermint/tmlibs/db" + cmn "github.com/tendermint/tendermint/libs/common" + "github.com/tendermint/tendermint/libs/db" ) // This file implement fuzz testing by generating programs and then running diff --git a/tree_test.go b/tree_test.go index a2302285a..ee5b13bd9 100644 --- a/tree_test.go +++ b/tree_test.go @@ -8,9 +8,9 @@ import ( "testing" "github.com/stretchr/testify/require" - "github.com/tendermint/tmlibs/db" + "github.com/tendermint/tendermint/libs/db" - cmn "github.com/tendermint/tmlibs/common" + cmn "github.com/tendermint/tendermint/libs/common" ) var testLevelDB bool diff --git a/versioned_tree.go b/versioned_tree.go index ba205f6d8..3e399d11e 100644 --- a/versioned_tree.go +++ b/versioned_tree.go @@ -4,8 +4,8 @@ import ( "bytes" "fmt" - cmn "github.com/tendermint/tmlibs/common" - dbm "github.com/tendermint/tmlibs/db" + cmn "github.com/tendermint/tendermint/libs/common" + dbm "github.com/tendermint/tendermint/libs/db" ) var ErrVersionDoesNotExist = fmt.Errorf("version does not exist") diff --git a/with_gcc_test.go b/with_gcc_test.go index 23b33cdd9..b3d590d71 100644 --- a/with_gcc_test.go +++ b/with_gcc_test.go @@ -9,7 +9,7 @@ package iavl import ( "testing" - "github.com/tendermint/tmlibs/db" + "github.com/tendermint/tendermint/libs/db" ) func BenchmarkImmutableAvlTreeCLevelDB(b *testing.B) {