Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions core/state/snapshot/difflayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,19 +525,20 @@ func (dl *diffLayer) StorageList(accountHash common.Hash) ([]common.Hash, bool)
dl.lock.RUnlock()
return list, destructed // the cached list can't be nil
}
storageMap := dl.storageData[accountHash]
dl.lock.RUnlock()

// No old sorted account list exists, generate a new one
dl.lock.Lock()
defer dl.lock.Unlock()

storageMap := dl.storageData[accountHash]
storageList := make([]common.Hash, 0, len(storageMap))
for k := range storageMap {
storageList = append(storageList, k)
}
slices.SortFunc(storageList, common.Hash.Cmp)

// No old sorted account list exists, generate a new one
dl.lock.Lock()
dl.storageList[accountHash] = storageList
dl.memory += uint64(len(dl.storageList)*common.HashLength + common.HashLength)
dl.lock.Unlock()

return storageList, destructed
}
10 changes: 4 additions & 6 deletions core/state/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -818,17 +818,21 @@ func (t *Tree) Verify(root common.Hash) error {
// The lock of snapTree is assumed to be held already.
func (t *Tree) disklayer() *diskLayer {
var snap snapshot
t.lock.RLock()
for _, s := range t.layers {
snap = s
break
}
t.lock.RUnlock()
if snap == nil {
return nil
}
switch layer := snap.(type) {
case *diskLayer:
return layer
case *diffLayer:
layer.lock.RLock()
defer layer.lock.RUnlock()
return layer.origin
default:
panic(fmt.Sprintf("%T: undefined layer", snap))
Expand All @@ -848,9 +852,6 @@ func (t *Tree) diskRoot() common.Hash {
// generating is an internal helper function which reports whether the snapshot
// is still under the construction.
func (t *Tree) generating() (bool, error) {
t.lock.Lock()
defer t.lock.Unlock()

layer := t.disklayer()
if layer == nil {
return false, errors.New("disk layer is missing")
Expand All @@ -862,9 +863,6 @@ func (t *Tree) generating() (bool, error) {

// DiskRoot is a external helper function to return the disk layer root.
func (t *Tree) DiskRoot() common.Hash {
t.lock.Lock()
defer t.lock.Unlock()

return t.diskRoot()
}

Expand Down