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

NetworkController: Add RPC service class #5163

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

mcmire
Copy link
Contributor

@mcmire mcmire commented Jan 16, 2025

Explanation

This commit adds an RPC service class that will ultimately be used inside of middleware to make JSON-RPC requests to an RPC endpoint. It makes uses of createServicePolicy, added in a previous commit, to encapsulate the request code using the retry and circuit breaker policies. As this service class is designed to replace large parts of the fetch and Infura middleware, it customizes the service policy so that the request will be retried only when the network is perceived to be "down". This occurs when:

  • The fetch call throws a "Failed to fetch" error (or something similar to it; see code for the full list of variations)
  • The fetch call throws an ETIMEDOUT or ECONNRESET error
  • The response status is 503 or 504
  • The response body is invalid JSON

In contrast, the network is not perceived to be "down" if:

  • The fetch call throws an unexpected error (e.g. if the request options are invalid)
  • The response status is not 2xx, but is also not 503 or 504
  • The response body is an unsuccessful JSON-RPC response
  • The response body is a successful, but empty, JSON-RPC response

References

Closes #4990.

Changelog

(N/A; internal change only)

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

eslint.config.mjs Outdated Show resolved Hide resolved
@mcmire mcmire force-pushed the create-nc-rpc-service branch from 31debed to 2b6e317 Compare January 16, 2025 18:18
Base automatically changed from extract-create-service-policy-3 to main January 22, 2025 23:33
@mcmire mcmire force-pushed the create-nc-rpc-service branch 4 times, most recently from 8ae2602 to 540bf4b Compare January 24, 2025 16:28
This commit adds an RPC service class that will ultimately be used
inside of middleware to make JSON-RPC requests to an RPC endpoint. It
makes uses of `createServicePolicy`, added in a previous commit, to
encapsulate the request code using the retry and circuit breaker
policies. As this service class is designed to replace large parts of
the fetch and Infura middleware, it customizes the service policy so
that the request will be retried only when the network is perceived to
be "down". This occurs when:

- The `fetch` call throws a "Failed to fetch" error (or something
  similar to it; see code for the full list of variations)
- The `fetch` call throws an ETIMEDOUT or ECONNRESET error
- The response status is 503 or 504
- The response body is invalid JSON

In contrast, the network is not perceived to be "down" if:

- The `fetch` call throws an unexpected error (e.g. if the request
  options are invalid)
- The response status is not 2xx, but is also not 503 or 504
- The response body is an unsuccessful JSON-RPC response
- The response body is a successful, but empty, JSON-RPC response
@mcmire mcmire force-pushed the create-nc-rpc-service branch from 540bf4b to a5d7141 Compare January 24, 2025 16:36
@mcmire mcmire marked this pull request as ready for review January 24, 2025 16:45
@mcmire mcmire requested review from a team as code owners January 24, 2025 16:45
@mcmire mcmire changed the title Add NetworkController RPC service class NetworkController: Add RPC service class Jan 24, 2025
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.

Create RPC service
1 participant