Skip to content

fix(jsonrpc): reuse receipts for transaction values - #7147

Closed
0xbigapple wants to merge 1 commit into
tronprotocol:release_v4.8.3from
0xbigapple:fix/jsonrpc-reuse-block-receipts
Closed

0xbigapple wants to merge 1 commit into
tronprotocol:release_v4.8.3from
0xbigapple:fix/jsonrpc-reuse-block-receipts

Conversation

@0xbigapple

Copy link
Copy Markdown
Collaborator

What does this PR do?

Reuse the transaction receipts already loaded by JSON-RPC block and transaction queries to populate gas and value.

  1. For eth_getBlockByNumber and eth_getBlockByHash with fullTx=true, pass each transaction's receipt from BlockResult to TransactionResult. When the receipt and transaction counts match, use the receipt at the same index. Otherwise, use an empty receipt for each transaction in the full response.
  2. For eth_getTransactionByHash, eth_getTransactionByBlockHashAndIndex, and eth_getTransactionByBlockNumberAndIndex, use the same receipt for both fields. If the transaction exists but its receipt is missing, the five receipt-dependent transaction types return "0x0" for both fields.

Why are these changes required?

The five affected types are UnfreezeBalanceContract, UnfreezeBalanceV2Contract, WithdrawBalanceContract, WithdrawExpireUnfreezeContract, and CancelAllUnfreezeV2Contract. Their reported value comes from the execution receipt.

Previously, after loading the block's receipts, the formatter looked up each affected transaction again by ID. With receipts stored in TransactionRetStore, each lookup read and decoded the entire block's receipts to find one transaction. A full block query containing five affected transactions therefore decoded the same receipt record six times. It now decodes it once.

This PR has been tested by:

  • Unit Tests
  • Manual Testing

Follow up

Extra details

Reuse the block receipt list when formatting full transaction objects.
Read the value of withdrawal and unfreeze transactions from their
receipts and use zero when the block receipt list is unavailable.

Pass the receipt from single-transaction queries to TransactionResult
so gas and value share one lookup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant