Skip to content

Commit

Permalink
Fix: racying issue in fixUpOriginAndResetPendingStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny2022da committed Jul 30, 2024
1 parent 19292e6 commit 09ef03b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -986,9 +986,12 @@ func (s *stateObject) fixUpOriginAndResetPendingStorage() {
if s.db.isParallel && s.db.parallel.isSlotDB {
mainDB := s.db.parallel.baseStateDB
origObj := mainDB.getStateObjectNoUpdate(s.address)
s.storageRecordsLock.RLock()
s.storageRecordsLock.Lock()
if origObj != nil && origObj.originStorage.Length() != 0 {
// There can be racing issue with CopyForSlot/LightCopy
origObj.storageRecordsLock.RLock()
originStorage := origObj.originStorage.Copy()
origObj.storageRecordsLock.RUnlock()
// During the tx execution, the originStorage can be updated with GetCommittedState()
// But is never get updated for the already existed one as there is no finalise called in execution.
// so here get the latest object in MainDB, and update the object storage with
Expand All @@ -1007,6 +1010,6 @@ func (s *stateObject) fixUpOriginAndResetPendingStorage() {
if s.pendingStorage.Length() > 0 {
s.pendingStorage = newStorage(false)
}
s.storageRecordsLock.RUnlock()
s.storageRecordsLock.Unlock()
}
}

0 comments on commit 09ef03b

Please sign in to comment.