Skip to content

Commit

Permalink
Merge pull request #68 from stars-labs/bugfix/fix_missing_trie_node
Browse files Browse the repository at this point in the history
fix missing trie node
  • Loading branch information
ken0x4b656e authored Aug 15, 2022
2 parents 26b1b05 + 2c44f20 commit 123ccb1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions trie/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ func (c *HashCache) PutIfAbsent(key []byte, value node) {
}
}

// Contains checks whether the key was cached
func (c *HashCache) Contains(key []byte) bool {
c.lock.RLock()
defer c.lock.RUnlock()
_, exist := c.inner[common.BytesToHash(key)]
return exist
}

// Get reads value of given key from cache with lock protection
func (c *HashCache) Get(key common.Hash) (node, bool) {
c.lock.RLock()
Expand Down
3 changes: 3 additions & 0 deletions trie/hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ func returnHasherToPool(h *hasher) {
func (h *hasher) hash(n node, force bool) (hashed node, cached node) {
// Return the cached hash if it's available
if hash, _ := n.cache(); hash != nil {
if h.dirties != nil && !h.dirties.Contains(hash) {
h.dirties.Put(hash, n)
}
return hash, n
}
// Trie not processed yet, walk the children
Expand Down

0 comments on commit 123ccb1

Please sign in to comment.