Skip to content

Commit 101bcbb

Browse files
aaronbuchwaldmaoueh
authored andcommitted
trie: move locking into trieDB insert method (ethereum#25030)
Move locking into trieDB insert function
1 parent eac1b86 commit 101bcbb

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

trie/committer.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,7 @@ func (c *committer) store(n node, db *Database) node {
193193
} else if db != nil {
194194
// No leaf-callback used, but there's still a database. Do serial
195195
// insertion
196-
db.lock.Lock()
197196
db.insert(common.BytesToHash(hash), size, n)
198-
db.lock.Unlock()
199197
}
200198
return hash
201199
}
@@ -209,9 +207,7 @@ func (c *committer) commitLoop(db *Database) {
209207
n = item.node
210208
)
211209
// We are pooling the trie nodes into an intermediate memory cache
212-
db.lock.Lock()
213210
db.insert(hash, size, n)
214-
db.lock.Unlock()
215211

216212
if c.onleaf != nil {
217213
switch n := n.(type) {

trie/database.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ func (db *Database) DiskDB() ethdb.KeyValueStore {
316316
// All nodes inserted by this function will be reference tracked
317317
// and in theory should only used for **trie nodes** insertion.
318318
func (db *Database) insert(hash common.Hash, size int, node node) {
319+
db.lock.Lock()
320+
defer db.lock.Unlock()
321+
319322
// If the node's already cached, skip
320323
if _, ok := db.dirties[hash]; ok {
321324
return

0 commit comments

Comments
 (0)