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

Create RPC service #4990

Open
Gudahtt opened this issue Nov 27, 2024 · 2 comments
Open

Create RPC service #4990

Gudahtt opened this issue Nov 27, 2024 · 2 comments
Assignees
Labels

Comments

@Gudahtt
Copy link
Member

Gudahtt commented Nov 27, 2024

Create an RPC service that can be used by the NetworkController to make RPC requests. This service would be responsible for intelligently retrying failed requests, and for avoid undue network load using exponential backoff, jitter, and circuit breaker patterns. This would be in accordance with the External API Integrations ADR: https://github.com/MetaMask/decisions/blob/main/decisions/core/0002-external-api-integrations.md

This would live alongside the NetworkController, not within it. It would be a separate package export. Whether it's in its own package or not can be a decision for the author, that is less important.

@mcmire
Copy link
Contributor

mcmire commented Dec 6, 2024

Instead of having the service take onBreak and onDegraded callbacks, we could consider having the service emit events, and emit separate events for the primary RPC endpoint vs. the failover RPC endpoints. This way clients could react to the failover status at each appropriately, and we'd also give the network controller a way to react to the status as well (if we, say, need to capture in state which RPC endpoint among a primary and list of failovers is the active one).

We could also keep things simple and make this change in #4992, whichever makes the most sense.

@mcmire
Copy link
Contributor

mcmire commented Jan 8, 2025

Leaving more notes for myself:

Currently both the fetch and Infura middleware implement retry logic. We need the service to contain this logic instead. This is different from a standard service object because some errors are retriable while others are not. This means that the RPC service needs to use a different error filter policy other than handleAll. That means that createServicePolicy needs to support passing in a custom error filter policy (defaulting to handleAll). The service also needs to check for HTTP status codes (which means we need to standardize on them), as this dictates whether or not to retry, and it may also parse the JSON response for convenience (but perhaps failing to parse the response should not trigger a retry? not sure).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants