-
Notifications
You must be signed in to change notification settings - Fork 21.4k
eth/filters: add transactionReceipts
subscription
#32697
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
Conversation
Hey thanks for this, I think it's a fair request. I will have a look |
Hi @s1na, hope you're doing well. When you have a chance, could you take a look at this PR? Any feedback would be great. Thanks! |
Pushed a commit to avoid an extra db read of the receipts in SetCanonical |
You're very thorough, thank you for the commit. |
Hi @s1na, just following up to see if you have any additional feedback on this PR? Happy to make any other changes if needed. |
Hi @s1na, I noticed a PR for EIP-7966 (eth_sendRawTransactionSync Method) is ready. I found that its implementation could be optimized after this PR is merged: |
// TransactionReceiptsFilter defines criteria for transaction receipts subscription. | ||
// If TransactionHashes is nil or empty, receipts for all transactions included in new blocks will be delivered. | ||
// Otherwise, only receipts for the specified transactions will be delivered. | ||
type TransactionReceiptsFilter struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why you made this a structure instead of taking []common.Hash as the parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @s1na, thanks for asking! I used a struct mainly for two reasons:
- Self-documenting API
Having named fields like{"transactionHashes": [...]}
makes the API more readable and self-explanatory compared to a bare array. - Future extensibility
A struct makes it easier to add new filter options in the future (e.g.,from
,to
, or other filters) without breaking backward compatibility.
Yes that's a good point! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good PR, thanks!
transactionReceipts
for receipts notificationtransactionReceipts
subscription
I just realized, we didn't add this to ethclient. Let me know if you'd like to open a PR for that. |
Thanks for pointing that out. The PR is ready: #32869. |
Add `SubscribeTransactionReceipts` for ethclient. This is a complement to #32697.
- Introduce a new subscription kind `transactionReceipts` to allow clients to receive transaction receipts over WebSocket as soon as they are available. - Accept optional `transactionHashes` filter to subscribe to receipts for specific transactions; an empty or omitted filter subscribes to all receipts. - Preserve the same receipt format as returned by `eth_getTransactionReceipt`. - Avoid additional HTTP polling, reducing RPC load and latency. --------- Co-authored-by: Sina Mahmoodi <itz.s1na@gmail.com>
Add `SubscribeTransactionReceipts` for ethclient. This is a complement to ethereum#32697.
Currently, we can get transaction receipts from the HTTP API eth_getTransactionReceipt. In this PR, I add support for getting transaction receipts from the WebSocket API: Add a new subscription_name:
transactionReceipts
, which accepts an optional transaction hashes filter.Why is this PR valuable?
Usage:
Subscribe to a transaction receipt by transaction hash (multiple transaction hashes are also supported):
Subscribe to all transaction receipts:
As mentioned in the above example, filtering is not performed when no second parameter is provided. The following describes three additional special cases where no filtering is performed:
transactionHashes
field in the second parameter is set tonull
;transactionHashes
field in the second parameter is set to[]
(empty array);{}
(empty object).All of the above are treated as subscribing to all transaction receipts:
I noticed that all HTTP APIs have been standardized in the execution-apis project, but WebSocket APIs are not included in that project. In this PR, I only enhance the WebSocket API - no HTTP APIs are changed.