aboutsummaryrefslogtreecommitdiffstats
path: root/trie/trie.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2018-06-21 17:28:05 +0800
committerFelix Lange <fjl@users.noreply.github.com>2018-06-21 17:28:05 +0800
commitd926bf2c7e3182d694c15829a37a0ca7331cd03c (patch)
treec2d3ddd85941a231fb05de46c36703273d11814a /trie/trie.go
parent8db8d074e2fff547e9d85169018e03f89b5975a1 (diff)
downloadgo-tangerine-d926bf2c7e3182d694c15829a37a0ca7331cd03c.tar
go-tangerine-d926bf2c7e3182d694c15829a37a0ca7331cd03c.tar.gz
go-tangerine-d926bf2c7e3182d694c15829a37a0ca7331cd03c.tar.bz2
go-tangerine-d926bf2c7e3182d694c15829a37a0ca7331cd03c.tar.lz
go-tangerine-d926bf2c7e3182d694c15829a37a0ca7331cd03c.tar.xz
go-tangerine-d926bf2c7e3182d694c15829a37a0ca7331cd03c.tar.zst
go-tangerine-d926bf2c7e3182d694c15829a37a0ca7331cd03c.zip
trie: cache collapsed tries node, not rlp blobs (#16876)
The current trie memory database/cache that we do pruning on stores trie nodes as binary rlp encoded blobs, and also stores the node relationships/references for GC purposes. However, most of the trie nodes (everything apart from a value node) is in essence just a collection of references. This PR switches out the RLP encoded trie blobs with the collapsed-but-not-serialized trie nodes. This permits most of the references to be recovered from within the node data structure, avoiding the need to track them a second time (expensive memory wise).
Diffstat (limited to 'trie/trie.go')
-rw-r--r--trie/trie.go8
1 files changed, 3 insertions, 5 deletions
diff --git a/trie/trie.go b/trie/trie.go
index 30543c549..4284e30ad 100644
--- a/trie/trie.go
+++ b/trie/trie.go
@@ -433,12 +433,10 @@ func (t *Trie) resolveHash(n hashNode, prefix []byte) (node, error) {
cacheMissCounter.Inc(1)
hash := common.BytesToHash(n)
-
- enc, err := t.db.Node(hash)
- if err != nil || enc == nil {
- return nil, &MissingNodeError{NodeHash: hash, Path: prefix}
+ if node := t.db.node(hash, t.cachegen); node != nil {
+ return node, nil
}
- return mustDecodeNode(n, enc, t.cachegen), nil
+ return nil, &MissingNodeError{NodeHash: hash, Path: prefix}
}
// Root returns the root hash of the trie.