Skip to content

fix: removes extra domains from SelectedNetworkController domain state#23130

Merged
adonesky1 merged 27 commits intodevelopfrom
ad/bump-selected-network-controller-v8.0.0
Mar 1, 2024
Merged

fix: removes extra domains from SelectedNetworkController domain state#23130
adonesky1 merged 27 commits intodevelopfrom
ad/bump-selected-network-controller-v8.0.0

Conversation

@adonesky1
Copy link
Copy Markdown
Contributor

@adonesky1 adonesky1 commented Feb 22, 2024

  • Bumps to the the latest version of @metamask/selected-network-controller which fixes issue where the SelectedNetworkController adds any and all domains the user visits to its domains state whether or not the user has connected to these sites.
  • Adds a migration to clean up the undesired state caused by this bug.
  • Adds logic to listen for updates to permissions state and add newly connected/permissioned dapps to domains state in the SelectedNetworkController. I've created a ticket here to move this logic into the SelectedNetworkController itself.
  • Adds logic to couple the useRequestQueue feature flag with the perDomainNetwork feature flag. I've created a ticket here to remove the latter state since it is redundant and requires keeping these two booleans in sync.
  • Removes calls to setNetworkClientIdForMetamask since the latest version of @metamask/selected-network-controller removes this method (and the metamask domain from the domains state entirely).
  • Adds logic to use provider and blockTracker from the SelectedNetworkController when feature flag is on and connected origin is in domains state (which can only happen when the dapp is connected) in setupProviderEngine for RPC middleware stack.
  • Fixes a bug where if a dapp prompts an addEthereumChain request and the user then accepts the subsequent switchEthereumChain call that is chained on, the networkClientID set for that dapp in the SelectedNetworkController domains state will not be updated.

Manual Testing Steps

well first you need to comment out some code that is causing a separate bug (found on develop) but one that will make manually testing this a nightmare.

  1. Go to settings > experimental > Select networks for each site and toggle this setting on
  2. Put the globally selected network to ethereum mainnet
  3. Connect to uniswap
  4. Connect to pancakeswap
  5. Vist Aave but don't connect the wallet
  6. Open devtools in the wallet UI and run the follow command in the console:
const { metamask } = await window.stateHooks.getCleanAppState();
console.log(metamask.domains)
  1. You should see the following log:
{https://app.uniswap.org: 'mainnet', https://pancakeswap.finance: 'mainnet'}
  1. Now call switchEthereumChain on one of the connected dapps (they each have UI elements that do this)
  2. Now go back to the other dapp (where the chain hasn't been switched) and initiate a transaction
  3. You should receive a switchEthereumChain confirmation back to Ethereum Mainnet before the transaction confirmation is show.

@github-actions
Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@adonesky1 adonesky1 force-pushed the ad/bump-selected-network-controller-v8.0.0 branch from 7041cee to f9d191b Compare February 22, 2024 18:40
@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Feb 22, 2024
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this wasn't being used?

@adonesky1 adonesky1 changed the title Bump @metamask/selected-network-controller to v8.0.0, fix issue where… Bump @metamask/selected-network-controller to v8.0.0 Feb 22, 2024
@adonesky1 adonesky1 changed the title Bump @metamask/selected-network-controller to v8.0.0 Fix: bump @metamask/selected-network-controller to v8.0.0 Feb 22, 2024
@adonesky1 adonesky1 force-pushed the ad/bump-selected-network-controller-v8.0.0 branch from b527a23 to 495f622 Compare February 22, 2024 19:54
Comment on lines 4916 to 4930
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is no longer necessary because SelectedNetworkController no longer keeps track of the globally selectedNetworkClientId

Comment on lines 4941 to 4953
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is no longer necessary because SelectedNetworkController no longer keeps track of the globally selectedNetworkClientId

@adonesky1
Copy link
Copy Markdown
Contributor Author

@metamaskbot update-policies

@adonesky1 adonesky1 added team-wallet-api-platform-deprecated DEPRECATED: please use "team-wallet-integrations" instead team-core-extension-ux Core Extension UX team and removed INVALID-PR-TEMPLATE PR's body doesn't match template labels Feb 22, 2024
@metamaskbot
Copy link
Copy Markdown
Collaborator

No policy changes

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [90af9d5]
Page Load Metrics (1760 ± 88 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1343261955325
domContentLoaded979372110
load15082401176018488
domInteractive979372110
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 1.88 KiB (0.05%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Comment on lines 512 to 518
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we should probably just remove this redundant perDomainNetwork state from the SelectedNetworkController and just query for the useRequestQueue state on the PreferencesController wherever we need it. But this will require another update to the SelectedNetworkController and should be done in a separate PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This dedupe is happening here btw: MetaMask/core#3989

@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Feb 22, 2024
@adonesky1 adonesky1 force-pushed the ad/bump-selected-network-controller-v8.0.0 branch from 01ef225 to a44307e Compare February 23, 2024 16:33
useRequestQueue: true,
},
SelectedNetworkController: { domains: true, perDomainNetwork: false },
SelectedNetworkController: { domains: false, perDomainNetwork: true },
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We do not want to include domains in our sentry reports since it is potentially sensitive and violates our goal to preserve privacy, but we do want to include the perDomainNetwork toggle since it is not sensitive and potentially useful for diagnosing bugs.

Comment on lines +2449 to +2477
// When permissions are added for a given origin we need to
// set the network client id for that origin to the current
// globally selected network client id.
if (accounts.length > 0) {
// TODO add this logic directly in the SelectedNetworkController
this.selectedNetworkController.setNetworkClientIdForDomain(
origin,
this.networkController.state.selectedNetworkClientId,
);
} else {
// TODO remove domain from selectedNetworkController when permissions are removed
// Add this logic directly in the SelectedNetworkController
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is a WIP PR against the SelectedNetworkController to pull this logic into that controller instead: MetaMask/core#3969

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 26, 2024

Codecov Report

Attention: Patch coverage is 71.42857% with 18 lines in your changes are missing coverage. Please review.

Project coverage is 68.59%. Comparing base (63fb3d4) to head (3e67f01).
Report is 1 commits behind head on develop.

Files Patch % Lines
app/scripts/metamask-controller.js 72.22% 10 Missing ⚠️
...ethod-middleware/handlers/switch-ethereum-chain.js 16.67% 5 Missing ⚠️
...c-method-middleware/handlers/add-ethereum-chain.js 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #23130      +/-   ##
===========================================
- Coverage    68.61%   68.59%   -0.02%     
===========================================
  Files         1098     1099       +1     
  Lines        43101    43141      +40     
  Branches     11513    11539      +26     
===========================================
+ Hits         29571    29589      +18     
- Misses       13530    13552      +22     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [a72e1c7]
Page Load Metrics (1254 ± 468 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint784221617134
domContentLoaded15198504321
load6232411254975468
domInteractive15197504321
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 1.97 KiB (0.05%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@adonesky1 adonesky1 marked this pull request as ready for review February 27, 2024 01:48
@adonesky1 adonesky1 requested a review from a team as a code owner February 27, 2024 01:48
@adonesky1 adonesky1 changed the title Fix: bump @metamask/selected-network-controller to v8.0.0 Chore: bump @metamask/selected-network-controller to v8.0.0 Feb 27, 2024
@adonesky1 adonesky1 changed the title Chore: bump @metamask/selected-network-controller to v8.0.0 fix: removes extra domains from SelectedNetworkController domain state Feb 27, 2024
@adonesky1 adonesky1 requested a review from jiexi February 27, 2024 01:52
@Gudahtt
Copy link
Copy Markdown
Member

Gudahtt commented Mar 1, 2024

The diff looks good! I can re-review when CI passes. It looks like at least one of the CI failures is related to these changes, the e2e test failure.

@adonesky1 adonesky1 requested review from Gudahtt, jiexi and tmashuang March 1, 2024 17:06
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [a9885a5]
Page Load Metrics (889 ± 433 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint652231194521
domContentLoaded107829199
load522381889903433
domInteractive107829199
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 2.95 KiB (0.08%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

jiexi
jiexi previously approved these changes Mar 1, 2024
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [bbc2f17]
Page Load Metrics (886 ± 393 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint592011093617
domContentLoaded96326178
load471864886819393
domInteractive96326178
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 2.95 KiB (0.08%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@adonesky1 adonesky1 requested a review from jiexi March 1, 2024 20:14
Copy link
Copy Markdown
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [3e67f01]
Page Load Metrics (1340 ± 305 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint872351414421
domContentLoaded1385392411
load8319311340635305
domInteractive1385392411
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 2.95 KiB (0.08%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@adonesky1 adonesky1 merged commit 53b4c5d into develop Mar 1, 2024
@adonesky1 adonesky1 deleted the ad/bump-selected-network-controller-v8.0.0 branch March 1, 2024 20:53
@github-actions github-actions bot locked and limited conversation to collaborators Mar 1, 2024
@metamaskbot metamaskbot added the release-11.13.0 Issue or pull request that will be included in release 11.13.0 label Mar 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

INVALID-PR-TEMPLATE PR's body doesn't match template release-11.13.0 Issue or pull request that will be included in release 11.13.0 team-core-extension-ux Core Extension UX team team-wallet-api-platform-deprecated DEPRECATED: please use "team-wallet-integrations" instead

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants