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

Add ability to create RPC service chain #5226

Merged
merged 6 commits into from
Feb 3, 2025
Merged

Add ability to create RPC service chain #5226

merged 6 commits into from
Feb 3, 2025

Conversation

mcmire
Copy link
Contributor

@mcmire mcmire commented Jan 30, 2025

Explanation

We want to update the fetch middleware in eth-json-rpc-middleware and the Infura middleware in eth-json-rpc-infura to automatically fail over to alternate RPC endpoints when the desired endpoint is down. To do this, we need a way to string together a collection of RPC services, where the first service represents the primary endpoint, the second service is the failover for the first, the third service is a failover for the second, etc. This composite object should conform to the same interface as an RPC service so consumers do not have to care whether they are working with a single endpoint or a chain of them.

References

Closes #5222.

Changelog

(Updated in PR.)

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

@mcmire mcmire force-pushed the add-rpc-service-chain branch from 7c711aa to 9a5238f Compare January 30, 2025 23:50
@mcmire
Copy link
Contributor Author

mcmire commented Jan 30, 2025

@metamaskbot publish-previews

Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "22.0.0-preview-9a5238f",
  "@metamask-previews/address-book-controller": "6.0.2-preview-9a5238f",
  "@metamask-previews/announcement-controller": "7.0.2-preview-9a5238f",
  "@metamask-previews/approval-controller": "7.1.2-preview-9a5238f",
  "@metamask-previews/assets-controllers": "47.0.0-preview-9a5238f",
  "@metamask-previews/base-controller": "7.1.1-preview-9a5238f",
  "@metamask-previews/build-utils": "3.0.2-preview-9a5238f",
  "@metamask-previews/composable-controller": "10.0.0-preview-9a5238f",
  "@metamask-previews/controller-utils": "11.4.5-preview-9a5238f",
  "@metamask-previews/ens-controller": "15.0.1-preview-9a5238f",
  "@metamask-previews/eth-json-rpc-provider": "4.1.7-preview-9a5238f",
  "@metamask-previews/gas-fee-controller": "22.0.2-preview-9a5238f",
  "@metamask-previews/json-rpc-engine": "10.0.2-preview-9a5238f",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.6-preview-9a5238f",
  "@metamask-previews/keyring-controller": "19.0.5-preview-9a5238f",
  "@metamask-previews/logging-controller": "6.0.3-preview-9a5238f",
  "@metamask-previews/message-manager": "12.0.0-preview-9a5238f",
  "@metamask-previews/multichain": "2.1.0-preview-9a5238f",
  "@metamask-previews/multichain-transactions-controller": "0.1.0-preview-9a5238f",
  "@metamask-previews/name-controller": "8.0.2-preview-9a5238f",
  "@metamask-previews/network-controller": "22.1.1-preview-9a5238f",
  "@metamask-previews/notification-services-controller": "0.18.0-preview-9a5238f",
  "@metamask-previews/permission-controller": "11.0.5-preview-9a5238f",
  "@metamask-previews/permission-log-controller": "3.0.2-preview-9a5238f",
  "@metamask-previews/phishing-controller": "12.3.1-preview-9a5238f",
  "@metamask-previews/polling-controller": "12.0.2-preview-9a5238f",
  "@metamask-previews/preferences-controller": "15.0.1-preview-9a5238f",
  "@metamask-previews/profile-sync-controller": "5.0.0-preview-9a5238f",
  "@metamask-previews/queued-request-controller": "9.0.0-preview-9a5238f",
  "@metamask-previews/rate-limit-controller": "6.0.2-preview-9a5238f",
  "@metamask-previews/remote-feature-flag-controller": "1.3.0-preview-9a5238f",
  "@metamask-previews/selected-network-controller": "21.0.0-preview-9a5238f",
  "@metamask-previews/signature-controller": "23.2.0-preview-9a5238f",
  "@metamask-previews/token-search-discovery-controller": "1.0.0-preview-9a5238f",
  "@metamask-previews/transaction-controller": "44.0.0-preview-9a5238f",
  "@metamask-previews/user-operation-controller": "23.0.0-preview-9a5238f"
}

Base automatically changed from add-endpoint-url-to-rpc-service-callbacks to main January 31, 2025 18:04
We want to update the `fetch` middleware in `eth-json-rpc-middleware`
and the Infura middleware in `eth-json-rpc-infura` to automatically fail
over to alternate RPC endpoints when the desired endpoint is down. To do
this, we need a way to string together a collection of RPC services,
where the first service represents the primary endpoint, the second
service is failover for the first, the third service is a failover for
the second, etc. This composite object should conform to the same
interface as an RPC service so consumers do not have to care whether
they are working with a single endpoint or a chain of them.

Also expose `AbstractRpcService` so that we can make use of it in the
middleware packages.
@mcmire mcmire force-pushed the add-rpc-service-chain branch from 269b72b to aded418 Compare February 3, 2025 15:38
@mcmire mcmire marked this pull request as ready for review February 3, 2025 15:44
@mcmire mcmire requested review from a team as code owners February 3, 2025 15:44
Co-authored-by: cryptodev-2s <109512101+cryptodev-2s@users.noreply.github.com>
cryptodev-2s
cryptodev-2s previously approved these changes Feb 3, 2025
Copy link
Contributor

@cryptodev-2s cryptodev-2s left a comment

Choose a reason for hiding this comment

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

LGTM! I left some minor suggestions

Co-authored-by: cryptodev-2s <109512101+cryptodev-2s@users.noreply.github.com>
mcmire and others added 2 commits February 3, 2025 13:43
Co-authored-by: cryptodev-2s <109512101+cryptodev-2s@users.noreply.github.com>
@mcmire mcmire merged commit 97958dd into main Feb 3, 2025
127 checks passed
@mcmire mcmire deleted the add-rpc-service-chain branch February 3, 2025 20:49
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.

Add a function to create an RPC service chain
2 participants