Skip to content

Allow createInfuraMiddleware to take an RPC service #116

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

Merged
merged 3 commits into from
Feb 12, 2025

Conversation

mcmire
Copy link
Contributor

@mcmire mcmire commented Jan 28, 2025

@metamask/network-controller now contains an RpcService class. Using this class not only allows us to remove a lot of code from this package, as it incorporates the vast majority of logic contained in createInfuraMiddleware, including the retry logic, but it also allows us to use the circuit breaker pattern and the exponential backoff pattern to prevent too many retries if the network is unreliable, and then automatically cut over to a failover node when the network truly goes down.

Closes #115.
Closes #77.

Copy link

socket-security bot commented Jan 28, 2025

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@metamask/[email protected] None 0 202 kB metamaskbot
npm/@metamask/[email protected] None 0 348 kB metamaskbot
npm/@metamask/[email protected] network 0 322 kB metamaskbot
npm/@metamask/[email protected] None 0 76.2 kB gudahtt
npm/@metamask/[email protected] network +2 874 kB lgbot
npm/@metamask/[email protected] network 0 177 kB metamaskbot
npm/@metamask/[email protected] None +1 12.9 kB mcmire
npm/@metamask/[email protected] None 0 144 kB danfinlay, gudahtt, kumavis, ...6 more
npm/@metamask/[email protected] None 0 321 kB lgbot
npm/@metamask/[email protected] environment +2 1.05 MB metamaskbot
npm/@metamask/[email protected] None 0 292 kB lgbot
npm/@metamask/[email protected] None 0 37.1 kB metamaskbot
npm/@spruceid/[email protected] None 0 36.3 kB sbihel
npm/@tsd/[email protected] None 0 46.8 MB samverschueren
npm/@types/[email protected] None 0 13.9 kB types
npm/@types/[email protected] None 0 165 kB types
npm/@types/[email protected] None 0 25.8 kB types
npm/@types/[email protected] None 0 6.27 kB types
npm/@types/[email protected] None 0 5.81 kB types
npm/[email protected] filesystem 0 1.46 MB ldthomas
npm/[email protected] None 0 2.34 kB sindresorhus
npm/[email protected] None 0 63 kB dirtyhairy
npm/[email protected] None 0 351 kB mikemcl
npm/[email protected] None 0 99 kB fanatid
npm/[email protected] None +1 16.3 kB sindresorhus
npm/[email protected] None 0 465 kB connor.peet
npm/[email protected] None +1 6.55 kB sindresorhus
npm/[email protected] None 0 2.94 kB sindresorhus
npm/[email protected] environment 0 8.82 kB sindresorhus
npm/[email protected] None 0 200 kB stefanbuck
npm/[email protected] None 0 254 kB danfinlay
npm/[email protected] None 0 5.14 kB sindresorhus
npm/[email protected] None 0 24.4 kB gar
npm/[email protected] None +1 232 kB 1api
npm/[email protected] environment 0 872 kB mweststrate
npm/[email protected] None 0 6.92 kB sindresorhus
npm/[email protected] None 0 9.44 kB silentcicero
npm/[email protected] None 0 3.54 kB sindresorhus
npm/[email protected] None 0 81.8 kB emn178
npm/[email protected] None 0 22.8 kB doowb
npm/[email protected] None 0 23.2 kB lukeed
npm/[email protected] None 0 4.58 kB sindresorhus
npm/[email protected] None 0 86.2 kB pimterry
npm/[email protected] None 0 9.49 kB sindresorhus
npm/[email protected] None +1 127 kB sindresorhus
npm/[email protected] None 0 2.97 kB thejameskyle
npm/[email protected] None +1 11.1 kB vdemedes
npm/[email protected] None 0 27.9 kB gar
npm/[email protected] None 0 8.87 kB sindresorhus
npm/[email protected] None 0 5 kB sindresorhus
npm/[email protected] None 0 7.47 kB sindresorhus
npm/[email protected] None +2 72.1 kB sindresorhus
npm/[email protected] filesystem +4 151 kB sindresorhus
npm/[email protected] None 0 3.6 kB sindresorhus
npm/[email protected] None 0 646 kB acemarke
npm/[email protected] None 0 30.7 kB bridgear
npm/[email protected] None 0 23.4 kB kemitchell
npm/[email protected] None 0 9.66 kB silentcicero
npm/[email protected] None 0 3.31 kB sindresorhus
npm/[email protected] None 0 3.85 kB sindresorhus
npm/[email protected] Transitive: environment +8 770 kB sindresorhus
npm/[email protected] None 0 90.4 kB typescript-bot
npm/[email protected] None 0 175 kB dchest
npm/[email protected] None 0 17.2 kB odysseas
npm/[email protected] None 0 16.6 kB kemitchell
npm/[email protected] None 0 6.46 kB raynos

View full report↗︎

Copy link

socket-security bot commented Jan 28, 2025

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

Ignoring: npm/[email protected], npm/[email protected], npm/@metamask/[email protected], npm/@spruceid/[email protected], npm/@metamask/[email protected], npm/@metamask/[email protected], npm/@metamask/[email protected], npm/@metamask/[email protected]

View full report↗︎

Next steps

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of ecosystem/package-name@version specifiers. e.g. @SocketSecurity ignore npm/[email protected] or ignore all packages with @SocketSecurity ignore-all

@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

@mcmire mcmire force-pushed the integrate-rpc-service branch from dae01b6 to b0ea84d Compare January 28, 2025 20:25
@mcmire
Copy link
Contributor Author

mcmire commented Jan 28, 2025

@SocketSecurity ignore npm/[email protected]
@SocketSecurity ignore npm/[email protected]
@SocketSecurity ignore npm/@metamask/[email protected]
@SocketSecurity ignore npm/@spruceid/[email protected]
@SocketSecurity ignore npm/@metamask-previews/[email protected]

New author is OK. Either it's us or known members of the NPM community.
Network access is OK. @metamask/controller-utils includes several wrappers around fetch.

@mcmire mcmire force-pushed the integrate-rpc-service branch 3 times, most recently from 9128d9b to 089e660 Compare February 3, 2025 22:34
@mcmire
Copy link
Contributor Author

mcmire commented Feb 3, 2025

@SocketSecurity ignore npm/@metamask/[email protected]
@SocketSecurity ignore npm/@metamask/[email protected]
@SocketSecurity ignore npm/@metamask/[email protected]

These are ours.

@mcmire mcmire force-pushed the integrate-rpc-service branch 2 times, most recently from d12e9a4 to 77e4bfc Compare February 4, 2025 22:54
`@metamask/network-controller` now contains an `RpcService` class. Using
this class not only allows us to remove a lot of code from this package,
as it incorporates the vast majority of logic contained in
`createInfuraMiddleware`, including the retry logic, but it also allows
us to use the circuit breaker pattern and the exponential backoff
pattern to prevent too many retries if the network is unreliable, and
then automatically cut over to a failover node when the network truly
goes down.
@mcmire mcmire force-pushed the integrate-rpc-service branch from 77e4bfc to c88e9c7 Compare February 4, 2025 22:56
@mcmire
Copy link
Contributor Author

mcmire commented Feb 4, 2025

@SocketSecurity ignore npm/@metamask/[email protected]

This is our package.

@mcmire mcmire marked this pull request as ready for review February 4, 2025 23:02
@mcmire mcmire requested a review from a team as a code owner February 4, 2025 23:02
* The interface for a service class responsible for making a request to an RPC
* endpoint.
*/
export type AbstractRpcService = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could get this from @metamask/network-controller, but that would create a circular dependency.

cryptodev-2s
cryptodev-2s previously approved these changes Feb 12, 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!

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!

@mcmire mcmire merged commit f24567d into main Feb 12, 2025
9 checks passed
@mcmire mcmire deleted the integrate-rpc-service branch February 12, 2025 18:36
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.

Use RPC service object from NetworkController Use exponential backoff when retrying requests
2 participants