Skip to content

Commit 2c44f20

Browse files
committed
fix missing trie node
1 parent 26b1b05 commit 2c44f20

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

trie/database.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ func (c *HashCache) PutIfAbsent(key []byte, value node) {
121121
}
122122
}
123123

124+
// Contains checks whether the key was cached
125+
func (c *HashCache) Contains(key []byte) bool {
126+
c.lock.RLock()
127+
defer c.lock.RUnlock()
128+
_, exist := c.inner[common.BytesToHash(key)]
129+
return exist
130+
}
131+
124132
// Get reads value of given key from cache with lock protection
125133
func (c *HashCache) Get(key common.Hash) (node, bool) {
126134
c.lock.RLock()

trie/hasher.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ func returnHasherToPool(h *hasher) {
7676
func (h *hasher) hash(n node, force bool) (hashed node, cached node) {
7777
// Return the cached hash if it's available
7878
if hash, _ := n.cache(); hash != nil {
79+
if h.dirties != nil && !h.dirties.Contains(hash) {
80+
h.dirties.Put(hash, n)
81+
}
7982
return hash, n
8083
}
8184
// Trie not processed yet, walk the children

0 commit comments

Comments
 (0)