Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trie: move locking into trieDB insert method #25030

Merged
merged 1 commit into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions trie/committer.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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