core/state: split the lock into two

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
jsvisa 2025-04-08 12:21:09 +08:00
parent 7c5fc085b0
commit a1cdc4f19f

View file

@ -1122,9 +1122,10 @@ func (s *StateDB) commit(deleteEmptyObjects bool, noStorageWiping bool) (*stateU
storageTrieNodesUpdated atomic.Int32 storageTrieNodesUpdated atomic.Int32
storageTrieNodesDeleted atomic.Int32 storageTrieNodesDeleted atomic.Int32
lock sync.Mutex // protect two maps below nodesLock sync.Mutex // protect the nodes map
nodes = trienode.NewMergedNodeSet() // aggregated trie nodes updatesLock sync.Mutex // protect the updates map
updates = make(map[common.Hash]*accountUpdate, len(s.mutations)) // aggregated account updates nodes = trienode.NewMergedNodeSet() // aggregated trie nodes
updates = make(map[common.Hash]*accountUpdate, len(s.mutations)) // aggregated account updates
// merge aggregates the dirty trie nodes into the global set. // merge aggregates the dirty trie nodes into the global set.
// //
@ -1149,8 +1150,8 @@ func (s *StateDB) commit(deleteEmptyObjects bool, noStorageWiping bool) (*stateU
storageTrieNodesDeleted.Add(int32(deletes)) storageTrieNodesDeleted.Add(int32(deletes))
} }
lock.Lock() nodesLock.Lock()
defer lock.Unlock() defer nodesLock.Unlock()
return nodes.Merge(set) return nodes.Merge(set)
} }
) )
@ -1221,10 +1222,10 @@ func (s *StateDB) commit(deleteEmptyObjects bool, noStorageWiping bool) (*stateU
if err := merge(set); err != nil { if err := merge(set); err != nil {
return err return err
} }
lock.Lock() updatesLock.Lock()
updates[obj.addrHash] = update updates[obj.addrHash] = update
s.StorageCommits = time.Since(start) // overwrite with the longest storage commit runtime s.StorageCommits = time.Since(start) // overwrite with the longest storage commit runtime
lock.Unlock() updatesLock.Unlock()
return nil return nil
}) })
} }