triedb/pathdb: double check the list availability before regeneration (#33622)
Some checks are pending
/ Linux Build (push) Waiting to run
/ Linux Build (arm) (push) Waiting to run
/ Keeper Build (push) Waiting to run
/ Windows Build (push) Waiting to run
/ Docker Image (push) Waiting to run

Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
This commit is contained in:
cui 2026-01-19 20:45:31 +08:00 committed by GitHub
parent 500931bc82
commit d0af257aa2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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