Skip to content

Refactor transaction result types to align with execution-apis spec#10113

Merged
fab-10 merged 1 commit into
besu-eth:mainfrom
fab-10:refactor-transaction-result-types
Mar 30, 2026
Merged

Refactor transaction result types to align with execution-apis spec#10113
fab-10 merged 1 commit into
besu-eth:mainfrom
fab-10:refactor-transaction-result-types

Conversation

@fab-10
Copy link
Copy Markdown
Contributor

@fab-10 fab-10 commented Mar 26, 2026

Summary

During the development of #10111, I found that TransactionPendingResult was missing new fields related to EIP-7702 txs, while they were present in TransactionCompleteResult. This was caused by the duplication across both classes — new fields had to be added in two places and it was easy to miss one.

This PR eliminates that duplication and aligns the class hierarchy with the execution-apis spec:

  • TransactionBaseResult — new base class containing only the fields defined in the spec; block metadata getters return null (correct for pending transactions)
  • TransactionWithMetadataResult — extends TransactionBaseResult, overrides block metadata getters with real values from the mined block (replaces TransactionCompleteResult)
  • TransactionPendingResult — extends TransactionBaseResult, retains only publicKey and raw as Besu-specific extensions (used by txpool_content / txpool_contentFrom)

Changes

  • TransactionBaseResult (new): spec-compliant base class with all transaction fields and getters; gasPrice for EIP-1559/blob transactions is computed as effectiveGasPrice(baseFee) when a base fee is provided, or falls back to maxFeePerGas for pending transactions
  • TransactionWithMetadataResult (new): replaces TransactionCompleteResult; overrides blockHash, blockNumber, blockTimestamp, and transactionIndex
  • TransactionPendingResult: now extends TransactionBaseResult; only retains publicKey and raw fields
  • EthGetTransactionByHash: pending transactions now use TransactionBaseResult directly (no publicKey/raw), aligning with the spec

Behaviour change

eth_getTransactionByHash no longer includes publicKey and raw in the response for pending transactions. These are Besu extensions appropriate for txpool introspection methods (txpool_content, txpool_contentFrom), not for eth_getTransactionByHash.

Test plan

  • Existing EthGetTransactionByHashTest passes
  • TransactionWithMetadataResultTest passes (covers EIP-1559, legacy pre/post London, and access-list transactions)
  • Acceptance test 02_cancun_get_blob_tx.json passes (verifies removal of publicKey/raw from eth_getTransactionByHash for pending blob tx)
  • Verify authorizationList is present in EIP-7702 transaction responses
  • Verify gasPrice is the effective gas price for mined EIP-1559 transactions

🤖 Generated with Claude Code

@fab-10 fab-10 changed the title Refactor TransactionCompleteResult to extend TransactionPendingResult Refactor TransactionCompleteResult to extend TransactionPendingResult Mar 26, 2026
@fab-10 fab-10 added the techdebt maintenance, cleanup, refactoring, documentation label Mar 26, 2026
@fab-10 fab-10 force-pushed the refactor-transaction-result-types branch 3 times, most recently from c7913ad to f724a59 Compare March 27, 2026 10:51
@fab-10 fab-10 changed the title Refactor TransactionCompleteResult to extend TransactionPendingResult Refactor transaction result types to align with execution-apis spec Mar 27, 2026
@fab-10 fab-10 force-pushed the refactor-transaction-result-types branch from f724a59 to ab335f3 Compare March 27, 2026 11:18
@fab-10 fab-10 marked this pull request as ready for review March 27, 2026 12:26
Copilot AI review requested due to automatic review settings March 27, 2026 12:26
Copy link
Copy Markdown
Contributor

@usmansaleem usmansaleem left a comment

Choose a reason for hiding this comment

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

LGTM

Eliminates ~200 lines of duplication by making TransactionCompleteResult
extend TransactionPendingResult instead of re-implementing all transaction
fields. The complete result now only adds blockHash, blockNumber,
blockTimestamp, and transactionIndex on top of the base class.

Additional changes:
- Add EIP-7702 authorizationList to TransactionPendingResult so pending
  code-delegation transactions are correctly represented
- Compute gasPrice as effectiveGasPrice(baseFee) for mined transactions
  instead of returning maxFeePerGas
- Use null-safe Optional.map() for block metadata instead of .get()
- Tighten Optional<Object> to Optional<TransactionPendingResult> in
  EthGetTransactionByHash

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@fab-10 fab-10 force-pushed the refactor-transaction-result-types branch from 2b6582c to 8bf7fb5 Compare March 30, 2026 09:38
@fab-10 fab-10 enabled auto-merge (squash) March 30, 2026 09:38
@fab-10 fab-10 merged commit 588cd45 into besu-eth:main Mar 30, 2026
46 checks passed
@fab-10 fab-10 deleted the refactor-transaction-result-types branch March 30, 2026 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

techdebt maintenance, cleanup, refactoring, documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants