Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: complete failed transaction receipts with block data #1952

Merged
merged 10 commits into from
Nov 21, 2024

Conversation

blindchaser
Copy link
Contributor

Describe your changes and provide context

This PR enhances the handling of failed transaction receipts by filling in missing fields using data from the block. When a transaction fails with zero gas usage, the receipt might be missing important information. This PR ensures all receipt fields are properly populated by looking up the transaction in the block.

In GetTransactionReceipt, when a receipt has TxType == 0 and GasUsed == 0, we:

  1. Fetch the block containing the transaction
  2. Find the matching transaction in the block
  3. Update receipt fields with actual transaction data:
    • From address (using transaction signer)
    • To address or contract address
    • Gas used
    • Transaction type
    • Status (set to failed)

Testing performed to validate your change

@blindchaser blindchaser changed the title feat: fill failed tx receipt missing fields with block data fix: complete failed transaction receipts with block data Nov 20, 2024
Copy link

codecov bot commented Nov 20, 2024

Codecov Report

Attention: Patch coverage is 84.37500% with 5 lines in your changes missing coverage. Please review.

Project coverage is 61.69%. Comparing base (cea68db) to head (16fac14).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
evmrpc/tx.go 84.37% 4 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1952      +/-   ##
==========================================
+ Coverage   61.49%   61.69%   +0.20%     
==========================================
  Files         263      263              
  Lines       23394    23425      +31     
==========================================
+ Hits        14387    14453      +66     
+ Misses       8006     7967      -39     
- Partials     1001     1005       +4     
Files with missing lines Coverage Δ
evmrpc/tx.go 67.46% <84.37%> (+2.30%) ⬆️

... and 1 file with indirect coverage changes

---- 🚨 Try these New Features:

@blindchaser blindchaser force-pushed the yiren/v6.0.0-getTransactionReceipt-incomplete branch from 2342a98 to 3ee367a Compare November 20, 2024 21:52
@blindchaser blindchaser force-pushed the yiren/v6.0.0-getTransactionReceipt-incomplete branch from 3ee367a to 92a44bd Compare November 20, 2024 22:49
evmrpc/tx.go Outdated
@@ -53,6 +53,44 @@ func (t *TransactionAPI) GetTransactionReceipt(ctx context.Context, hash common.
}
return nil, err
}
// Fill in the receipt if the transaction has failed and used 0 gas
if receipt.TxType == 0 && receipt.GasUsed == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

should check status instead of txType

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

}
receipt.TxType = uint32(etx.Type())
receipt.Status = uint32(ethtypes.ReceiptStatusFailed)
receipt.GasUsed = 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think you can also fill other fields like input, value, etc. from etc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it looks receipt doesn't have these fields: https://github.com/sei-protocol/sei-chain/blob/main/x/evm/types/receipt.pb.go#L102

i checked some successfully tx receipts, they have logs but it doesn't have input/value either.

evmrpc/tx.go Outdated
Comment on lines 56 to 57
// Fill in the receipt if the transaction has failed and used 0 gas
if receipt.Status == 0 && receipt.GasUsed == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a comment here saying that this case is for when a tx fails before it makes it to the VM?

@philipsu522 philipsu522 merged commit 9432bee into main Nov 21, 2024
49 checks passed
@philipsu522 philipsu522 deleted the yiren/v6.0.0-getTransactionReceipt-incomplete branch November 21, 2024 19:04
philipsu522 pushed a commit that referenced this pull request Nov 21, 2024
* feat: fill failed tx receipt missing fields with block data

* improve logic

* set gasUsed=0

* debug: gasUsed

* remove log

* fix status check

* unit test

* update comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants