diff --git a/trie/node_enc.go b/trie/node_enc.go index 7cd421b225..c95587eeab 100644 --- a/trie/node_enc.go +++ b/trie/node_enc.go @@ -81,12 +81,6 @@ func (n *extNodeEncoder) encode(w rlp.EncoderBuffer) { func (n *leafNodeEncoder) encode(w rlp.EncoderBuffer) { offset := w.List() - - // Encode the key to Compact format. The assumption is held - // that it's safe to modify the key in place. - n.Key = append(n.Key, 16) // termination flag - n.Key = hexToCompactInPlace(n.Key) - w.WriteBytes(n.Key) // Compact format key w.WriteBytes(n.Val) // Value node, must be non-nil w.ListEnd(offset) diff --git a/trie/stacktrie.go b/trie/stacktrie.go index 41992b1b7c..2b7366c3c5 100644 --- a/trie/stacktrie.go +++ b/trie/stacktrie.go @@ -68,7 +68,7 @@ func (t *StackTrie) grow(key []byte) { if cap(t.kBuf) < 2*len(key) { t.kBuf = make([]byte, 2*len(key)) } - if cap(t.pBuf) < len(key) { + if cap(t.pBuf) < 2*len(key) { t.pBuf = make([]byte, 2*len(key)) } } @@ -353,6 +353,7 @@ func (t *StackTrie) hash(st *stNode, path []byte) { } nodes.encode(t.h.encbuf) blob = t.h.encodedBytes() + for i, child := range st.children { if child == nil { continue @@ -377,8 +378,9 @@ func (t *StackTrie) hash(st *stNode, path []byte) { st.children[0] = nil case leafNode: + st.key = append(st.key, byte(16)) n := leafNodeEncoder{ - Key: st.key, + Key: hexToCompactInPlace(st.key), Val: st.val, } n.encode(t.h.encbuf)