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
39 changes: 39 additions & 0 deletions evmrpc/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,45 @@
}
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

// Get the block
height := int64(receipt.BlockNumber)
block, err := blockByNumberWithRetry(ctx, t.tmClient, &height, 1)
if err != nil {
return nil, err
}

// Find the transaction in the block
for _, tx := range block.Block.Txs {
etx := getEthTxForTxBz(tx, t.txConfig.TxDecoder())
if etx != nil && etx.Hash() == hash {
// Get the signer
signer := ethtypes.MakeSigner(
types.DefaultChainConfig().EthereumConfig(t.keeper.ChainID(sdkctx)),
big.NewInt(height),
uint64(block.Block.Time.Unix()),
)
from, _ := ethtypes.Sender(signer, etx)

// Update receipt with correct information
receipt.From = from.Hex()
if etx.To() != nil {
receipt.To = etx.To().Hex()
receipt.ContractAddress = ""
} else {
receipt.To = ""
// For contract creation transactions, calculate the contract address
receipt.ContractAddress = crypto.CreateAddress(from, etx.Nonce()).Hex()
}
receipt.TxType = uint32(etx.Type())
receipt.GasUsed = etx.Gas()
receipt.Status = uint32(ethtypes.ReceiptStatusFailed)

break

Check warning on line 91 in evmrpc/tx.go

View check run for this annotation

Codecov / codecov/patch

evmrpc/tx.go#L66-L91

Added lines #L66 - L91 were not covered by tests
}
}
}
height := int64(receipt.BlockNumber)
block, err := blockByNumberWithRetry(ctx, t.tmClient, &height, 1)
if err != nil {
Expand Down
Loading