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

Implement eth_subscribe newHeads #16318

Merged
merged 2 commits into from
Dec 12, 2022
Merged

Implement eth_subscribe newHeads #16318

merged 2 commits into from
Dec 12, 2022

Conversation

bbondy
Copy link
Member

@bbondy bbondy commented Dec 9, 2022

This adds support for a new eth_subscribe method that can be used in Ethereum provider requests.
See a description of this here: https://docs.infura.io/infura/networks/ethereum/json-rpc-methods/subscription-methods/eth_subscribe

This implementation only supports newHeads for now.
There's a follow up issue in brave/brave-browser#27283 for supporting the "logs" param.
These params are not currently supported by MM at the time of this writing, so they are probably not used in the wild and we can sit on the implementation for now: "newPendingTransactions" and "syncing"".

As an alternative to this implementation, I considered first adding websocket support and then using Infura, but then eth_subscribe wouldn't be supported for user's HTTPS configured RPC endpoints. So I'm starting here with querying for block updates via the block tracker.

If approved I will do another pull request for wallet-docs.

Resolves brave/brave-browser#21350

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run lint, npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

  • Clone https://github.com/bbondy/eth-manual-tests and start a server as per the readme
  • Use eth_subscribe to listen for new block head. You should see a console message in the developer console matching the same subscription ID every 20 seconds. You can subscribe multiple times, each time will give a new subscription ID.
  • Use eth_unsubscribe to stop listening to an event by putting the subscription ID from the eth_subscribe call. It should stop ending events and return true to the console when you unsubscribe successfully from something.

@bbondy bbondy marked this pull request as ready for review December 9, 2022 21:06
@bbondy bbondy requested a review from a team as a code owner December 9, 2022 21:06
@darkdh
Copy link
Member

darkdh commented Dec 9, 2022

Can we also update https://github.com/bbondy/eth-manual-tests and add test plan for QA using it?

@bbondy bbondy requested a review from darkdh December 10, 2022 21:06
I considered first adding websocket support and then using Infura, but
then eth_subscribe wouldn't be supported for user's HTTPS configured RPC
endpoints.  So I'm starting here with querying for block updates via the
block tracker.

.
@bbondy
Copy link
Member Author

bbondy commented Dec 12, 2022

Can we also update https://github.com/bbondy/eth-manual-tests and add test plan for QA using it?

Yep, I'll do that today.

@bbondy
Copy link
Member Author

bbondy commented Dec 12, 2022

Can we also update https://github.com/bbondy/eth-manual-tests and add test plan for QA using it?

Yep, I'll do that today.

Added the test plan above and made a pull request for that here: bbondy/eth-manual-tests#5

@bbondy
Copy link
Member Author

bbondy commented Dec 12, 2022

Brave Wallet docs PR: brave/brave-wallet-docs#84

@bbondy
Copy link
Member Author

bbondy commented Dec 12, 2022

eth_unsubscribe PR for eth-manual-tests bbondy/eth-manual-tests#6

@bbondy bbondy merged commit c943d8d into master Dec 12, 2022
@bbondy bbondy deleted the eth_subscribe branch December 12, 2022 17:03
@bbondy bbondy added this to the 1.48.x - Nightly milestone Dec 12, 2022
@yrliou yrliou mentioned this pull request Dec 12, 2022
25 tasks
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.

Support the eth_subscribe method with the "newHeads" param
2 participants