aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2018-07-30 21:31:17 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-07-30 21:31:17 +0800
commit8a9c31a30766eb40bebadfefe0845fac6c9b54a1 (patch)
treee36e29f0530bb4c79fed1b17ba3f92e029384fe6
parent6380c06c6541f6a3422ea3c173baa00100e4ba8e (diff)
downloaddexon-8a9c31a30766eb40bebadfefe0845fac6c9b54a1.tar
dexon-8a9c31a30766eb40bebadfefe0845fac6c9b54a1.tar.gz
dexon-8a9c31a30766eb40bebadfefe0845fac6c9b54a1.tar.bz2
dexon-8a9c31a30766eb40bebadfefe0845fac6c9b54a1.tar.lz
dexon-8a9c31a30766eb40bebadfefe0845fac6c9b54a1.tar.xz
dexon-8a9c31a30766eb40bebadfefe0845fac6c9b54a1.tar.zst
dexon-8a9c31a30766eb40bebadfefe0845fac6c9b54a1.zip
trie: handle removing the freshest node too
-rw-r--r--trie/database.go18
1 files changed, 14 insertions, 4 deletions
diff --git a/trie/database.go b/trie/database.go
index df7fc01ea..8675b9f0a 100644
--- a/trie/database.go
+++ b/trie/database.go
@@ -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
}