Skip to content

Commit

Permalink
skip on system calls
Browse files Browse the repository at this point in the history
  • Loading branch information
s1na committed Dec 19, 2024
1 parent 1e4038f commit fa9e6f4
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions eth/tracers/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ type StructLogger struct {

interrupt atomic.Bool // Atomic flag to signal execution interruption
reason error // Textual reason for the interruption
skip bool // skip processing hooks.
}

// NewStreamingStructLogger returns a new streaming logger.
Expand All @@ -243,6 +244,7 @@ func (l *StructLogger) Hooks() *tracing.Hooks {
OnTxStart: l.OnTxStart,
OnTxEnd: l.OnTxEnd,
OnSystemCallStartV2: l.OnSystemCallStart,
OnSystemCallEnd: l.OnSystemCallEnd,
OnExit: l.OnExit,
OnOpcode: l.OnOpcode,
}
Expand All @@ -256,6 +258,10 @@ func (l *StructLogger) OnOpcode(pc uint64, opcode byte, gas, cost uint64, scope
if l.interrupt.Load() {
return
}
// Processing a system call.
if l.skip {
return
}
// check if already accumulated the size of the response.
if l.cfg.Limit != 0 && l.resultSize > l.cfg.Limit {
return
Expand Down Expand Up @@ -321,6 +327,9 @@ func (l *StructLogger) OnExit(depth int, output []byte, gasUsed uint64, err erro
if depth != 0 {
return
}
if l.skip {
return
}
l.output = output
l.err = err
// TODO @holiman, should we output the per-scope output?
Expand Down Expand Up @@ -362,7 +371,11 @@ func (l *StructLogger) OnTxStart(env *tracing.VMContext, tx *types.Transaction,
l.env = env
}
func (l *StructLogger) OnSystemCallStart(env *tracing.VMContext) {
l.env = env
l.skip = true
}

func (l *StructLogger) OnSystemCallEnd() {
l.skip = false
}

func (l *StructLogger) OnTxEnd(receipt *types.Receipt, err error) {
Expand Down Expand Up @@ -393,9 +406,10 @@ func WriteTrace(writer io.Writer, logs []StructLog) {
}

type mdLogger struct {
out io.Writer
cfg *Config
env *tracing.VMContext
out io.Writer
cfg *Config
env *tracing.VMContext
skip bool
}

// NewMarkdownLogger creates a logger which outputs information in a format adapted
Expand All @@ -412,6 +426,7 @@ func (t *mdLogger) Hooks() *tracing.Hooks {
return &tracing.Hooks{
OnTxStart: t.OnTxStart,
OnSystemCallStartV2: t.OnSystemCallStart,
OnSystemCallEnd: t.OnSystemCallEnd,
OnEnter: t.OnEnter,
OnExit: t.OnExit,
OnOpcode: t.OnOpcode,
Expand All @@ -422,11 +437,19 @@ func (t *mdLogger) Hooks() *tracing.Hooks {
func (t *mdLogger) OnTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
t.env = env
}

func (t *mdLogger) OnSystemCallStart(env *tracing.VMContext) {
t.env = env
t.skip = true
}

func (t *mdLogger) OnSystemCallEnd() {
t.skip = false
}

func (t *mdLogger) OnEnter(depth int, typ byte, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
if t.skip {
return
}
if depth != 0 {
return
}
Expand Down Expand Up @@ -454,6 +477,9 @@ func (t *mdLogger) OnEnter(depth int, typ byte, from common.Address, to common.A
}

func (t *mdLogger) OnExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
if t.skip {
return
}
if depth == 0 {
fmt.Fprintf(t.out, "\nPost-execution info:\n"+
" - output: `%#x`\n"+
Expand All @@ -465,6 +491,9 @@ func (t *mdLogger) OnExit(depth int, output []byte, gasUsed uint64, err error, r

// OnOpcode also tracks SLOAD/SSTORE ops to track storage change.
func (t *mdLogger) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
if t.skip {
return
}
stack := scope.StackData()
fmt.Fprintf(t.out, "| %4d | %10v | %3d |%10v |", pc, vm.OpCode(op).String(),
cost, t.env.StateDB.GetRefund())
Expand All @@ -485,6 +514,9 @@ func (t *mdLogger) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.
}

func (t *mdLogger) OnFault(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, depth int, err error) {
if t.skip {
return
}
fmt.Fprintf(t.out, "\nError: at pc=%d, op=%v: %v\n", pc, op, err)
}

Expand Down

0 comments on commit fa9e6f4

Please sign in to comment.