Skip to content

Commit 02159d5

Browse files
authored
eth/tracers/logger: improve markdown logger (#30805)
This PR improves the output of the markdown logger a bit. - Remove `RStack` field, - Move `Stack` last, since it may have very large vertical expansion - Make the pre- and post-exec metadata structured into a bullet-list
1 parent ab4a1cc commit 02159d5

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

eth/tracers/logger/logger.go

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -363,34 +363,44 @@ func (t *mdLogger) OnEnter(depth int, typ byte, from common.Address, to common.A
363363
if depth != 0 {
364364
return
365365
}
366-
create := vm.OpCode(typ) == vm.CREATE
367-
if !create {
368-
fmt.Fprintf(t.out, "From: `%v`\nTo: `%v`\nData: `%#x`\nGas: `%d`\nValue `%v` wei\n",
369-
from.String(), to.String(),
370-
input, gas, value)
366+
if create := vm.OpCode(typ) == vm.CREATE; !create {
367+
fmt.Fprintf(t.out, "Pre-execution info:\n"+
368+
" - from: `%v`\n"+
369+
" - to: `%v`\n"+
370+
" - data: `%#x`\n"+
371+
" - gas: `%d`\n"+
372+
" - value: `%v` wei\n",
373+
from.String(), to.String(), input, gas, value)
371374
} else {
372-
fmt.Fprintf(t.out, "From: `%v`\nCreate at: `%v`\nData: `%#x`\nGas: `%d`\nValue `%v` wei\n",
373-
from.String(), to.String(),
374-
input, gas, value)
375+
fmt.Fprintf(t.out, "Pre-execution info:\n"+
376+
" - from: `%v`\n"+
377+
" - create: `%v`\n"+
378+
" - data: `%#x`\n"+
379+
" - gas: `%d`\n"+
380+
" - value: `%v` wei\n",
381+
from.String(), to.String(), input, gas, value)
375382
}
376-
377383
fmt.Fprintf(t.out, `
378-
| Pc | Op | Cost | Stack | RStack | Refund |
379-
|-------|-------------|------|-----------|-----------|---------|
384+
| Pc | Op | Cost | Refund | Stack |
385+
|-------|-------------|------|-----------|-----------|
380386
`)
381387
}
382388

383389
func (t *mdLogger) OnExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
384390
if depth == 0 {
385-
fmt.Fprintf(t.out, "\nOutput: `%#x`\nConsumed gas: `%d`\nError: `%v`\n",
391+
fmt.Fprintf(t.out, "\nPost-execution info:\n"+
392+
" - output: `%#x`\n"+
393+
" - consumed gas: `%d`\n"+
394+
" - error: `%v`\n",
386395
output, gasUsed, err)
387396
}
388397
}
389398

390399
// OnOpcode also tracks SLOAD/SSTORE ops to track storage change.
391400
func (t *mdLogger) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
392401
stack := scope.StackData()
393-
fmt.Fprintf(t.out, "| %4d | %10v | %3d |", pc, vm.OpCode(op).String(), cost)
402+
fmt.Fprintf(t.out, "| %4d | %10v | %3d |%10v |", pc, vm.OpCode(op).String(),
403+
cost, t.env.StateDB.GetRefund())
394404

395405
if !t.cfg.DisableStack {
396406
// format stack
@@ -401,7 +411,6 @@ func (t *mdLogger) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.
401411
b := fmt.Sprintf("[%v]", strings.Join(a, ","))
402412
fmt.Fprintf(t.out, "%10v |", b)
403413
}
404-
fmt.Fprintf(t.out, "%10v |", t.env.StateDB.GetRefund())
405414
fmt.Fprintln(t.out, "")
406415
if err != nil {
407416
fmt.Fprintf(t.out, "Error: %v\n", err)

0 commit comments

Comments
 (0)