trie: handle removing the freshest node too

parent 6380c06c
...@@ -475,9 +475,14 @@ func (db *Database) dereference(child common.Hash, parent common.Hash) { ...@@ -475,9 +475,14 @@ func (db *Database) dereference(child common.Hash, parent common.Hash) {
} }
if node.parents == 0 { if node.parents == 0 {
// Remove the node from the flush-list // Remove the node from the flush-list
if child == db.oldest { switch child {
case db.oldest:
db.oldest = node.flushNext 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.flushPrev].flushNext = node.flushNext
db.nodes[node.flushNext].flushPrev = node.flushPrev db.nodes[node.flushNext].flushPrev = node.flushPrev
} }
...@@ -697,9 +702,14 @@ func (db *Database) uncache(hash common.Hash) { ...@@ -697,9 +702,14 @@ func (db *Database) uncache(hash common.Hash) {
return return
} }
// Node still exists, remove it from the flush-list // Node still exists, remove it from the flush-list
if hash == db.oldest { switch hash {
case db.oldest:
db.oldest = node.flushNext 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.flushPrev].flushNext = node.flushNext
db.nodes[node.flushNext].flushPrev = node.flushPrev db.nodes[node.flushNext].flushPrev = node.flushPrev
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment