Skip to content

Commit 09e8bde

Browse files
s7v7nislandsshekhirin
authored andcommitted
core/state: use atomic.Bool (ethereum#26992)
1 parent f3f8d82 commit 09e8bde

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

core/state/snapshot/difflayer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ type diffLayer struct {
103103
memory uint64 // Approximate guess as to how much memory we use
104104

105105
root common.Hash // Root hash to which this snapshot diff belongs to
106-
stale uint32 // Signals that the layer became stale (state progressed)
106+
stale atomic.Bool // Signals that the layer became stale (state progressed)
107107

108108
// destructSet is a very special helper marker. If an account is marked as
109109
// deleted, then it's recorded in this set. However it's allowed that an account
@@ -267,7 +267,7 @@ func (dl *diffLayer) Parent() snapshot {
267267
// Stale return whether this layer has become stale (was flattened across) or if
268268
// it's still live.
269269
func (dl *diffLayer) Stale() bool {
270-
return atomic.LoadUint32(&dl.stale) != 0
270+
return dl.stale.Load()
271271
}
272272

273273
// Account directly retrieves the account associated with a particular hash in
@@ -449,7 +449,7 @@ func (dl *diffLayer) flatten() snapshot {
449449

450450
// Before actually writing all our data to the parent, first ensure that the
451451
// parent hasn't been 'corrupted' by someone else already flattening into it
452-
if atomic.SwapUint32(&parent.stale, 1) != 0 {
452+
if parent.stale.Swap(true) {
453453
panic("parent diff layer is stale") // we've flattened into the same parent from two children, boo
454454
}
455455
// Overwrite all the updated accounts blindly, merge the sorted list

core/state/snapshot/snapshot.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"errors"
2323
"fmt"
2424
"sync"
25-
"sync/atomic"
2625

2726
"github.com/ethereum/go-ethereum/common"
2827
"github.com/ethereum/go-ethereum/core/rawdb"
@@ -272,7 +271,7 @@ func (t *Tree) Disable() {
272271
case *diffLayer:
273272
// If the layer is a simple diff, simply mark as stale
274273
layer.lock.Lock()
275-
atomic.StoreUint32(&layer.stale, 1)
274+
layer.stale.Store(true)
276275
layer.lock.Unlock()
277276

278277
default:
@@ -726,7 +725,7 @@ func (t *Tree) Rebuild(root common.Hash) {
726725
case *diffLayer:
727726
// If the layer is a simple diff, simply mark as stale
728727
layer.lock.Lock()
729-
atomic.StoreUint32(&layer.stale, 1)
728+
layer.stale.Store(true)
730729
layer.lock.Unlock()
731730

732731
default:

0 commit comments

Comments
 (0)