From 7ef4adf0a623c466b023992560f0dff39dab803f Mon Sep 17 00:00:00 2001 From: Sunny Date: Tue, 8 Oct 2024 10:14:27 +0800 Subject: [PATCH] fix trie prefetch issue after rebase --- core/state/parallel_statedb.go | 2 ++ core/state/state_object.go | 2 ++ core/state/statedb.go | 6 ++++++ 3 files changed, 10 insertions(+) diff --git a/core/state/parallel_statedb.go b/core/state/parallel_statedb.go index a415604df7..6321dfb9d1 100644 --- a/core/state/parallel_statedb.go +++ b/core/state/parallel_statedb.go @@ -1798,7 +1798,9 @@ func (s *ParallelStateDB) FinaliseForParallel(deleteEmptyObjects bool, mainDB *S } if mainDB.prefetcher != nil && len(addressesToPrefetch) > 0 { + mainDB.trieParallelLock.Lock() mainDB.prefetcher.prefetch(common.Hash{}, s.originalRoot, common.Address{}, addressesToPrefetch) + mainDB.trieParallelLock.Unlock() } // Invalidate journal because reverting across transactions is not allowed. s.clearJournalAndRefund() diff --git a/core/state/state_object.go b/core/state/state_object.go index 1b5059140d..561ee0fbef 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -490,7 +490,9 @@ func (s *stateObject) finalise(prefetch bool) { s.dirtyCodeHash = nil } if s.db.prefetcher != nil && prefetch && len(slotsToPrefetch) > 0 && s.data.Root != types.EmptyRootHash { + s.db.trieParallelLock.Lock() s.db.prefetcher.prefetch(s.addrHash, s.data.Root, s.address, slotsToPrefetch) + s.db.trieParallelLock.Unlock() } if s.dirtyStorage.Length() > 0 { s.dirtyStorage = newStorage(s.isParallel) diff --git a/core/state/statedb.go b/core/state/statedb.go index 1838e2882a..d71c675055 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -2451,12 +2451,16 @@ func (s *StateDB) AddrPrefetch(slotDb *ParallelStateDB) { }) obj.storageRecordsLock.RUnlock() if s.prefetcher != nil && len(slotsToPrefetch) > 0 { + s.trieParallelLock.Lock() s.prefetcher.prefetch(obj.addrHash, obj.data.Root, obj.address, slotsToPrefetch) + s.trieParallelLock.Unlock() } } if s.prefetcher != nil && len(addressesToPrefetch) > 0 { + s.trieParallelLock.Lock() s.prefetcher.prefetch(common.Hash{}, s.originalRoot, emptyAddr, addressesToPrefetch) + s.trieParallelLock.Unlock() } } @@ -2623,7 +2627,9 @@ func (s *StateDB) MergeSlotDB(slotDb *ParallelStateDB, slotReceipt *types.Receip } if s.prefetcher != nil && len(addressesToPrefetch) > 0 { + s.trieParallelLock.Lock() s.prefetcher.prefetch(common.Hash{}, s.originalRoot, emptyAddr, addressesToPrefetch) // prefetch for trie node of account + s.trieParallelLock.Unlock() } for addr := range slotDb.stateObjectsPending {