-
-
Notifications
You must be signed in to change notification settings - Fork 185
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
Refactor: Expose SelectedNetworkController
proxies map in the constructor params
#4104
Merged
adonesky1
merged 6 commits into
main
from
jl/selected-network-controller-domainProxyMap
Mar 26, 2024
Merged
Refactor: Expose SelectedNetworkController
proxies map in the constructor params
#4104
adonesky1
merged 6 commits into
main
from
jl/selected-network-controller-domainProxyMap
Mar 26, 2024
Conversation
This file contains 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
3 tasks
adonesky1
previously approved these changes
Mar 25, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM based on the approach you carved out with @Gudahtt while I was away. Thanks for all your hard work here!
Gudahtt
reviewed
Mar 26, 2024
packages/selected-network-controller/src/SelectedNetworkController.ts
Outdated
Show resolved
Hide resolved
Gudahtt
previously approved these changes
Mar 26, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
…ller.ts Co-authored-by: Mark Stacey <markjstacey@gmail.com>
adonesky1
approved these changes
Mar 26, 2024
adonesky1
added a commit
that referenced
this pull request
Mar 26, 2024
…orkClient from `getProviderAndBlockTracker` when domain not in state (#4063) ## Explanation The SelectedNetworkController currently constructs a proxy for any domain that has permissions. Other domains have no associated proxy, so the getProviderAndBlockTracker method would throw an error. This is problematic because we grab the network client for an origin a single time when constructing an RPC pipeline for that origin in the MetaMask extension. We don't re-create the RPC pipeline when permissions change. That means that the pipeline is setup with the wrong network client (see here for more details on this bug: MetaMask/metamask-extension#23509 ) To resolve this problem, we can instead keep network client proxies for all origins, not just those with permissions. Origins without permissions still should not have a selected network client ID state, but they can have proxies that point at the globally selected network client. That way, when the origin is granted permissions, we can redirect this proxy to the selected network client and everything works smoothly, without needing to reconstruct the RPC pipeline. This PR should be merged shortly after #4104 ## References Fixes: #4062 See: #4104 ## Changelog <!-- If you're making any consumer-facing changes, list those changes here as if you were updating a changelog, using the template below as a guide. (CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or FIXED. For security-related issues, follow the Security Advisory process.) Please take care to name the exact pieces of the API you've added or changed (e.g. types, interfaces, functions, or methods). If there are any breaking changes, make sure to offer a solution for consumers to follow once they upgrade to the changes. Finally, if you're only making changes to development scripts or tests, you may replace the template below with "None". --> ### `@metamask/network-controller` - **ADDED**: Add `getSelectedNetworkClient()` method that returns the provider and blockTracker for the currently selected network - **ADDED**: Add 'NetworkController:getSelectedNetworkClient' action ### `@metamask/selected-network-controller` - **BREAKING**: `SelectedNetworkController` now requires the `NetworkController:getSelectedNetworkClient` messenger action - **CHANGED**: Previously when a domain became no longer permissioned, it's network client proxy would continue to point at the networkClientId it was last set to. Now it is set to follow the globally selected network - **CHANGED**: `SelectedNetworkController. getProviderAndBlockTracker()` no longer throws an error if the `useRequestQueue` flag is false - **CHANGED**: Previously `SelectedNetworkController. getProviderAndBlockTracker()` threw an error if there was no networkClientId set for the passed domain. Now it returns a proxy that follows the globally selected network instead. ## 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 --------- Co-authored-by: Mark Stacey <markjstacey@gmail.com> Co-authored-by: Jiexi Luan <jiexiluan@gmail.com>
Sign up for free
to 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.
Explanation
In a preceding PR, the SelectedNetworkController will start to keep proxy instances for all domains seen without a way to remove them when they become stale. This PR exposes the private proxies cache map as a constructor param which will enable callers to implement their own cache invalidation strategies without needing to concern the SelectedNetworkController of the implementation details themselves. This is needed because Mobile and Extension will need to follow different cache invalidation strategies.
This PR should be merged before #4063
References
Fixes: #4062
See: #4063
Changelog
@metamask/selected-network-controller
SelectedNetworkController
now expects thedomainProxyMap
param which is aMap
ofDomain
toNetworkProxy
Domain
typeChecklist