Merge pull request #17282 from karalabe/trie-flushlist-fixes

trie: handle removing the freshest node too
This commit is contained in:
Péter Szilágyi 2018-07-31 10:41:53 +03:00 committed by GitHub
commit d927cbb638
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 4 deletions

View File

@ -475,9 +475,14 @@ func (db *Database) dereference(child common.Hash, parent common.Hash) {
}
if node.parents == 0 {
// Remove the node from the flush-list
if child == db.oldest {
switch child {
case db.oldest:
db.oldest = node.flushNext
} else {
db.nodes[node.flushNext].flushPrev = common.Hash{}
case db.newest:
db.newest = node.flushPrev
db.nodes[node.flushPrev].flushNext = common.Hash{}
default:
db.nodes[node.flushPrev].flushNext = node.flushNext
db.nodes[node.flushNext].flushPrev = node.flushPrev
}
@ -697,9 +702,14 @@ func (db *Database) uncache(hash common.Hash) {
return
}
// Node still exists, remove it from the flush-list
if hash == db.oldest {
switch hash {
case db.oldest:
db.oldest = node.flushNext
} else {
db.nodes[node.flushNext].flushPrev = common.Hash{}
case db.newest:
db.newest = node.flushPrev
db.nodes[node.flushPrev].flushNext = common.Hash{}
default:
db.nodes[node.flushPrev].flushNext = node.flushNext
db.nodes[node.flushNext].flushPrev = node.flushPrev
}