From c46beb8c3a71dbf2a329ed9aa0375801862d083d Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Mon, 18 Jul 2022 11:39:55 +0800 Subject: [PATCH] fix trace revert --- eth/tracers/api.go | 2 +- eth/tracers/native/types.go | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/eth/tracers/api.go b/eth/tracers/api.go index 61db29ce1..345da44e5 100644 --- a/eth/tracers/api.go +++ b/eth/tracers/api.go @@ -910,7 +910,7 @@ func (api *API) traceTx(ctx context.Context, message core.Message, txctx *Contex case config.Tracer != nil: // Define a meaningful timeout of a single transaction trace plain = config.Plain - timeout := defaultTraceTimeout + timeout := time.Minute if config.Timeout != nil { if timeout, err = time.ParseDuration(*config.Timeout); err != nil { return nil, err diff --git a/eth/tracers/native/types.go b/eth/tracers/native/types.go index a3755bef4..bfc8fc68d 100644 --- a/eth/tracers/native/types.go +++ b/eth/tracers/native/types.go @@ -19,6 +19,7 @@ package native import ( "encoding/hex" "encoding/json" + "errors" "fmt" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/vm" @@ -80,7 +81,6 @@ type OpsTracer struct { currentDepth int currentFrame *OpsCallFrame interrupt uint32 // Atomic flag to signal execution interruption - reason error // Textual reason for the interruption initialized bool } @@ -137,9 +137,11 @@ func (t *OpsTracer) getLabel(topic0 string) string { func (t *OpsTracer) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, rData []byte, depth int, err error) { if err != nil { - t.reason = err if t.currentFrame != nil { t.currentFrame.Error = err.Error() + t.currentFrame.Calls = []*OpsCallFrame{} + t.currentFrame = t.currentFrame.parent + t.currentDepth -= 1 } return } @@ -324,8 +326,8 @@ func (t *OpsTracer) GetCallStack() *OpsCallFrame { if len(t.callstack.Error) != 0 { t.callstack.Calls = []*OpsCallFrame{} } - if t.reason != nil { - t.callstack.Error = t.reason.Error() + errString := t.callstack.Error + if len(errString) > 0 { t.callstack.Calls = []*OpsCallFrame{} } return &t.callstack @@ -381,6 +383,11 @@ func dfs(node *protobuf.StackFrame, prefix string, sks *[]types.PlainStackFrame) func (t *OpsTracer) GetResult() (json.RawMessage, error) { result := t.GetCallStack() + errString := t.callstack.Error + var traceErr error + if len(errString) > 0 { + traceErr = errors.New(errString) + } if t.plain { pbTrace := toPbCallTrace(result) ptxs := make([]types.PlainStackFrame, 0) @@ -389,17 +396,17 @@ func (t *OpsTracer) GetResult() (json.RawMessage, error) { if err != nil { return nil, err } - return res, t.reason + return res, traceErr } res, err := json.Marshal(result) if err != nil { return nil, err } - return res, t.reason + return res, traceErr } func (t *OpsTracer) Stop(err error) { - t.reason = err + t.callstack.Error = err.Error() atomic.StoreUint32(&t.interrupt, 1) }