From d0a86c45b54663f62771d48200c2be2a2f822785 Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi Date: Thu, 7 Mar 2024 13:08:27 +0100 Subject: [PATCH] rm canceler --- core/tracing/hooks.go | 7 ------- core/vm/evm.go | 1 - eth/tracers/js/goja.go | 35 +++++++++++++++++++++-------------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/core/tracing/hooks.go b/core/tracing/hooks.go index b262b0aed7..df1da15f87 100644 --- a/core/tracing/hooks.go +++ b/core/tracing/hooks.go @@ -45,12 +45,6 @@ type StateDB interface { GetRefund() uint64 } -// Canceler is an interface that wraps the Cancel method. -// It allows loggers to cancel EVM processing. -type Canceler interface { - Cancel() -} - // VMContext provides the context for the EVM execution. type VMContext struct { Coinbase common.Address @@ -61,7 +55,6 @@ type VMContext struct { GasPrice *big.Int ChainConfig *params.ChainConfig StateDB StateDB - VM Canceler } // BlockEvent is emitted upon tracing an incoming block. diff --git a/core/vm/evm.go b/core/vm/evm.go index 8baa69adfa..099ee6c877 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -554,6 +554,5 @@ func (evm *EVM) GetVMContext() *tracing.VMContext { GasPrice: evm.TxContext.GasPrice, ChainConfig: evm.ChainConfig(), StateDB: evm.StateDB, - VM: evm, } } diff --git a/eth/tracers/js/goja.go b/eth/tracers/js/goja.go index 458b99f525..86454d376a 100644 --- a/eth/tracers/js/goja.go +++ b/eth/tracers/js/goja.go @@ -239,7 +239,6 @@ func (t *jsTracer) OnTxStart(env *tracing.VMContext, tx *types.Transaction, from gasPriceBig, err := t.toBig(t.vm, env.GasPrice.String()) if err != nil { t.err = err - t.env.VM.Cancel() return } t.ctx["gasPrice"] = gasPriceBig @@ -248,6 +247,9 @@ func (t *jsTracer) OnTxStart(env *tracing.VMContext, tx *types.Transaction, from // OnTxEnd implements the Tracer interface and is invoked at the end of // transaction processing. func (t *jsTracer) OnTxEnd(receipt *types.Receipt, err error) { + if t.err != nil { + return + } if err != nil { // Don't override vm error if _, ok := t.ctx["error"]; !ok { @@ -260,9 +262,8 @@ func (t *jsTracer) OnTxEnd(receipt *types.Receipt, err error) { // onStart implements the Tracer interface to initialize the tracing operation. func (t *jsTracer) onStart(from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) { - cancel := func(err error) { - t.err = err - t.env.VM.Cancel() + if t.err != nil { + return } if create { t.ctx["type"] = t.vm.ToValue("CREATE") @@ -271,19 +272,19 @@ func (t *jsTracer) onStart(from common.Address, to common.Address, create bool, } fromVal, err := t.toBuf(t.vm, from.Bytes()) if err != nil { - cancel(err) + t.err = err return } t.ctx["from"] = fromVal toVal, err := t.toBuf(t.vm, to.Bytes()) if err != nil { - cancel(err) + t.err = err return } t.ctx["to"] = toVal inputVal, err := t.toBuf(t.vm, input) if err != nil { - cancel(err) + t.err = err return } t.ctx["input"] = inputVal @@ -334,6 +335,9 @@ func (t *jsTracer) OnFault(pc uint64, op byte, gas, cost uint64, scope tracing.O // onEnd is called after the call finishes to finalize the tracing. func (t *jsTracer) onEnd(output []byte, gasUsed uint64, err error, reverted bool) { + if t.err != nil { + return + } if err != nil { t.ctx["error"] = t.vm.ToValue(err.Error()) } @@ -341,6 +345,9 @@ func (t *jsTracer) onEnd(output []byte, gasUsed uint64, err error, reverted bool // OnEnter is called when EVM enters a new scope (via call, create or selfdestruct). func (t *jsTracer) OnEnter(depth int, typ byte, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) { + if t.err != nil { + return + } if depth == 0 { t.onStart(from, to, vm.OpCode(typ) == vm.CREATE, input, gas, value) return @@ -348,9 +355,6 @@ func (t *jsTracer) OnEnter(depth int, typ byte, from common.Address, to common.A if !t.traceFrame { return } - if t.err != nil { - return - } t.frame.typ = vm.OpCode(typ).String() t.frame.from = from @@ -370,6 +374,9 @@ func (t *jsTracer) OnEnter(depth int, typ byte, from common.Address, to common.A // OnExit is called when EVM exits a scope, even if the scope didn't // execute any code. func (t *jsTracer) OnExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) { + if t.err != nil { + return + } if depth == 0 { t.onEnd(output, gasUsed, err, reverted) return @@ -389,6 +396,9 @@ func (t *jsTracer) OnExit(depth int, output []byte, gasUsed uint64, err error, r // GetResult calls the Javascript 'result' function and returns its value, or any accumulated error func (t *jsTracer) GetResult() (json.RawMessage, error) { + if t.err != nil { + return nil, t.err + } ctx := t.vm.ToValue(t.ctx) res, err := t.result(t.obj, ctx, t.dbValue) if err != nil { @@ -398,7 +408,7 @@ func (t *jsTracer) GetResult() (json.RawMessage, error) { if err != nil { return nil, err } - return json.RawMessage(encoded), t.err + return encoded, t.err } // Stop terminates execution of the tracer at the first opportune moment. @@ -411,9 +421,6 @@ func (t *jsTracer) Stop(err error) { // execution. func (t *jsTracer) onError(context string, err error) { t.err = wrapError(context, err) - // `env` is set on OnStart which comes before any JS execution. - // So it should be non-nil. - t.env.VM.Cancel() } func wrapError(context string, err error) error {