From 4c8dc88a48363095c220e086336c4d01cc60db3d Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Mon, 17 Jun 2024 09:49:24 +0200 Subject: [PATCH 1/2] core/state/snapshot: acquire the lock on release --- core/state/snapshot/snapshot.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/state/snapshot/snapshot.go b/core/state/snapshot/snapshot.go index 89a4c16c209d..4eee5d803760 100644 --- a/core/state/snapshot/snapshot.go +++ b/core/state/snapshot/snapshot.go @@ -666,6 +666,9 @@ func diffToDisk(bottom *diffLayer) *diskLayer { // Release releases resources func (t *Tree) Release() { + t.lock.Lock() + defer t.lock.Unlock() + if dl := t.disklayer(); dl != nil { dl.Release() } From 4579ef94d8f6dd4d941f54e209e37f84ab32962f Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Mon, 17 Jun 2024 15:54:27 +0200 Subject: [PATCH 2/2] core/state/snapshot: only acquire read-lock when iterating --- core/state/snapshot/snapshot.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/state/snapshot/snapshot.go b/core/state/snapshot/snapshot.go index 4eee5d803760..9c3d0fbddfaf 100644 --- a/core/state/snapshot/snapshot.go +++ b/core/state/snapshot/snapshot.go @@ -666,8 +666,8 @@ func diffToDisk(bottom *diffLayer) *diskLayer { // Release releases resources func (t *Tree) Release() { - t.lock.Lock() - defer t.lock.Unlock() + t.lock.RLock() + defer t.lock.RUnlock() if dl := t.disklayer(); dl != nil { dl.Release() @@ -851,8 +851,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 { @@ -865,8 +865,8 @@ 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() + t.lock.RLock() + defer t.lock.RUnlock() return t.diskRoot() }