From 2f1722cd87cee31f66ea0b1641fd56ea53354244 Mon Sep 17 00:00:00 2001 From: cuiweixie Date: Sat, 17 Jan 2026 01:46:34 +0800 Subject: [PATCH] triedb/pathdb: double check pattern --- triedb/pathdb/states.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/triedb/pathdb/states.go b/triedb/pathdb/states.go index dc737c3b53..59e7be8979 100644 --- a/triedb/pathdb/states.go +++ b/triedb/pathdb/states.go @@ -176,6 +176,11 @@ func (s *stateSet) accountList() []common.Hash { 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 @@ -206,6 +211,11 @@ func (s *stateSet) storageList(accountHash common.Hash) []common.Hash { 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