Skip to content

fix legacy structLog JSON encoding#5031

Merged
Frozen merged 1 commit intodevfrom
improve/tracer_json
Apr 14, 2026
Merged

fix legacy structLog JSON encoding#5031
Frozen merged 1 commit intodevfrom
improve/tracer_json

Conversation

@GheisMohammadi
Copy link
Copy Markdown
Collaborator

This PR makes error field truly optional in tracer logger. StructLogRes.Error was a string. Even when there was no error, JSON had "error": "". After changes, It’s a *string with omitempty, and we only set it when there is a real error message. Many tracers/INDEXERS/specs expect the field to be absent when no error occurs, not present with "". This fixes schema/decoder issues and false “error” detections.
Current memory was chunked into 32‑byte slices and encoded with fmt.Sprintf("%x", slice). A partial word (e.g. 2 bytes) gave "0xaabb" instead of a 32‑byte (64‑hex‑char) word. After changes each memory chunk is:

  • Cut into up to 32 bytes,
  • Zero‑padded to 32 bytes,
  • Hex‑encoded via hexutil.Bytes(word).String() → 0x + 64 hex chars.
    Tools that assume 32‑byte, zero‑padded, 0x‑prefixed words (as in Geth) no longer break or misinterpret short words at the end of memory.

Also, the PR helps the storage and return data hex encoding is now consistent. In current code:
Storage keys/values were fmt.Sprintf("%x", hash) → no 0x prefix, inconsistent with most Ethereum JSON APIs.
ExecutionResult.ReturnValue was a plain hex string and manually blanked out on failure.
But the PR changes it to:

  • Storage uses hash.Hex() for both key and value → consistent 0x‑prefixed hex.
  • ReturnValue is hexutil.Bytes, and we zero the underlying bytes on hard failure.

So, now debuggers and explorers that expect standard 0x‑prefixed hex (like the Execution APIs / Geth) can work with your traces without custom handling.

The PR fixes debug_traceTransaction style output’s JSON shape and hex formats now match what existing Ethereum tooling already knows how to parse.

Note: the same changes on Ethereum can be found on PR#34093

@GheisMohammadi GheisMohammadi self-assigned this Mar 31, 2026
@GheisMohammadi GheisMohammadi added the core Core Protocol label Mar 31, 2026
@GheisMohammadi GheisMohammadi requested review from Frozen and mur-me March 31, 2026 11:08
@GheisMohammadi GheisMohammadi marked this pull request as draft April 6, 2026 20:48
@mur-me
Copy link
Copy Markdown
Collaborator

mur-me commented Apr 9, 2026

@mur-me - check the failed rpc tests, fix should be simple, see the golang tests from this PR

@mur-me mur-me marked this pull request as ready for review April 14, 2026 16:11
@Frozen Frozen merged commit 252b46d into dev Apr 14, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core Protocol

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants