mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 14:16:44 +00:00
Add trie caching for misses
This commit is contained in:
parent
7c12e8ea44
commit
c7c2e8e990
1 changed files with 10 additions and 9 deletions
19
trie/trie.go
19
trie/trie.go
|
|
@ -410,11 +410,16 @@ func (t *Trie) resolve(n node, prefix, suffix []byte) (node, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Trie) resolveHash(n hashNode, prefix, suffix []byte) (node, error) {
|
func (t *Trie) resolveHash(n hashNode, prefix, suffix []byte) (node, error) {
|
||||||
if v, ok := globalCache.Get(n); ok {
|
var v node = nil
|
||||||
return v, nil
|
var ok bool
|
||||||
}
|
if v, ok = globalCache.Get(n); !ok {
|
||||||
enc, err := t.db.Get(n)
|
enc, err := t.db.Get(n)
|
||||||
if err != nil || enc == nil {
|
if err == nil && enc != nil {
|
||||||
|
v = mustDecodeNode(n, enc)
|
||||||
|
}
|
||||||
|
globalCache.Put(n, v)
|
||||||
|
}
|
||||||
|
if v == nil {
|
||||||
return nil, &MissingNodeError{
|
return nil, &MissingNodeError{
|
||||||
RootHash: t.originalRoot,
|
RootHash: t.originalRoot,
|
||||||
NodeHash: common.BytesToHash(n),
|
NodeHash: common.BytesToHash(n),
|
||||||
|
|
@ -423,11 +428,7 @@ func (t *Trie) resolveHash(n hashNode, prefix, suffix []byte) (node, error) {
|
||||||
SuffixLen: len(suffix),
|
SuffixLen: len(suffix),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dec := mustDecodeNode(n, enc)
|
return v, nil
|
||||||
if dec != nil {
|
|
||||||
globalCache.Put(n, dec)
|
|
||||||
}
|
|
||||||
return dec, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Root returns the root hash of the trie.
|
// Root returns the root hash of the trie.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue