diff options
author | Felix Lange <fjl@twurst.com> | 2016-10-17 22:13:50 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2016-10-18 10:57:47 +0800 |
commit | 177cab5fe70910ee0af3fcf493d51999ae2d923d (patch) | |
tree | 54a8c78b9e2a25880b1d9cc284affad7d0830d33 /trie/trie.go | |
parent | 187d6a66a5176a1dc3e75d5ad4baad623762acb9 (diff) | |
download | go-tangerine-177cab5fe70910ee0af3fcf493d51999ae2d923d.tar go-tangerine-177cab5fe70910ee0af3fcf493d51999ae2d923d.tar.gz go-tangerine-177cab5fe70910ee0af3fcf493d51999ae2d923d.tar.bz2 go-tangerine-177cab5fe70910ee0af3fcf493d51999ae2d923d.tar.lz go-tangerine-177cab5fe70910ee0af3fcf493d51999ae2d923d.tar.xz go-tangerine-177cab5fe70910ee0af3fcf493d51999ae2d923d.tar.zst go-tangerine-177cab5fe70910ee0af3fcf493d51999ae2d923d.zip |
trie: ensure resolved nodes stay loaded
Commit 40cdcf1183 broke the optimisation which kept nodes resolved
during Get in the trie. The decoder assigned cache generation 0
unconditionally, causing resolved nodes to get flushed on Commit.
This commit fixes it and adds two tests.
Diffstat (limited to 'trie/trie.go')
-rw-r--r-- | trie/trie.go | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/trie/trie.go b/trie/trie.go index cce4cfeb6..30f566a8d 100644 --- a/trie/trie.go +++ b/trie/trie.go @@ -144,14 +144,15 @@ func (t *Trie) tryGet(origNode node, key []byte, pos int) (value []byte, newnode if err == nil && didResolve { n = n.copy() n.Val = newnode + n.flags.gen = t.cachegen } return value, n, didResolve, err case *fullNode: value, newnode, didResolve, err = t.tryGet(n.Children[key[pos]], key, pos+1) if err == nil && didResolve { n = n.copy() + n.flags.gen = t.cachegen n.Children[key[pos]] = newnode - } return value, n, didResolve, err case hashNode: @@ -247,7 +248,8 @@ func (t *Trie) insert(n node, prefix, key []byte, value node) (bool, node, error return false, n, err } n = n.copy() - n.Children[key[0]], n.flags.hash, n.flags.dirty = nn, nil, true + n.flags = t.newFlag() + n.Children[key[0]] = nn return true, n, nil case nil: @@ -331,7 +333,8 @@ func (t *Trie) delete(n node, prefix, key []byte) (bool, node, error) { return false, n, err } n = n.copy() - n.Children[key[0]], n.flags.hash, n.flags.dirty = nn, nil, true + n.flags = t.newFlag() + n.Children[key[0]] = nn // Check how many non-nil entries are left after deleting and // reduce the full node to a short node if only one entry is @@ -427,7 +430,7 @@ func (t *Trie) resolveHash(n hashNode, prefix, suffix []byte) (node, error) { SuffixLen: len(suffix), } } - dec := mustDecodeNode(n, enc) + dec := mustDecodeNode(n, enc, t.cachegen) return dec, nil } |