From d0af257aa20fe9d3e244570ee4abb9a78ff3b9c4 Mon Sep 17 00:00:00 2001 From: cui Date: Mon, 19 Jan 2026 20:45:31 +0800 Subject: [PATCH] triedb/pathdb: double check the list availability before regeneration (#33622) Co-authored-by: rjl493456442 --- triedb/pathdb/states.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/triedb/pathdb/states.go b/triedb/pathdb/states.go index dc737c3b53..c84e2dc60c 100644 --- a/triedb/pathdb/states.go +++ b/triedb/pathdb/states.go @@ -170,12 +170,13 @@ func (s *stateSet) accountList() []common.Hash { if list != nil { return list } - // No old sorted account list exists, generate a new one. It's possible that - // multiple threads waiting for the write lock may regenerate the list - // multiple times, which is acceptable. s.listLock.Lock() defer s.listLock.Unlock() + // Double check after acquiring the write lock + if list = s.accountListSorted; list != nil { + return list + } list = slices.SortedFunc(maps.Keys(s.accountData), common.Hash.Cmp) s.accountListSorted = list return list @@ -200,12 +201,13 @@ func (s *stateSet) storageList(accountHash common.Hash) []common.Hash { } s.listLock.RUnlock() - // No old sorted account list exists, generate a new one. It's possible that - // multiple threads waiting for the write lock may regenerate the list - // multiple times, which is acceptable. s.listLock.Lock() defer s.listLock.Unlock() + // Double check after acquiring the write lock + if list := s.storageListSorted[accountHash]; list != nil { + return list + } list := slices.SortedFunc(maps.Keys(s.storageData[accountHash]), common.Hash.Cmp) s.storageListSorted[accountHash] = list return list