aboutsummaryrefslogtreecommitdiffstats
path: root/ptrie/trie.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-12-24 21:47:50 +0800
committerobscuren <geffobscura@gmail.com>2014-12-24 21:47:50 +0800
commit58d477f7a676563c5237df9c0cfd20ddba5df03c (patch)
treed0ebd9ed08dd75e9613837732a950ac991bd1131 /ptrie/trie.go
parent804af9658a89555d6b4069433676acdb6deb9742 (diff)
downloadgo-tangerine-58d477f7a676563c5237df9c0cfd20ddba5df03c.tar
go-tangerine-58d477f7a676563c5237df9c0cfd20ddba5df03c.tar.gz
go-tangerine-58d477f7a676563c5237df9c0cfd20ddba5df03c.tar.bz2
go-tangerine-58d477f7a676563c5237df9c0cfd20ddba5df03c.tar.lz
go-tangerine-58d477f7a676563c5237df9c0cfd20ddba5df03c.tar.xz
go-tangerine-58d477f7a676563c5237df9c0cfd20ddba5df03c.tar.zst
go-tangerine-58d477f7a676563c5237df9c0cfd20ddba5df03c.zip
Fixed a bug where keys where serialised twice
Diffstat (limited to 'ptrie/trie.go')
-rw-r--r--ptrie/trie.go24
1 files changed, 17 insertions, 7 deletions
diff --git a/ptrie/trie.go b/ptrie/trie.go
index d8135f36c..5c83b57d0 100644
--- a/ptrie/trie.go
+++ b/ptrie/trie.go
@@ -215,7 +215,7 @@ func (self *Trie) get(node Node, key []byte) Node {
}
func (self *Trie) delete(node Node, key []byte) Node {
- if len(key) == 0 {
+ if len(key) == 0 && node == nil {
return nil
}
@@ -234,7 +234,9 @@ func (self *Trie) delete(node Node, key []byte) Node {
nkey := append(k, child.Key()...)
n = NewShortNode(self, nkey, child.Value())
case *FullNode:
- n = NewShortNode(self, node.key, child)
+ sn := NewShortNode(self, node.Key(), child)
+ sn.key = node.key
+ n = sn
}
return n
@@ -275,9 +277,10 @@ func (self *Trie) delete(node Node, key []byte) Node {
}
return nnode
-
+ case nil:
+ return nil
default:
- panic("Invalid node")
+ panic(fmt.Sprintf("%T: invalid node: %v (%v)", node, node, key))
}
}
@@ -288,7 +291,10 @@ func (self *Trie) mknode(value *ethutil.Value) Node {
case 0:
return nil
case 2:
- return NewShortNode(self, trie.CompactDecode(string(value.Get(0).Bytes())), self.mknode(value.Get(1)))
+ // A value node may consists of 2 bytes.
+ if value.Get(0).Len() != 0 {
+ return NewShortNode(self, trie.CompactDecode(string(value.Get(0).Bytes())), self.mknode(value.Get(1)))
+ }
case 17:
fnode := NewFullNode(self)
for i := 0; i < l; i++ {
@@ -297,9 +303,9 @@ func (self *Trie) mknode(value *ethutil.Value) Node {
return fnode
case 32:
return &HashNode{value.Bytes()}
- default:
- return &ValueNode{self, value.Bytes()}
}
+
+ return &ValueNode{self, value.Bytes()}
}
func (self *Trie) trans(node Node) Node {
@@ -323,3 +329,7 @@ func (self *Trie) store(node Node) interface{} {
return node.RlpData()
}
+
+func (self *Trie) PrintRoot() {
+ fmt.Println(self.root)
+}