cmd, core, eth, trie: get rid of trie cache generations (#19262)

* cmd, core, eth, trie: get rid of trie cache generations

* core, trie: get rid of remainder of cache gen boilerplate
This commit is contained in:
Péter Szilágyi
2019-03-14 15:25:12 +02:00
committed by GitHub
parent e270a753be
commit 91eec1251c
21 changed files with 100 additions and 332 deletions

View File

@ -26,11 +26,9 @@ import (
)
type hasher struct {
tmp sliceBuffer
sha keccakState
cachegen uint16
cachelimit uint16
onleaf LeafCallback
tmp sliceBuffer
sha keccakState
onleaf LeafCallback
}
// keccakState wraps sha3.state. In addition to the usual hash methods, it also supports
@ -62,9 +60,9 @@ var hasherPool = sync.Pool{
},
}
func newHasher(cachegen, cachelimit uint16, onleaf LeafCallback) *hasher {
func newHasher(onleaf LeafCallback) *hasher {
h := hasherPool.Get().(*hasher)
h.cachegen, h.cachelimit, h.onleaf = cachegen, cachelimit, onleaf
h.onleaf = onleaf
return h
}
@ -80,14 +78,13 @@ func (h *hasher) hash(n node, db *Database, force bool) (node, node, error) {
if db == nil {
return hash, n, nil
}
if n.canUnload(h.cachegen, h.cachelimit) {
// Unload the node from cache. All of its subnodes will have a lower or equal
// cache generation number.
cacheUnloadCounter.Inc(1)
return hash, hash, nil
}
if !dirty {
return hash, n, nil
switch n.(type) {
case *fullNode, *shortNode:
return hash, hash, nil
default:
return hash, n, nil
}
}
}
// Trie not processed yet or needs storage, walk the children