Skip to content

Commit 01bb908

Browse files
committed
core,eth: cancel evm on nativecalltracer stop
1 parent a839259 commit 01bb908

File tree

9 files changed

+19
-17
lines changed

9 files changed

+19
-17
lines changed

core/vm/access_list_tracer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (*AccessListTracer) CaptureFault(env *EVM, pc uint64, op OpCode, gas, cost
166166

167167
func (*AccessListTracer) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) {}
168168

169-
func (*AccessListTracer) CaptureEnter(typ OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
169+
func (*AccessListTracer) CaptureEnter(env *EVM, typ OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
170170
}
171171

172172
func (*AccessListTracer) CaptureExit(output []byte, gasUsed uint64, err error) {}

core/vm/evm.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
187187
evm.Config.Tracer.CaptureStart(evm, caller.Address(), addr, false, input, gas, value)
188188
evm.Config.Tracer.CaptureEnd(ret, 0, 0, nil)
189189
} else {
190-
evm.Config.Tracer.CaptureEnter(CALL, caller.Address(), addr, input, gas, value)
190+
evm.Config.Tracer.CaptureEnter(evm, CALL, caller.Address(), addr, input, gas, value)
191191
evm.Config.Tracer.CaptureExit(ret, 0, nil)
192192
}
193193
}
@@ -206,7 +206,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
206206
}(gas, time.Now())
207207
} else {
208208
// Handle tracer events for entering and exiting a call frame
209-
evm.Config.Tracer.CaptureEnter(CALL, caller.Address(), addr, input, gas, value)
209+
evm.Config.Tracer.CaptureEnter(evm, CALL, caller.Address(), addr, input, gas, value)
210210
defer func(startGas uint64) {
211211
evm.Config.Tracer.CaptureExit(ret, startGas-gas, err)
212212
}(gas)
@@ -272,7 +272,7 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte,
272272

273273
// Invoke tracer hooks that signal entering/exiting a call frame
274274
if evm.Config.Debug {
275-
evm.Config.Tracer.CaptureEnter(CALLCODE, caller.Address(), addr, input, gas, value)
275+
evm.Config.Tracer.CaptureEnter(evm, CALLCODE, caller.Address(), addr, input, gas, value)
276276
defer func(startGas uint64) {
277277
evm.Config.Tracer.CaptureExit(ret, startGas-gas, err)
278278
}(gas)
@@ -316,7 +316,7 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by
316316

317317
// Invoke tracer hooks that signal entering/exiting a call frame
318318
if evm.Config.Debug {
319-
evm.Config.Tracer.CaptureEnter(DELEGATECALL, caller.Address(), addr, input, gas, nil)
319+
evm.Config.Tracer.CaptureEnter(evm, DELEGATECALL, caller.Address(), addr, input, gas, nil)
320320
defer func(startGas uint64) {
321321
evm.Config.Tracer.CaptureExit(ret, startGas-gas, err)
322322
}(gas)
@@ -369,7 +369,7 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte
369369

370370
// Invoke tracer hooks that signal entering/exiting a call frame
371371
if evm.Config.Debug {
372-
evm.Config.Tracer.CaptureEnter(STATICCALL, caller.Address(), addr, input, gas, nil)
372+
evm.Config.Tracer.CaptureEnter(evm, STATICCALL, caller.Address(), addr, input, gas, nil)
373373
defer func(startGas uint64) {
374374
evm.Config.Tracer.CaptureExit(ret, startGas-gas, err)
375375
}(gas)
@@ -456,7 +456,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
456456
if evm.depth == 0 {
457457
evm.Config.Tracer.CaptureStart(evm, caller.Address(), address, true, codeAndHash.code, gas, value)
458458
} else {
459-
evm.Config.Tracer.CaptureEnter(typ, caller.Address(), address, codeAndHash.code, gas, value)
459+
evm.Config.Tracer.CaptureEnter(evm, typ, caller.Address(), address, codeAndHash.code, gas, value)
460460
}
461461
}
462462

core/vm/instructions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ func opSuicide(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]
792792
interpreter.evm.StateDB.AddBalance(beneficiary.Bytes20(), balance)
793793
interpreter.evm.StateDB.Suicide(scope.Contract.Address())
794794
if interpreter.cfg.Debug {
795-
interpreter.cfg.Tracer.CaptureEnter(SELFDESTRUCT, scope.Contract.Address(), beneficiary.Bytes20(), []byte{}, 0, balance)
795+
interpreter.cfg.Tracer.CaptureEnter(interpreter.evm, SELFDESTRUCT, scope.Contract.Address(), beneficiary.Bytes20(), []byte{}, 0, balance)
796796
interpreter.cfg.Tracer.CaptureExit([]byte{}, 0, nil)
797797
}
798798
return nil, nil

core/vm/logger.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (s *StructLog) ErrorString() string {
106106
type EVMLogger interface {
107107
CaptureStart(env *EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int)
108108
CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint64, scope *ScopeContext, rData []byte, depth int, err error)
109-
CaptureEnter(typ OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int)
109+
CaptureEnter(env *EVM, typ OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int)
110110
CaptureExit(output []byte, gasUsed uint64, err error)
111111
CaptureFault(env *EVM, pc uint64, op OpCode, gas, cost uint64, scope *ScopeContext, depth int, err error)
112112
CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error)
@@ -227,7 +227,7 @@ func (l *StructLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration
227227
}
228228
}
229229

230-
func (l *StructLogger) CaptureEnter(typ OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
230+
func (l *StructLogger) CaptureEnter(env *EVM, typ OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
231231
}
232232

233233
func (l *StructLogger) CaptureExit(output []byte, gasUsed uint64, err error) {}
@@ -350,7 +350,7 @@ func (t *mdLogger) CaptureEnd(output []byte, gasUsed uint64, tm time.Duration, e
350350
output, gasUsed, err)
351351
}
352352

353-
func (t *mdLogger) CaptureEnter(typ OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
353+
func (t *mdLogger) CaptureEnter(env *EVM, typ OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
354354
}
355355

356356
func (t *mdLogger) CaptureExit(output []byte, gasUsed uint64, err error) {}

core/vm/logger_json.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (l *JSONLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration,
8888
l.encoder.Encode(endLog{common.Bytes2Hex(output), math.HexOrDecimal64(gasUsed), t, errMsg})
8989
}
9090

91-
func (l *JSONLogger) CaptureEnter(typ OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
91+
func (l *JSONLogger) CaptureEnter(env *EVM, typ OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
9292
}
9393

9494
func (l *JSONLogger) CaptureExit(output []byte, gasUsed uint64, err error) {}

eth/tracers/native/call.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ func (t *callTracer) CaptureState(env *vm.EVM, pc uint64, op vm.OpCode, gas, cos
9090
func (t *callTracer) CaptureFault(env *vm.EVM, pc uint64, op vm.OpCode, gas, cost uint64, _ *vm.ScopeContext, depth int, err error) {
9191
}
9292

93-
func (t *callTracer) CaptureEnter(typ vm.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
93+
func (t *callTracer) CaptureEnter(env *vm.EVM, typ vm.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
9494
// Skip if tracing was interrupted
9595
if atomic.LoadUint32(&t.interrupt) > 0 {
96-
// TODO: env.Cancel()
96+
env.Cancel()
9797
return
9898
}
9999

eth/tracers/native/noop.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (t *noopTracer) CaptureState(env *vm.EVM, pc uint64, op vm.OpCode, gas, cos
3232
func (t *noopTracer) CaptureFault(env *vm.EVM, pc uint64, op vm.OpCode, gas, cost uint64, _ *vm.ScopeContext, depth int, err error) {
3333
}
3434

35-
func (t *noopTracer) CaptureEnter(typ vm.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
35+
func (t *noopTracer) CaptureEnter(env *vm.EVM, typ vm.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
3636
}
3737

3838
func (t *noopTracer) CaptureExit(output []byte, gasUsed uint64, err error) {

eth/tracers/tracer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ func (jst *jsTracer) CaptureEnd(output []byte, gasUsed uint64, t time.Duration,
750750
}
751751

752752
// CaptureEnter is called when EVM enters a new scope (via call, create or selfdestruct).
753-
func (jst *jsTracer) CaptureEnter(typ vm.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
753+
func (jst *jsTracer) CaptureEnter(env *vm.EVM, typ vm.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
754754
if !jst.traceCallFrames {
755755
return
756756
}

eth/tracers/tracer_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,10 @@ func TestEnterExit(t *testing.T) {
255255
scope := &vm.ScopeContext{
256256
Contract: vm.NewContract(&account{}, &account{}, big.NewInt(0), 0),
257257
}
258+
vmctx := testCtx()
259+
env := vm.NewEVM(vmctx.blockCtx, vmctx.txCtx, &dummyStatedb{}, params.TestChainConfig, vm.Config{Debug: true, Tracer: tracer})
258260

259-
tracer.CaptureEnter(vm.CALL, scope.Contract.Caller(), scope.Contract.Address(), []byte{}, 1000, new(big.Int))
261+
tracer.CaptureEnter(env, vm.CALL, scope.Contract.Caller(), scope.Contract.Address(), []byte{}, 1000, new(big.Int))
260262
tracer.CaptureExit([]byte{}, 400, nil)
261263

262264
have, err := tracer.GetResult()

0 commit comments

Comments
 (0)