Uh oh!
There was an error while loading. Please reload this page.
Fix SelectedNetworkController state corruption when networkClients are removed - #3926
Merged
Conversation
adonesky1
marked this pull request as ready for review
February 16, 2024 21:27
SelectedNetworkController state corruption when networkClients are removedGudahtt
reviewed
Feb 16, 2024
Member
There was a problem hiding this comment.
Interesting idea to use patches for this. Might be more performant this way? I worry about the potential for a network configuration to be replaced by a different operation though, e.g. move or replace.
At the moment I think remove is the only possibility, but later with data syncing, I am not so sure.
Comparing each selected network client ID with each existing network might be safer.
Member
There was a problem hiding this comment.
We could ensure this only runs for config changes by using a selector as well, e.g.
this.messagingSystem.subscribe(
'NetworkController:stateChange',
(networkConfigurations) => {
...
},
(state) => state.networkConfigurations,
)
jiexi
previously approved these changes
Feb 20, 2024
adonesky1force-pushed
the
ad/fix-selected-network-middleware
branch
from
February 20, 2024 19:29
a209931 to
a71ecddCompareadonesky1force-pushed
the
ad/fix-removing-networks
branch
from
February 20, 2024 20:10
2baf760 to
b6c560fCompareadonesky1
dismissed stale reviews from jiexi and GudahttFebruary 22, 2024 00:14
The base branch was changed.
…mains that were pointed at that networkClient are repointed to the globally selected network
adonesky1force-pushed
the
ad/fix-removing-networks
branch
from
February 22, 2024 15:12
b6c560f to
5652d07Compareshanejonas
approved these changes
Feb 22, 2024
Merged
adonesky1 added a commit
that referenced
this pull request
Feb 22, 2024
# @metamask/selected-network-controller ## [8.0.0] ### Changed - **BREAKING:** `setNetworkClientIdForDomain` now throws an error if passed `metamask` as its first (`domain`) argument ([#3908](#3908)). - **BREAKING:** `setNetworkClientIdForDomain` now includes a check that the requesting `domain` has already been granted permissions in the `PermissionsController` before adding it to `domains` state and throws an error if the domain does not have permissions ([#3908](#3908)). - **BREAKING:** the `domains` state now no longer contains a `metamask` domain key Consumers should instead use the `selectedNetworkClientId` from the `NetworkController` to get the selected network for the `metamask` domain ([#3908](#3908)). - **BREAKING:** `getProviderAndBlockTracker` now throws an error if called with any domain while the `perDomainNetwork` flag is false. Consumers should instead use the `provider` and `blockTracker` from the `NetworkController` when the `perDomainNetwork` flag is false ([#3908](#3908)). - **BREAKING:** `getProviderAndBlockTracker` now throws an error if called with a domain that is not in domains state ([#3908](#3908)). - **BREAKING:** `getNetworkClientIdForDomain` now returns the `selectedNetworkClientId` for the globally selected network if the `perDomainNetwork` flag is false and if the domain is not in the `domains` state ([#3908](#3908)). ### Removed - **BREAKING:** Remove logic in `selectedNetworkMiddleware` to set a default `networkClientId` for the requesting origin when not already set. Now if no `networkClientId` is already set for the requesting origin, the middleware will not add the origin to `domains` state but will add the `networkClientId` currently set for the `selectedNetworkClient` from the `NetworkController` to the request object ([#3908](#3908)). ### Fixed - The `SelectedNetworkController` now listens for `networkConfiguration` removal events on the `NetworkController` and if a removed `networkClientId` matches the set `networkClientId` for any domains in its state, it updates them to the globally selected `networkClientId` and repoints the proxies accordingly. ([#3926](#3926)) --------- Co-authored-by: jiexi <jiexiluan@gmail.com> Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: https://github.com/MetaMask/MetaMask-planning/issues/1964
@metamask/selected-network-controllerCHANGED
SelectedNetworkControllernow listens fornetworkConfigurationremoval events on theNetworkControllerand if a removednetworkClientIdmatches the set networkClientId for anydomainsin its state, it updates them to the globally selected networkClientId and repoints the proxies accordingly.Checklist