From 9b5a689eacac9a6825cf099a14b375067e7ca602 Mon Sep 17 00:00:00 2001 From: aaronbuchwald Date: Tue, 7 Jun 2022 02:02:04 -0400 Subject: [PATCH] trie: move locking into trieDB insert method (#25030) Move locking into trieDB insert function --- trie/committer.go | 4 ---- trie/database.go | 3 +++ 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/trie/committer.go b/trie/committer.go index 9a7bf48d977fd..9b7ecbf5fcce4 100644 --- a/trie/committer.go +++ b/trie/committer.go @@ -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 } @@ -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) { diff --git a/trie/database.go b/trie/database.go index d71abeee476a5..4167031a584c6 100644 --- a/trie/database.go +++ b/trie/database.go @@ -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