Skip to content

feat(debug): add enableReturnData param and returnData field #10172

Merged
macfarla merged 13 commits into
besu-eth:mainfrom
sagarkhandagre998:issue-10115
May 8, 2026
Merged

feat(debug): add enableReturnData param and returnData field #10172
macfarla merged 13 commits into
besu-eth:mainfrom
sagarkhandagre998:issue-10115

Conversation

@sagarkhandagre998
Copy link
Copy Markdown
Contributor

@sagarkhandagre998 sagarkhandagre998 commented Apr 3, 2026

PR description

Add enableReturnData param and returnData field

Part of aligning Besu's debug RPC endpoints with the execution-apis spec.

What changed:

  • TransactionTraceParams — new optional enableReturnData boolean param (default false)
  • DebugOperationTracer — captures frame.getReturnData() per opcode when enabled
  • TraceFrame — carries the captured return data buffer through the trace pipeline
  • StructLog — serializes returnData as a hex string; field is omitted from JSON when not enabled

Behaviour:

  • When enableReturnData: false (default) — no change to existing responses
  • When enableReturnData: true — each StructLog entry includes a returnData field containing the EVM return data buffer (populated after CALL/CREATE/etc.) as a 0x-prefixed hex string

Fixed Issue(s)

Refs #10115

Thanks for sending a pull request! Have you done the following?

  • Checked out our contribution guidelines?
  • Considered documentation and added the doc-change-required label to this PR if updates are required.
  • Considered the changelog and included an update if required.
  • For database changes (e.g. KeyValueSegmentIdentifier) considered compatibility and performed forwards and backwards compatibility tests

Locally, you can run these tests to catch failures early:

  • spotless: ./gradlew spotlessApply
  • unit tests: ./gradlew build
  • acceptance tests: ./gradlew acceptanceTest
  • integration tests: ./gradlew integrationTest
  • reference tests: ./gradlew ethereum:referenceTests:referenceTests
  • hive tests: Engine or other RPCs modified?

@sagarkhandagre998
Copy link
Copy Markdown
Contributor Author

@macfarla Kindly take a look at once.

@parthdagia05
Copy link
Copy Markdown
Contributor

parthdagia05 commented Apr 10, 2026

This PR doesn't include any unit tests. Would be good to add at least: a test that returnData is captured or absent.
Just want to check when TraceFrame.from(lastTraceFrame) is used in DebugOperationTracer to backfill gasRemainingPostExecution, it copies all fields from the old frame into a new one. Is the new returnData field included in that copy?
@sagarkhandagre998

Comment thread evm/src/main/java/org/hyperledger/besu/evm/tracing/TraceFrame.java
@sagarkhandagre998
Copy link
Copy Markdown
Contributor Author

This PR doesn't include any unit tests. Would be good to add at least: a test that returnData is captured or absent. Just want to check when TraceFrame.from(lastTraceFrame) is used in DebugOperationTracer to backfill gasRemainingPostExecution, it copies all fields from the old frame into a new one. Is the new returnData field included in that copy? @sagarkhandagre998

Thanks @parthdagia05 for the review.
I think we need tests by following the priority.

Test file What's missing Priority
DebugOperationTracerTest shouldRecordReturnDataWhenEnabled + shouldNotRecordReturnDataWhenDisabled High
StructLogTest returnData field serialized/absent in JSON, value mapping Medium
TransactionTraceParamsTest enableReturnData deserialization + default false Low

@parthdagia05
Copy link
Copy Markdown
Contributor

@sagarkhandagre998
A few things still missing in StructLog.java:

@JsonPropertyOrder needs returnData without it, Jackson serializes the field at an arbitrary position, breaking spec-expected ordering:

@JsonPropertyOrder({"pc", "op", "gas", "gasCost", "depth", "refund", "stack", "memory", "returnData", "storage"})
equals() and hashCode() need updating the new returnData field isn't included in either method, so two StructLog objects differing only by returnData would incorrectly be considered equal.

@sagarkhandagre998
Copy link
Copy Markdown
Contributor Author

@sagarkhandagre998 A few things still missing in StructLog.java:

@JsonPropertyOrder needs returnData without it, Jackson serializes the field at an arbitrary position, breaking spec-expected ordering:

@JsonPropertyOrder({"pc", "op", "gas", "gasCost", "depth", "refund", "stack", "memory", "returnData", "storage"}) equals() and hashCode() need updating the new returnData field isn't included in either method, so two StructLog objects differing only by returnData would incorrectly be considered equal.

equals() and hashCode() on StructLog are only used for test assertions, not in any production logic. The fields included — pc, op, gas, gasCost, depth, memory, stack, storage — represent the EVM execution state at the point of tracing. reason was deliberately left out of both methods for the same reason returnData is: they are conditional output fields populated only on specific opcodes, not part of the core state being compared. Adding returnData here would be inconsistent. The @JsonPropertyOrder fix is valid though — will fix that.

@jframe is this correct behavior ?

@sagarkhandagre998 sagarkhandagre998 force-pushed the issue-10115 branch 2 times, most recently from 03b7e20 to 32b2fa6 Compare April 11, 2026 13:15
Copy link
Copy Markdown
Contributor

@macfarla macfarla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some comments, please take a look

@macfarla macfarla marked this pull request as draft April 21, 2026 21:29
@sagarkhandagre998 sagarkhandagre998 force-pushed the issue-10115 branch 3 times, most recently from b7e5253 to f286618 Compare April 22, 2026 06:12
@sagarkhandagre998
Copy link
Copy Markdown
Contributor Author

@macfarla Kindly take a look

@sagarkhandagre998 sagarkhandagre998 marked this pull request as ready for review April 22, 2026 06:13
Copy link
Copy Markdown
Contributor

@macfarla macfarla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prob worth a changelog entry

Comment thread evm/src/main/java/org/hyperledger/besu/evm/tracing/TraceFrame.java
@sagarkhandagre998 sagarkhandagre998 force-pushed the issue-10115 branch 2 times, most recently from 6a0baf0 to f4c7489 Compare April 29, 2026 16:28
@sagarkhandagre998
Copy link
Copy Markdown
Contributor Author

@macfarla All Done , Please take a look.

Copy link
Copy Markdown
Contributor

@macfarla macfarla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sagarkhandagre998 spotless check is failing. before you ask for review, run gradlew build locally and ensure code builds and passes tests. reviewer's time is precious and limited.

@macfarla
Copy link
Copy Markdown
Contributor

macfarla commented May 7, 2026

@sagarkhandagre998 can you merge latest main and resolve conflicts

@sagarkhandagre998
Copy link
Copy Markdown
Contributor Author

sagarkhandagre998 commented May 7, 2026

@sagarkhandagre998 can you merge latest main and resolve conflicts

@macfarla Done.

@macfarla macfarla self-assigned this May 8, 2026
@macfarla
Copy link
Copy Markdown
Contributor

macfarla commented May 8, 2026

@sagarkhandagre998 I'm going to run the checks but you'll also need to resolve conflicts in changelog

Signed-off-by: Sagar Khandagre <sagar.khandagre998@gmail.com>
Signed-off-by: Sagar Khandagre <sagar.khandagre998@gmail.com>
Signed-off-by: Sagar Khandagre <sagar.khandagre998@gmail.com>
Signed-off-by: Sagar Khandagre <sagar.khandagre998@gmail.com>
…nsures empty return buffer is omitted even when traceReturnData is enabled

Signed-off-by: Sagar Khandagre <sagar.khandagre998@gmail.com>
…tests.

Signed-off-by: Sagar Khandagre <sagar.khandagre998@gmail.com>
Signed-off-by: Sagar Khandagre <sagar.khandagre998@gmail.com>
Signed-off-by: Sagar Khandagre <sagar.khandagre998@gmail.com>
Signed-off-by: Sagar Khandagre <sagar.khandagre998@gmail.com>
Signed-off-by: Sagar Khandagre <sagar.khandagre998@gmail.com>
Signed-off-by: Sagar Khandagre <sagar.khandagre998@gmail.com>
Signed-off-by: Sagar Khandagre <sagar.khandagre998@gmail.com>
@sagarkhandagre998
Copy link
Copy Markdown
Contributor Author

@sagarkhandagre998 I'm going to run the checks but you'll also need to resolve conflicts in changelog

@macfarla we can run the checks

@macfarla macfarla added the doc-change-required Indicates an issue or PR that requires doc to be updated label May 8, 2026
@macfarla macfarla merged commit fbbd79e into besu-eth:main May 8, 2026
34 checks passed
abhay-dev2901 pushed a commit to abhay-dev2901/besu that referenced this pull request May 14, 2026
…h#10172)

* implements test by priority

Signed-off-by: Sagar Khandagre <sagar.khandagre998@gmail.com>

* add returnData field in the correct order - EIP-3155

Signed-off-by: Sagar Khandagre <sagar.khandagre998@gmail.com>

* applying a targeted fix in captureReturnData and adding a test that ensures empty return buffer is omitted even when traceReturnData is enabled

Signed-off-by: Sagar Khandagre <sagar.khandagre998@gmail.com>

---------

Signed-off-by: Sagar Khandagre <sagar.khandagre998@gmail.com>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
Signed-off-by: abhay-dev2901 <abhaytp1998@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-change-required Indicates an issue or PR that requires doc to be updated

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants