core/state/snapshot: acquire the lock on Release (#30011)

* core/state/snapshot: acquire the lock on release

* core/state/snapshot: only acquire read-lock when iterating
pull/30025/head
Marius van der Wijden 5 months ago committed by GitHub
parent d8664490da
commit 7cf6a63687
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 11
      core/state/snapshot/snapshot.go

@ -666,6 +666,9 @@ func diffToDisk(bottom *diffLayer) *diskLayer {
// Release releases resources // Release releases resources
func (t *Tree) Release() { func (t *Tree) Release() {
t.lock.RLock()
defer t.lock.RUnlock()
if dl := t.disklayer(); dl != nil { if dl := t.disklayer(); dl != nil {
dl.Release() dl.Release()
} }
@ -850,8 +853,8 @@ func (t *Tree) diskRoot() common.Hash {
// generating is an internal helper function which reports whether the snapshot // generating is an internal helper function which reports whether the snapshot
// is still under the construction. // is still under the construction.
func (t *Tree) generating() (bool, error) { func (t *Tree) generating() (bool, error) {
t.lock.Lock() t.lock.RLock()
defer t.lock.Unlock() defer t.lock.RUnlock()
layer := t.disklayer() layer := t.disklayer()
if layer == nil { if layer == nil {
@ -864,8 +867,8 @@ func (t *Tree) generating() (bool, error) {
// DiskRoot is an external helper function to return the disk layer root. // DiskRoot is an external helper function to return the disk layer root.
func (t *Tree) DiskRoot() common.Hash { func (t *Tree) DiskRoot() common.Hash {
t.lock.Lock() t.lock.RLock()
defer t.lock.Unlock() defer t.lock.RUnlock()
return t.diskRoot() return t.diskRoot()
} }

Loading…
Cancel
Save