aboutsummaryrefslogtreecommitdiffstats
path: root/trie
diff options
context:
space:
mode:
Diffstat (limited to 'trie')
-rw-r--r--trie/cache.go18
-rw-r--r--trie/encoding.go67
-rw-r--r--trie/encoding_test.go78
-rw-r--r--trie/fullnode.go10
-rw-r--r--trie/hashnode.go10
-rw-r--r--trie/iterator.go12
-rw-r--r--trie/iterator_test.go10
-rw-r--r--trie/node.go10
-rw-r--r--trie/secure_trie.go10
-rw-r--r--trie/shortnode.go14
-rw-r--r--trie/slice.go10
-rw-r--r--trie/trie.go22
-rw-r--r--trie/trie_test.go10
-rw-r--r--trie/valuenode.go10
14 files changed, 166 insertions, 125 deletions
diff --git a/trie/cache.go b/trie/cache.go
index 2a5288353..99d8033a6 100644
--- a/trie/cache.go
+++ b/trie/cache.go
@@ -1,23 +1,22 @@
// Copyright 2014 The go-ethereum Authors
-// This file is part of go-ethereum.
+// This file is part of the go-ethereum library.
//
-// go-ethereum is free software: you can redistribute it and/or modify
+// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
-// go-ethereum is distributed in the hope that it will be useful,
+// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
-// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package trie
import (
- "github.com/ethereum/go-ethereum/compression/rle"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/syndtr/goleveldb/leveldb"
@@ -39,6 +38,8 @@ func NewCache(backend Backend) *Cache {
}
func (self *Cache) Get(key []byte) []byte {
+ key = append(StatePre, key...)
+
data := self.store[string(key)]
if data == nil {
data, _ = self.backend.Get(key)
@@ -48,8 +49,9 @@ func (self *Cache) Get(key []byte) []byte {
}
func (self *Cache) Put(key []byte, data []byte) {
- // write the data to the ldb batch
- self.batch.Put(key, rle.Compress(data))
+ key = append(StatePre, key...)
+
+ self.batch.Put(key, data)
self.store[string(key)] = data
}
diff --git a/trie/encoding.go b/trie/encoding.go
index 8c2d6a3f7..9c862d78f 100644
--- a/trie/encoding.go
+++ b/trie/encoding.go
@@ -1,28 +1,22 @@
// Copyright 2014 The go-ethereum Authors
-// This file is part of go-ethereum.
+// This file is part of the go-ethereum library.
//
-// go-ethereum is free software: you can redistribute it and/or modify
+// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
-// go-ethereum is distributed in the hope that it will be useful,
+// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
-// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package trie
-import (
- "bytes"
- "encoding/hex"
- "strings"
-)
-
-func CompactEncode(hexSlice []byte) string {
+func CompactEncode(hexSlice []byte) []byte {
terminator := 0
if hexSlice[len(hexSlice)-1] == 16 {
terminator = 1
@@ -40,15 +34,15 @@ func CompactEncode(hexSlice []byte) string {
hexSlice = append([]byte{flags, 0}, hexSlice...)
}
- var buff bytes.Buffer
- for i := 0; i < len(hexSlice); i += 2 {
- buff.WriteByte(byte(16*hexSlice[i] + hexSlice[i+1]))
+ l := len(hexSlice) / 2
+ var buf = make([]byte, l)
+ for i := 0; i < l; i++ {
+ buf[i] = 16*hexSlice[2*i] + hexSlice[2*i+1]
}
-
- return buff.String()
+ return buf
}
-func CompactDecode(str string) []byte {
+func CompactDecode(str []byte) []byte {
base := CompactHexDecode(str)
base = base[:len(base)-1]
if base[0] >= 2 {
@@ -63,30 +57,23 @@ func CompactDecode(str string) []byte {
return base
}
-func CompactHexDecode(str string) []byte {
- base := "0123456789abcdef"
- var hexSlice []byte
-
- enc := hex.EncodeToString([]byte(str))
- for _, v := range enc {
- hexSlice = append(hexSlice, byte(strings.IndexByte(base, byte(v))))
+func CompactHexDecode(str []byte) []byte {
+ l := len(str)*2 + 1
+ var nibbles = make([]byte, l)
+ for i, b := range str {
+ nibbles[i*2] = b / 16
+ nibbles[i*2+1] = b % 16
}
- hexSlice = append(hexSlice, 16)
-
- return hexSlice
+ nibbles[l-1] = 16
+ return nibbles
}
-func DecodeCompact(key []byte) string {
- const base = "0123456789abcdef"
- var str string
-
- for _, v := range key {
- if v < 16 {
- str += string(base[v])
- }
+func DecodeCompact(key []byte) []byte {
+ l := len(key) / 2
+ var res = make([]byte, l)
+ for i := 0; i < l; i++ {
+ v1, v0 := key[2*i], key[2*i+1]
+ res[i] = v1*16 + v0
}
-
- res, _ := hex.DecodeString(str)
-
- return string(res)
+ return res
}
diff --git a/trie/encoding_test.go b/trie/encoding_test.go
index 86b69636f..e49b57ef0 100644
--- a/trie/encoding_test.go
+++ b/trie/encoding_test.go
@@ -1,25 +1,30 @@
// Copyright 2014 The go-ethereum Authors
-// This file is part of go-ethereum.
+// This file is part of the go-ethereum library.
//
-// go-ethereum is free software: you can redistribute it and/or modify
+// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
-// go-ethereum is distributed in the hope that it will be useful,
+// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
-// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package trie
import (
+ "encoding/hex"
+ "testing"
+
checker "gopkg.in/check.v1"
)
+func Test(t *testing.T) { checker.TestingT(t) }
+
type TrieEncodingSuite struct{}
var _ = checker.Suite(&TrieEncodingSuite{})
@@ -28,48 +33,93 @@ func (s *TrieEncodingSuite) TestCompactEncode(c *checker.C) {
// even compact encode
test1 := []byte{1, 2, 3, 4, 5}
res1 := CompactEncode(test1)
- c.Assert(res1, checker.Equals, "\x11\x23\x45")
+ c.Assert(res1, checker.DeepEquals, []byte("\x11\x23\x45"))
// odd compact encode
test2 := []byte{0, 1, 2, 3, 4, 5}
res2 := CompactEncode(test2)
- c.Assert(res2, checker.Equals, "\x00\x01\x23\x45")
+ c.Assert(res2, checker.DeepEquals, []byte("\x00\x01\x23\x45"))
//odd terminated compact encode
test3 := []byte{0, 15, 1, 12, 11, 8 /*term*/, 16}
res3 := CompactEncode(test3)
- c.Assert(res3, checker.Equals, "\x20\x0f\x1c\xb8")
+ c.Assert(res3, checker.DeepEquals, []byte("\x20\x0f\x1c\xb8"))
// even terminated compact encode
test4 := []byte{15, 1, 12, 11, 8 /*term*/, 16}
res4 := CompactEncode(test4)
- c.Assert(res4, checker.Equals, "\x3f\x1c\xb8")
+ c.Assert(res4, checker.DeepEquals, []byte("\x3f\x1c\xb8"))
}
func (s *TrieEncodingSuite) TestCompactHexDecode(c *checker.C) {
exp := []byte{7, 6, 6, 5, 7, 2, 6, 2, 16}
- res := CompactHexDecode("verb")
+ res := CompactHexDecode([]byte("verb"))
c.Assert(res, checker.DeepEquals, exp)
}
func (s *TrieEncodingSuite) TestCompactDecode(c *checker.C) {
// odd compact decode
exp := []byte{1, 2, 3, 4, 5}
- res := CompactDecode("\x11\x23\x45")
+ res := CompactDecode([]byte("\x11\x23\x45"))
c.Assert(res, checker.DeepEquals, exp)
// even compact decode
exp = []byte{0, 1, 2, 3, 4, 5}
- res = CompactDecode("\x00\x01\x23\x45")
+ res = CompactDecode([]byte("\x00\x01\x23\x45"))
c.Assert(res, checker.DeepEquals, exp)
// even terminated compact decode
exp = []byte{0, 15, 1, 12, 11, 8 /*term*/, 16}
- res = CompactDecode("\x20\x0f\x1c\xb8")
+ res = CompactDecode([]byte("\x20\x0f\x1c\xb8"))
c.Assert(res, checker.DeepEquals, exp)
// even terminated compact decode
exp = []byte{15, 1, 12, 11, 8 /*term*/, 16}
- res = CompactDecode("\x3f\x1c\xb8")
+ res = CompactDecode([]byte("\x3f\x1c\xb8"))
+ c.Assert(res, checker.DeepEquals, exp)
+}
+
+func (s *TrieEncodingSuite) TestDecodeCompact(c *checker.C) {
+ exp, _ := hex.DecodeString("012345")
+ res := DecodeCompact([]byte{0, 1, 2, 3, 4, 5})
c.Assert(res, checker.DeepEquals, exp)
+
+ exp, _ = hex.DecodeString("012345")
+ res = DecodeCompact([]byte{0, 1, 2, 3, 4, 5, 16})
+ c.Assert(res, checker.DeepEquals, exp)
+
+ exp, _ = hex.DecodeString("abcdef")
+ res = DecodeCompact([]byte{10, 11, 12, 13, 14, 15})
+ c.Assert(res, checker.DeepEquals, exp)
+}
+
+func BenchmarkCompactEncode(b *testing.B) {
+
+ testBytes := []byte{0, 15, 1, 12, 11, 8 /*term*/, 16}
+ for i := 0; i < b.N; i++ {
+ CompactEncode(testBytes)
+ }
+}
+
+func BenchmarkCompactDecode(b *testing.B) {
+ testBytes := []byte{0, 15, 1, 12, 11, 8 /*term*/, 16}
+ for i := 0; i < b.N; i++ {
+ CompactDecode(testBytes)
+ }
+}
+
+func BenchmarkCompactHexDecode(b *testing.B) {
+ testBytes := []byte{7, 6, 6, 5, 7, 2, 6, 2, 16}
+ for i := 0; i < b.N; i++ {
+ CompactHexDecode(testBytes)
+ }
+
+}
+
+func BenchmarkDecodeCompact(b *testing.B) {
+ testBytes := []byte{7, 6, 6, 5, 7, 2, 6, 2, 16}
+ for i := 0; i < b.N; i++ {
+ DecodeCompact(testBytes)
+ }
+
}
diff --git a/trie/fullnode.go b/trie/fullnode.go
index 06edf6a60..8ff019ec4 100644
--- a/trie/fullnode.go
+++ b/trie/fullnode.go
@@ -1,18 +1,18 @@
// Copyright 2014 The go-ethereum Authors
-// This file is part of go-ethereum.
+// This file is part of the go-ethereum library.
//
-// go-ethereum is free software: you can redistribute it and/or modify
+// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
-// go-ethereum is distributed in the hope that it will be useful,
+// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
-// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package trie
diff --git a/trie/hashnode.go b/trie/hashnode.go
index a6ab084a8..d4a0bc7ec 100644
--- a/trie/hashnode.go
+++ b/trie/hashnode.go
@@ -1,18 +1,18 @@
// Copyright 2014 The go-ethereum Authors
-// This file is part of go-ethereum.
+// This file is part of the go-ethereum library.
//
-// go-ethereum is free software: you can redistribute it and/or modify
+// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
-// go-ethereum is distributed in the hope that it will be useful,
+// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
-// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package trie
diff --git a/trie/iterator.go b/trie/iterator.go
index ea299c0c1..9c4c7fbe5 100644
--- a/trie/iterator.go
+++ b/trie/iterator.go
@@ -1,18 +1,18 @@
// Copyright 2014 The go-ethereum Authors
-// This file is part of go-ethereum.
+// This file is part of the go-ethereum library.
//
-// go-ethereum is free software: you can redistribute it and/or modify
+// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
-// go-ethereum is distributed in the hope that it will be useful,
+// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
-// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package trie
@@ -41,7 +41,7 @@ func (self *Iterator) Next() bool {
self.Key = make([]byte, 32)
}
- key := RemTerm(CompactHexDecode(string(self.Key)))
+ key := RemTerm(CompactHexDecode(self.Key))
k := self.next(self.trie.root, key, isIterStart)
self.Key = []byte(DecodeCompact(k))
diff --git a/trie/iterator_test.go b/trie/iterator_test.go
index 8ebac5d3d..148f9adf9 100644
--- a/trie/iterator_test.go
+++ b/trie/iterator_test.go
@@ -1,18 +1,18 @@
// Copyright 2014 The go-ethereum Authors
-// This file is part of go-ethereum.
+// This file is part of the go-ethereum library.
//
-// go-ethereum is free software: you can redistribute it and/or modify
+// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
-// go-ethereum is distributed in the hope that it will be useful,
+// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
-// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package trie
diff --git a/trie/node.go b/trie/node.go
index a16800e2b..9d49029de 100644
--- a/trie/node.go
+++ b/trie/node.go
@@ -1,18 +1,18 @@
// Copyright 2014 The go-ethereum Authors
-// This file is part of go-ethereum.
+// This file is part of the go-ethereum library.
//
-// go-ethereum is free software: you can redistribute it and/or modify
+// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
-// go-ethereum is distributed in the hope that it will be useful,
+// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
-// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package trie
diff --git a/trie/secure_trie.go b/trie/secure_trie.go
index 944bd53ac..47c7542bb 100644
--- a/trie/secure_trie.go
+++ b/trie/secure_trie.go
@@ -1,18 +1,18 @@
// Copyright 2015 The go-ethereum Authors
-// This file is part of go-ethereum.
+// This file is part of the go-ethereum library.
//
-// go-ethereum is free software: you can redistribute it and/or modify
+// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
-// go-ethereum is distributed in the hope that it will be useful,
+// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
-// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package trie
diff --git a/trie/shortnode.go b/trie/shortnode.go
index ebc6c532b..569d5f109 100644
--- a/trie/shortnode.go
+++ b/trie/shortnode.go
@@ -1,18 +1,18 @@
// Copyright 2014 The go-ethereum Authors
-// This file is part of go-ethereum.
+// This file is part of the go-ethereum library.
//
-// go-ethereum is free software: you can redistribute it and/or modify
+// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
-// go-ethereum is distributed in the hope that it will be useful,
+// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
-// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package trie
@@ -26,7 +26,7 @@ type ShortNode struct {
}
func NewShortNode(t *Trie, key []byte, value Node) *ShortNode {
- return &ShortNode{t, []byte(CompactEncode(key)), value, false}
+ return &ShortNode{t, CompactEncode(key), value, false}
}
func (self *ShortNode) Value() Node {
self.value = self.trie.trans(self.value)
@@ -49,7 +49,7 @@ func (self *ShortNode) Hash() interface{} {
}
func (self *ShortNode) Key() []byte {
- return CompactDecode(string(self.key))
+ return CompactDecode(self.key)
}
func (self *ShortNode) setDirty(dirty bool) {
diff --git a/trie/slice.go b/trie/slice.go
index de3f7acf8..ccefbd064 100644
--- a/trie/slice.go
+++ b/trie/slice.go
@@ -1,18 +1,18 @@
// Copyright 2014 The go-ethereum Authors
-// This file is part of go-ethereum.
+// This file is part of the go-ethereum library.
//
-// go-ethereum is free software: you can redistribute it and/or modify
+// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
-// go-ethereum is distributed in the hope that it will be useful,
+// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
-// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package trie
diff --git a/trie/trie.go b/trie/trie.go
index 30c2569fa..2970bc185 100644
--- a/trie/trie.go
+++ b/trie/trie.go
@@ -1,18 +1,18 @@
// Copyright 2014 The go-ethereum Authors
-// This file is part of go-ethereum.
+// This file is part of the go-ethereum library.
//
-// go-ethereum is free software: you can redistribute it and/or modify
+// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
-// go-ethereum is distributed in the hope that it will be useful,
+// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
-// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// Package trie implements Merkle Patricia Tries.
package trie
@@ -27,6 +27,8 @@ import (
"github.com/ethereum/go-ethereum/crypto"
)
+var StatePre = []byte("state-")
+
func ParanoiaCheck(t1 *Trie, backend Backend) (bool, *Trie) {
t2 := New(nil, backend)
@@ -69,7 +71,7 @@ func (self *Trie) Iterator() *Iterator {
func (self *Trie) Copy() *Trie {
cpy := make([]byte, 32)
- copy(cpy, self.roothash)
+ copy(cpy, self.roothash) // NOTE: cpy isn't being used anywhere?
trie := New(nil, nil)
trie.cache = self.cache.Copy()
if self.root != nil {
@@ -131,7 +133,7 @@ func (self *Trie) Update(key, value []byte) Node {
self.mu.Lock()
defer self.mu.Unlock()
- k := CompactHexDecode(string(key))
+ k := CompactHexDecode(key)
if len(value) != 0 {
node := NewValueNode(self, value)
@@ -149,7 +151,7 @@ func (self *Trie) Get(key []byte) []byte {
self.mu.Lock()
defer self.mu.Unlock()
- k := CompactHexDecode(string(key))
+ k := CompactHexDecode(key)
n := self.get(self.root, k)
if n != nil {
@@ -164,7 +166,7 @@ func (self *Trie) Delete(key []byte) Node {
self.mu.Lock()
defer self.mu.Unlock()
- k := CompactHexDecode(string(key))
+ k := CompactHexDecode(key)
self.root = self.delete(self.root, k)
return self.root
@@ -336,7 +338,7 @@ func (self *Trie) mknode(value *common.Value) Node {
case 2:
// A value node may consists of 2 bytes.
if value.Get(0).Len() != 0 {
- key := CompactDecode(string(value.Get(0).Bytes()))
+ key := CompactDecode(value.Get(0).Bytes())
if key[len(key)-1] == 16 {
return NewShortNode(self, key, NewValueNode(self, value.Get(1).Bytes()))
} else {
diff --git a/trie/trie_test.go b/trie/trie_test.go
index cfb162e21..ae4e5efe4 100644
--- a/trie/trie_test.go
+++ b/trie/trie_test.go
@@ -1,18 +1,18 @@
// Copyright 2014 The go-ethereum Authors
-// This file is part of go-ethereum.
+// This file is part of the go-ethereum library.
//
-// go-ethereum is free software: you can redistribute it and/or modify
+// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
-// go-ethereum is distributed in the hope that it will be useful,
+// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
-// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package trie
diff --git a/trie/valuenode.go b/trie/valuenode.go
index ef9e88ebb..0afa64d54 100644
--- a/trie/valuenode.go
+++ b/trie/valuenode.go
@@ -1,18 +1,18 @@
// Copyright 2014 The go-ethereum Authors
-// This file is part of go-ethereum.
+// This file is part of the go-ethereum library.
//
-// go-ethereum is free software: you can redistribute it and/or modify
+// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
-// go-ethereum is distributed in the hope that it will be useful,
+// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
-// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package trie