feat: Auto-failover to Quicknode when Infura is down#14139
Conversation
When Infura goes down, we want to automatically and invisibly redirect requests from Infura RPC endpoints to Quicknode endpoints. - There is not one central Quicknode RPC endpoint that all Infura requests will be forwarded to; rather, each Infura-supported chain gets its own Quicknode endpoint. These URLs contain an API key, so we need to add an environment variable for each endpoint. - All of the Infura RPC endpoints that have an associated Quicknode endpoint are: - Ethereum Mainnet - Linea Mainnet - Arbitrum Mainnet - Avalanche - Optimism (OP) Mainnet - Polygon Mainnet - Base Mainnet - The failover behavior itself is already present in `@metamask/network-controller`, where a new `failoverRpcUrls` property has been added to the `RpcEndpoint` type. This commit bumps `@metamask/network-controller` to bring in those changes, and then it not only adds a migration to go through each RPC endpoint in NetworkController state and populate the `failoverRpcUrls` property, it also updates the code responsible for the "additional networks" feature to ensure that Infura RPC endpoints get added with `failoverRpcUrls` set correctly. In addition, any other place that is responsible for adding a network, we need to make sure we pass `failoverRpcUrls` as an empty array (since it's a required configuration property). - Finally, this commit adds some minimal UI to allow users to see that Infura endpoints have a failover URL assigned. Since all of the Quicknode URLs are long, this ends up getting cut off, but that doesn't matter.
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
|
|
app/component-library/components/Cells/Cell/foundation/CellBase/CellBase.types.ts
Show resolved
Hide resolved
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #14139 +/- ##
==========================================
+ Coverage 66.29% 66.62% +0.32%
==========================================
Files 2248 2263 +15
Lines 48037 48397 +360
Branches 6766 6853 +87
==========================================
+ Hits 31848 32246 +398
+ Misses 14172 14115 -57
- Partials 2017 2036 +19 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
jiexi
left a comment
There was a problem hiding this comment.
approving for wallet_addEthereumChain handler changes
|
Ramp changes LGTM 🚀 |
…14408) <!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> These upgrades support the RPC failover and MegaETH initiatives. The patch for `network-controller` is no longer needed because the changes there have been integrated into `network-controller`. ## **Related issues** Unblocks #14139, and other initiatives. ## **Manual testing steps** This PR should have no functional changes, everything should work the same way. 1. Check out this branch and go through the setup steps to load the app onto your device or emulator. 2. Create an account if necessary. 3. Open the wallet to go the home screen. You should see no errors in your local console. 4. Try to switch the network. You should see no errors. 5. Try to send a transaction. You should see no errors. 6. Open the browser, go to `docs.metamask.io`, tap the hamburger menu, go to Wallet API, tap the menu again, go to JSON-RPC API, tap the menu again, go to `wallet_addEthereumChain`. 7. Click on "Connect MetaMask". 8. Scroll down and run the request (which should add Gnosis). Accept the approval. 9. You should get a modal saying that Gnosis has been switched to. You should not see any errors in your local terminal. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> (No screenshots/recordings, as everything should work the same way.) ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.



Description
When Infura goes down, we want to automatically and invisibly redirect requests from Infura RPC endpoints to Quicknode endpoints.
@metamask/network-controller, where a newfailoverRpcUrlsproperty has been added to theRpcEndpointtype. This commit bumps@metamask/network-controllerto bring in those changes, and then it not only adds a migration to go through each RPC endpoint in NetworkController state and populate thefailoverRpcUrlsproperty, it also updates the code responsible for the "additional networks" feature to ensure that Infura RPC endpoints get added withfailoverRpcUrlsset correctly. In addition, any other place that is responsible for adding a network, we need to make sure we passfailoverRpcUrlsas an empty array (since it's a required configuration property).Related issues
Fixes #14120.
Manual testing steps
There are 7 environment variables that you need to have set in
.js.envbefore you begin. Please contact me in Slack and I will give them to you.Testing the UI changes
yarn setup/yarn setup:expoand then runyarn watch.mainnet.infura.iodocs.metamask.io, tap the hamburger menu, go to Wallet API, tap the menu again, go to JSON-RPC API, tap the menu again, go towallet_addEthereumChain.Testing the failover logic
app/core/Engine/Engine.ts. Look forconst networkControllerOpts =and make the following changes:const networkControllerOpts = { infuraProjectId: process.env.MM_INFURA_PROJECT_ID || NON_EMPTY, state: initialNetworkControllerState, messenger: networkControllerMessenger, getRpcServiceOptions: () => ({ fetch, btoa, + policyOptions: { + maxRetries: 1, + maxConsecutiveFailures: 10, + circuitBreakDuration: 10000, + }, }), };node_modules/@metamask/network-controller/dist/rpc-service/rpc-service.cjs.exports.RpcService = RpcService. Make the following changes:=== Fetching.=== Fetching <URL> ===messages where it's an Infura URL, followed by the error we just created ("Infura is down").=== Fetching <URL> ===messages where instead of an Infura URL, it's a Quicknode URL (https://<descriptive-random-string>.quicknode.pro/<api-key>). You have to look closely, because right after that you will still continue to see the "Infura is down" message.Screenshots/Recordings
Before
After
This is what it now looks like when editing an Infura network:
This is what it looks like when editing a custom network:
Here is a video that goes through all Quicknode-suppported Infura networks and then shows selecting a custom RPC endpoint vs. Infura RPC endpoint:
mobile.demo.mp4
Pre-merge author checklist
Pre-merge reviewer checklist