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(ethapi): make eth_getTransactionReceipt null for unexecuted/unknown transactions #1006

Merged
merged 7 commits into from
Jul 22, 2024

Conversation

cryptoAtwill
Copy link
Contributor

This one addresses #1003.

From the issue above, it seems the txn hash is found but the block information is not found. This could be the latest block is not yet confirmed. This PR checks if block header is found when txn hash is present, it will return None. Else if the block header is found but block data is not found, it will throw an error.

Copy link
Contributor

@raulk raulk left a comment

Choose a reason for hiding this comment

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

Is there a test you can augment with these scenarios?

} else {
Ok(None)
error(ExitCode::USR_ILLEGAL_ARGUMENT, "incompatible transaction")
Copy link
Contributor

Choose a reason for hiding this comment

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

When can this happen? When the transaction we requested was a system transaction? Eg top-down finality?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do those not have a receipt we can return?

Copy link
Contributor

Choose a reason for hiding this comment

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

It sounds reasonable for an app to find this tx in an explorer or via the block API, then request its receipt. Not returning it breaks assumptions, but returning an error will cause breakage, I'm sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The other kind of message is IPC mesage, which I believe the receipts are not handled like signed txns, we might not get a proper txn receipt. Or we can just return None regardless of whatever error and just log these error using metrics

)
.await
.context("failed to convert to receipt")?;
let Some(res) = data.tx_by_hash(tx_hash).await? else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we call this var tx?

@cryptoAtwill cryptoAtwill requested a review from raulk May 24, 2024 09:17
@raulk raulk changed the title eth_getTransactionReceipt returns null for unexecuted transactions fix(ethapi): make eth_getTransactionReceipt null for unexecuted/unknown transactions Jul 22, 2024
Copy link
Contributor

@raulk raulk left a comment

Choose a reason for hiding this comment

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

@cryptoAtwill We don't seem to have structured integration tests for the Eth API, so covering this in a test case is a non-starter for now. Did you successfully test this manually?

@raulk
Copy link
Contributor

raulk commented Jul 22, 2024

Pending test results from @cryptoAtwill.

@cryptoAtwill
Copy link
Contributor Author

I have tested this using:

RPC_URL="http://localhost:8545"
txn_hash=$(cast send --rpc-url ${RPC_URL} --private-key <PRIVATE_KEY> --value 1gwei <ADDRESS> --async)
echo "${txn_hash}"

curl ${RPC_URL} \
  -X POST \
  -H "Content-Type: application/json" \
  --data "{\"method\":\"eth_getTransactionReceipt\",\"params\":[\"${txn_hash}\"],\"id\":1,\"jsonrpc\":\"2.0\"}"

The result I got: {"jsonrpc":"2.0","result":null,"id":1}. I think it will only be triggered under certain race condition, this PR should not have caused extra errors.

@raulk raulk merged commit 5990fc0 into main Jul 22, 2024
17 checks passed
@raulk raulk deleted the fix-1003 branch July 22, 2024 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants