From 09ef03b8e45778cfacae99b9105a31bb3cd1c199 Mon Sep 17 00:00:00 2001 From: Sunny Date: Tue, 30 Jul 2024 10:41:59 +0800 Subject: [PATCH] Fix: racying issue in fixUpOriginAndResetPendingStorage --- core/state/state_object.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/state/state_object.go b/core/state/state_object.go index ecf14b0548..cd7cde2947 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -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 @@ -1007,6 +1010,6 @@ func (s *stateObject) fixUpOriginAndResetPendingStorage() { if s.pendingStorage.Length() > 0 { s.pendingStorage = newStorage(false) } - s.storageRecordsLock.RUnlock() + s.storageRecordsLock.Unlock() } }