Skip to content

Commit

Permalink
trie: move locking into trieDB insert method (ethereum#25030)
Browse files Browse the repository at this point in the history
Move locking into trieDB insert function
  • Loading branch information
aaronbuchwald authored and blakehhuynh committed Oct 7, 2022
1 parent b44d406 commit a5ceee5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 0 additions & 4 deletions trie/committer.go
Expand Up @@ -193,9 +193,7 @@ func (c *committer) store(n node, db *Database) node {
} else if db != nil {
// No leaf-callback used, but there's still a database. Do serial
// insertion
db.lock.Lock()
db.insert(common.BytesToHash(hash), size, n)
db.lock.Unlock()
}
return hash
}
Expand All @@ -209,9 +207,7 @@ func (c *committer) commitLoop(db *Database) {
n = item.node
)
// We are pooling the trie nodes into an intermediate memory cache
db.lock.Lock()
db.insert(hash, size, n)
db.lock.Unlock()

if c.onleaf != nil {
switch n := n.(type) {
Expand Down
3 changes: 3 additions & 0 deletions trie/database.go
Expand Up @@ -310,6 +310,9 @@ func (db *Database) DiskDB() ethdb.KeyValueStore {
// All nodes inserted by this function will be reference tracked
// and in theory should only used for **trie nodes** insertion.
func (db *Database) insert(hash common.Hash, size int, node node) {
db.lock.Lock()
defer db.lock.Unlock()

// If the node's already cached, skip
if _, ok := db.dirties[hash]; ok {
return
Expand Down

0 comments on commit a5ceee5

Please sign in to comment.