erigontech / erigon

Ethereum implementation on the efficiency frontier https://erigon.gitbook.io
GNU Lesser General Public License v3.0
3.14k stars 1.12k forks source link

Type of `error` field in structlog logger differs from geth, alloy #12085

Closed einar-polygon closed 1 month ago

einar-polygon commented 1 month ago

System information

Commit hash: c293883ec039ebcc9bb7bbe85807cabee828b4bc

Expected behaviour

The field error should probably be logged as a string to be compatible with Geth, Alloy.

Actual behaviour

The field error is logged as an object containing a string.

Steps to reproduce the behaviour

I don't know of a tx_id on a public chain, whose logs contains the error field, but here is the command I used to confirm this issue:

curl $RPC \                                                                                        
-X POST \
-H "Content-Type: application/json" \
--data '{"method":"debug_traceTransaction","params":[tx_id, {"disableStack": true, "disableMemory": true, "disableStorage": true} ], "id":1,"jsonrpc":"2.0"}'  | jq | rg "error" -C 16

Source

https://github.com/erigontech/erigon/blob/c293883ec039ebcc9bb7bbe85807cabee828b4bc/eth/tracers/logger/json_stream.go#L128-L131

Suggested fix

diff --git a/eth/tracers/logger/json_stream.go b/eth/tracers/logger/json_stream.go
index 5b616e81e7..60b8443b65 100644
--- a/eth/tracers/logger/json_stream.go
+++ b/eth/tracers/logger/json_stream.go
@@ -127,9 +127,9 @@ func (l *JsonStreamLogger) CaptureState(pc uint64, op vm.OpCode, gas, cost uint6
        if err != nil {
                l.stream.WriteMore()
                l.stream.WriteObjectField("error")
-               l.stream.WriteObjectStart()
-               l.stream.WriteObjectEnd()
-               //l.stream.WriteString(err.Error())
+               // l.stream.WriteObjectStart()
+               // l.stream.WriteObjectEnd()
+               l.stream.WriteString(err.Error())
        }
        if !l.cfg.DisableStack {
                l.stream.WriteMore()
AskAlexSharov commented 1 month ago

tnx. pr: https://github.com/erigontech/erigon/pull/12089

einar-polygon commented 1 month ago

@AlexeyAkhunov seems to be the original committer of those lines so tagging him. Perhaps he knows something I don't about why the line was already there, but commented out (//l.stream.WriteString(err.Error())).