aboutsummaryrefslogtreecommitdiffstats
path: root/trie/trie.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2016-10-19 19:35:49 +0800
committerGitHub <noreply@github.com>2016-10-19 19:35:49 +0800
commit25ac04a444d82f42138fc06e651c1ef9bac935dc (patch)
tree4b4925de834f243a05c73e661e77bc60287aeb9d /trie/trie.go
parent8e52c2e754cdb343d0eb880a33251e1ba593d327 (diff)
parent8d56bf5ceb74a7ed45c986450848a89e2df61189 (diff)
downloadgo-tangerine-25ac04a444d82f42138fc06e651c1ef9bac935dc.tar
go-tangerine-25ac04a444d82f42138fc06e651c1ef9bac935dc.tar.gz
go-tangerine-25ac04a444d82f42138fc06e651c1ef9bac935dc.tar.bz2
go-tangerine-25ac04a444d82f42138fc06e651c1ef9bac935dc.tar.lz
go-tangerine-25ac04a444d82f42138fc06e651c1ef9bac935dc.tar.xz
go-tangerine-25ac04a444d82f42138fc06e651c1ef9bac935dc.tar.zst
go-tangerine-25ac04a444d82f42138fc06e651c1ef9bac935dc.zip
Merge pull request #3153 from fjl/trie-unload-fix
trie: improve cache unloading mechanism
Diffstat (limited to 'trie/trie.go')
-rw-r--r--trie/trie.go21
1 files changed, 11 insertions, 10 deletions
diff --git a/trie/trie.go b/trie/trie.go
index 5a4b6185d..914bf20fa 100644
--- a/trie/trie.go
+++ b/trie/trie.go
@@ -105,13 +105,11 @@ func New(root common.Hash, db Database) (*Trie, error) {
if db == nil {
panic("trie.New: cannot use existing root without a database")
}
- if v, _ := trie.db.Get(root[:]); len(v) == 0 {
- return nil, &MissingNodeError{
- RootHash: root,
- NodeHash: root,
- }
+ rootnode, err := trie.resolveHash(root[:], nil, nil)
+ if err != nil {
+ return nil, err
}
- trie.root = hashNode(root.Bytes())
+ trie.root = rootnode
}
return trie, nil
}
@@ -158,14 +156,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:
@@ -261,7 +260,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:
@@ -345,7 +345,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
@@ -443,7 +444,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
}