Skip to content

Commit

Permalink
trie: Fix concurrent map access on trie.dirties
Browse files Browse the repository at this point in the history
The dirties map of trie.Database was not read protected inside the
commit function, since the trie.Database is called from many go-routines
this sometimes lead to concurrent map read and write errors.

The solution is to read lock over trie.dirties in commit
  • Loading branch information
piersy committed Oct 1, 2021
1 parent b522f5e commit b5a3d8e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions trie/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,10 +755,15 @@ func (db *Database) Commit(node common.Hash, report bool, callback func(common.H
// commit is the private locked version of Commit.
func (db *Database) commit(hash common.Hash, batch ethdb.Batch, uncacher *cleaner, callback func(common.Hash)) error {
// If the node does not exist, it's a previously committed node

db.lock.RLock()
node, ok := db.dirties[hash]
if !ok {
db.lock.RUnlock()
return nil
}
db.lock.RUnlock()

var err error
node.forChilds(func(child common.Hash) {
if err == nil {
Expand Down

0 comments on commit b5a3d8e

Please sign in to comment.