Skip to content

Commit

Permalink
core/state/snapshot: acquire the lock on Release (ethereum#30011)
Browse files Browse the repository at this point in the history
* core/state/snapshot: acquire the lock on release

* core/state/snapshot: only acquire read-lock when iterating
  • Loading branch information
MariusVanDerWijden authored Jun 18, 2024
1 parent d866449 commit 7cf6a63
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions core/state/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,9 @@ func diffToDisk(bottom *diffLayer) *diskLayer {

// Release releases resources
func (t *Tree) Release() {
t.lock.RLock()
defer t.lock.RUnlock()

if dl := t.disklayer(); dl != nil {
dl.Release()
}
Expand Down Expand Up @@ -850,8 +853,8 @@ 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()
t.lock.RLock()
defer t.lock.RUnlock()

layer := t.disklayer()
if layer == nil {
Expand All @@ -864,8 +867,8 @@ func (t *Tree) generating() (bool, error) {

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

return t.diskRoot()
}
Expand Down

0 comments on commit 7cf6a63

Please sign in to comment.