aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2018-07-31 15:41:53 +0800
committerGitHub <noreply@github.com>2018-07-31 15:41:53 +0800
commitd927cbb638419866de47929a723b5f2b8922c88e (patch)
tree798c86ec08194fe5d0dc4afd8e0a1506dcd51687
parent2fbc454355f6214aee6b9480819e1a4d65bb6fcf (diff)
parent8a9c31a30766eb40bebadfefe0845fac6c9b54a1 (diff)
downloaddexon-d927cbb638419866de47929a723b5f2b8922c88e.tar
dexon-d927cbb638419866de47929a723b5f2b8922c88e.tar.gz
dexon-d927cbb638419866de47929a723b5f2b8922c88e.tar.bz2
dexon-d927cbb638419866de47929a723b5f2b8922c88e.tar.lz
dexon-d927cbb638419866de47929a723b5f2b8922c88e.tar.xz
dexon-d927cbb638419866de47929a723b5f2b8922c88e.tar.zst
dexon-d927cbb638419866de47929a723b5f2b8922c88e.zip
Merge pull request #17282 from karalabe/trie-flushlist-fixes
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
}