Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix partially reverted cases handling #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eth/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 17 additions & 8 deletions eth/tracers/native/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -389,17 +396,19 @@ 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
atomic.StoreUint32(&t.interrupt, 1)
if err != nil {
t.callstack.Error = err.Error()
atomic.StoreUint32(&t.interrupt, 1)
}
}