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

eth/tracers/logger: use omitempty in error JSON tag to avoid unnecessary log bloat #24487

Closed
odeke-em opened this issue Mar 1, 2022 · 1 comment · Fixed by #24547
Closed
Labels

Comments

@odeke-em
Copy link
Contributor

odeke-em commented Mar 1, 2022

System information

Geth version: geth version Not Applicable
OS & Version: Windows/Linux/OSX Not Applicable
Commit hash : 687e4dc

Expected behaviour

Lack of error strings should NOT log "error":"" which bloats logs and can actually be confusing when you grep for "error" in logs when things are failing.

Actual behaviour

Looking at such logs like

{"pc":4716,"op":80,"gas":"0x688e5","gasCost":"0x2","memory":"0x","memSize":352,"stack":["0xfa31de01","0x29a","0x7d0","0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd","0x80","0x534","0xc0","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7","0x15dc","0x34","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7"],"returnData":"0x","depth":2,"refund":0,"opName":"POP","error":""}
{"pc":4717,"op":80,"gas":"0x688e3","gasCost":"0x2","memory":"0x","memSize":352,"stack":["0xfa31de01","0x29a","0x7d0","0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd","0x80","0x534","0xc0","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7","0x15dc","0x34"],"returnData":"0x","depth":2,"refund":0,"opName":"POP","error":""}
{"pc":4718,"op":86,"gas":"0x688e1","gasCost":"0x8","memory":"0x","memSize":352,"stack":["0xfa31de01","0x29a","0x7d0","0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd","0x80","0x534","0xc0","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7","0x15dc"],"returnData":"0x","depth":2,"refund":0,"opName":"JUMP","error":""}
{"pc":5596,"op":91,"gas":"0x688d9","gasCost":"0x1","memory":"0x","memSize":352,"stack":["0xfa31de01","0x29a","0x7d0","0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd","0x80","0x534","0xc0","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7"],"returnData":"0x","depth":2,"refund":0,"opName":"JUMPDEST","error":""}
{"pc":5597,"op":97,"gas":"0x688d8","gasCost":"0x3","memory":"0x","memSize":352,"stack":["0xfa31de01","0x29a","0x7d0","0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd","0x80","0x534","0xc0","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7"],"returnData":"0x","depth":2,"refund":0,"opName":"PUSH2","error":""}
{"pc":5600,"op":97,"gas":"0x688d5","gasCost":"0x3","memory":"0x","memSize":352,"stack":["0xfa31de01","0x29a","0x7d0","0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd","0x80","0x534","0xc0","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7","0x15ef"],"returnData":"0x","depth":2,"refund":0,"opName":"PUSH2","error":""}
{"pc":5603,"op":97,"gas":"0x688d2","gasCost":"0x3","memory":"0x","memSize":352,"stack":["0xfa31de01","0x29a","0x7d0","0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd","0x80","0x534","0xc0","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7","0x15ef","0x15e7"],"returnData":"0x","depth":2,"refund":0,"opName":"PUSH2","error":""}

Notice that each log line has "error":"" per
Screen Shot 2022-03-01 at 12 31 39 PM

Steps to reproduce the behaviour

Just run the tracers

This bug was sponsored by Tharsis / evmos.org

@s1na
Copy link
Contributor

s1na commented Mar 1, 2022

I take it you're using the evm command? Because debug_traceTransaction already omits empty errors. Anyhow this patch should omit empty errors for evm too.

diff --git a/eth/tracers/logger/gen_structlog.go b/eth/tracers/logger/gen_structlog.go
index 9e71b555c..7818fbe70 100644
--- a/eth/tracers/logger/gen_structlog.go
+++ b/eth/tracers/logger/gen_structlog.go
@@ -30,7 +30,7 @@ func (s StructLog) MarshalJSON() ([]byte, error) {
                RefundCounter uint64                      `json:"refund"`
                Err           error                       `json:"-"`
                OpName        string                      `json:"opName"`
-               ErrorString   string                      `json:"error"`
+               ErrorString   string                      `json:"error,omitempty"`
        }
        var enc StructLog
        enc.Pc = s.Pc
diff --git a/eth/tracers/logger/logger.go b/eth/tracers/logger/logger.go
index 846193582..444a665d6 100644
--- a/eth/tracers/logger/logger.go
+++ b/eth/tracers/logger/logger.go
@@ -82,8 +82,8 @@ type structLogMarshaling struct {
        GasCost     math.HexOrDecimal64
        Memory      hexutil.Bytes
        ReturnData  hexutil.Bytes
-       OpName      string `json:"opName"` // adds call to OpName() in MarshalJSON
-       ErrorString string `json:"error"`  // adds call to ErrorString() in MarshalJSON
+       OpName      string `json:"opName"`          // adds call to OpName() in MarshalJSON
+       ErrorString string `json:"error,omitempty"` // adds call to ErrorString() in MarshalJSON
 }

 // OpName formats the operand name in a human-readable format.

odeke-em added a commit to orijtech/go-ethereum that referenced this issue Mar 2, 2022
…oat from blank fields

Noticed while debugging Tharsis/EVMOS logs that the logs were
extraneous with empty fields such as
```json
{"pc":4716,"op":80,"gas":"0x688e5","gasCost":"0x2","memory":"0x","memSize":352,"stack":["0xfa31de01","0x29a","0x7d0","0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd","0x80","0x534","0xc0","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7","0x15dc","0x34","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7"],"returnData":"0x","depth":2,"refund":0,"opName":"POP","error":""}
{"pc":4717,"op":80,"gas":"0x688e3","gasCost":"0x2","memory":"0x","memSize":352,"stack":["0xfa31de01","0x29a","0x7d0","0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd","0x80","0x534","0xc0","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7","0x15dc","0x34"],"returnData":"0x","depth":2,"refund":0,"opName":"POP","error":""}
```

with empty fields like "error", "refund", "memory", "returnData".

This change adds the JSON tag ",omitempty" to remove the bloat from the
above empty fields which shows immediate impact of reducing the logs to

```json
{"pc":4716,"op":80,"gas":"0x688e5","gasCost":"0x2","memSize":352,"stack":["0xfa31de01","0x29a","0x7d0","0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd","0x80","0x534","0xc0","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7","0x15dc","0x34","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7"],"depth":2,"opName":"POP"}
{"pc":4717,"op":80,"gas":"0x688e3","gasCost":"0x2","memSize":352,"stack":["0xfa31de01","0x29a","0x7d0","0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd","0x80","0x534","0xc0","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7","0x15dc","0x34"],"depth":2,"opName":"POP"}
```

and not only does that reduce the size of logs but it also makes it much
easier to quickly debug and grep for errors, which will only be present if
erroring.

Fixes ethereum#24487
@ligi ligi removed the status:triage label Mar 8, 2022
holiman pushed a commit to holiman/go-ethereum that referenced this issue Mar 16, 2022
…oat from blank fields

Noticed while debugging Tharsis/EVMOS logs that the logs were
extraneous with empty fields such as
```json
{"pc":4716,"op":80,"gas":"0x688e5","gasCost":"0x2","memory":"0x","memSize":352,"stack":["0xfa31de01","0x29a","0x7d0","0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd","0x80","0x534","0xc0","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7","0x15dc","0x34","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7"],"returnData":"0x","depth":2,"refund":0,"opName":"POP","error":""}
{"pc":4717,"op":80,"gas":"0x688e3","gasCost":"0x2","memory":"0x","memSize":352,"stack":["0xfa31de01","0x29a","0x7d0","0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd","0x80","0x534","0xc0","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7","0x15dc","0x34"],"returnData":"0x","depth":2,"refund":0,"opName":"POP","error":""}
```

with empty fields like "error", "refund", "memory", "returnData".

This change adds the JSON tag ",omitempty" to remove the bloat from the
above empty fields which shows immediate impact of reducing the logs to

```json
{"pc":4716,"op":80,"gas":"0x688e5","gasCost":"0x2","memSize":352,"stack":["0xfa31de01","0x29a","0x7d0","0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd","0x80","0x534","0xc0","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7","0x15dc","0x34","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7"],"depth":2,"opName":"POP"}
{"pc":4717,"op":80,"gas":"0x688e3","gasCost":"0x2","memSize":352,"stack":["0xfa31de01","0x29a","0x7d0","0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd","0x80","0x534","0xc0","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7","0x15dc","0x34"],"depth":2,"opName":"POP"}
```

and not only does that reduce the size of logs but it also makes it much
easier to quickly debug and grep for errors, which will only be present if
erroring.

Fixes ethereum#24487
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants