Skip to content

Correct invalid initial selectedNetworkClientId #5851

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mcmire
Copy link
Contributor

@mcmire mcmire commented May 22, 2025

Explanation

Currently, when NetworkController is instantiated with pre-existing state that contains an invalid selectedNetworkClientId — that is, no RPC endpoint exists which has the same network client ID — then it throws an error. This was intentionally done to bring attention to possible bugs in NetworkController, but this has the unfortunate side effect of bricking users' wallets.

To fix this, we now correct an invalid selectedNetworkClientId to point to the default RPC endpoint of the first network sorted by chain ID (which in the vast majority of cases will be Mainnet). We still do want to know about this, though, so we log the error in Sentry.

References

Fixes #5739.

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 communicated my changes to consumers by updating changelogs for packages I've changed, highlighting breaking changes as necessary
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

@mcmire mcmire force-pushed the handle-invalid-selected-network-client-id branch from 291f6b3 to 3d36c69 Compare May 22, 2025 20:00
Base automatically changed from add-error-reporting-service to main May 23, 2025 20:08
Currently, when NetworkController is instantiated with pre-existing
state that contains an invalid `selectedNetworkClientId` — that is, no
RPC endpoint exists which has the same network client ID — then it
throws an error. This was intentionally done to bring attention to
possible bugs in NetworkController, but this has the unfortunate side
effect of bricking users' wallets.

To fix this, we now correct an invalid `selectedNetworkClientId` to
point to the default RPC endpoint of the first network sorted by chain
ID (which in the vast majority of cases will be Mainnet). We still do
want to know about this, though, so we log the error in Sentry.
@mcmire mcmire force-pushed the handle-invalid-selected-network-client-id branch from 3d36c69 to 409b54c Compare May 23, 2025 21:02
NetworkControllerActions,
NetworkControllerEvents
>;
messenger: RootMessenger;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The type of the messenger in these tests only took internal actions and events into consideration and not external actions, so I've had to correct all of them.

@@ -87,7 +89,7 @@ export function buildNetworkControllerMessenger(
): NetworkControllerMessenger {
return messenger.getRestricted({
name: 'NetworkController',
allowedActions: [],
allowedActions: ['ErrorReportingService:captureException'],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here we need to add ErrorReportingService:captureException to the list of external actions because we are now using it in the controller.

@mcmire mcmire marked this pull request as ready for review May 23, 2025 21:12
@mcmire mcmire requested review from a team as code owners May 23, 2025 21:12
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!

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.

Gracefully handle invalid selectedNetworkClientId upon NetworkController initialization
2 participants