Skip to content

Commit 97b83bd

Browse files
s7v7nislandsfjlholiman
authored andcommitted
core/vm: use atomic.Bool (ethereum#26951)
Make use of new atomic types --------- Co-authored-by: Felix Lange <fjl@twurst.com> Co-authored-by: Martin Holst Swende <martin@swende.se>
1 parent 7fabbf7 commit 97b83bd

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

core/vm/evm.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ type EVM struct {
114114
// used throughout the execution of the tx.
115115
interpreter *EVMInterpreter
116116
// abort is used to abort the EVM calling operations
117-
// NOTE: must be set atomically
118-
abort int32
117+
abort atomic.Bool
119118
// callGasTemp holds the gas available for the current call. This is needed because the
120119
// available gas is calculated in gasCall* according to the 63/64 rule and later
121120
// applied in opCall*.
@@ -147,12 +146,12 @@ func (evm *EVM) Reset(txCtx TxContext, statedb StateDB) {
147146
// Cancel cancels any running EVM operation. This may be called concurrently and
148147
// it's safe to be called multiple times.
149148
func (evm *EVM) Cancel() {
150-
atomic.StoreInt32(&evm.abort, 1)
149+
evm.abort.Store(true)
151150
}
152151

153152
// Cancelled returns true if Cancel has been called
154153
func (evm *EVM) Cancelled() bool {
155-
return atomic.LoadInt32(&evm.abort) == 1
154+
return evm.abort.Load()
156155
}
157156

158157
// Interpreter returns the current interpreter

core/vm/instructions.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
package vm
1818

1919
import (
20-
"sync/atomic"
21-
2220
"github.com/ethereum/go-ethereum/common"
2321
"github.com/ethereum/go-ethereum/core/types"
2422
"github.com/ethereum/go-ethereum/crypto"
@@ -531,7 +529,7 @@ func opSstore(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]b
531529
}
532530

533531
func opJump(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
534-
if atomic.LoadInt32(&interpreter.evm.abort) != 0 {
532+
if interpreter.evm.abort.Load() {
535533
return nil, errStopToken
536534
}
537535
pos := scope.Stack.pop()
@@ -543,7 +541,7 @@ func opJump(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byt
543541
}
544542

545543
func opJumpi(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
546-
if atomic.LoadInt32(&interpreter.evm.abort) != 0 {
544+
if interpreter.evm.abort.Load() {
547545
return nil, errStopToken
548546
}
549547
pos, cond := scope.Stack.pop(), scope.Stack.pop()

0 commit comments

Comments
 (0)