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

[Sentry] Error: networkConfigurationId [UUID] does not match a configured networkConfiguration or built-in network type #26309

Closed
sentry-io bot opened this issue Aug 2, 2024 · 2 comments · Fixed by #26428
Assignees
Labels
area-Sentry error reporting to sentry regression-prod-12.0.0 Regression bug that was found in production in release 12.0.0 release-12.3.0 Issue or pull request that will be included in release 12.3.0 Sev1-high High severity; partial loss of service with severe impact upon users, with no workaround. team-wallet-framework type-bug

Comments

@sentry-io
Copy link

sentry-io bot commented Aug 2, 2024

Sentry Issue: METAMASK-XB5M

Error: networkConfigurationId 329bb3e7-6f60-48fd-90a3-41d770dbae27 does not match a configured networkConfiguration or built-in network type
  at <object>.setActiveNetworkConfigurationId (app/scripts/metamask-controller.js:2977:32)
  at ReflectApply (app/scripts/lib/createMetaRPCHandler.js:23:31)
...
(13 additional frame(s) were not displayed)
@Gudahtt Gudahtt added type-bug Sev1-high High severity; partial loss of service with severe impact upon users, with no workaround. team-wallet-framework labels Aug 2, 2024
@github-project-automation github-project-automation bot moved this to To be fixed in Bugs by severity Aug 2, 2024
@github-project-automation github-project-automation bot moved this to To be fixed in Bugs by team Aug 2, 2024
@Gudahtt Gudahtt added the regression-prod-12.0.0 Regression bug that was found in production in release 12.0.0 label Aug 2, 2024
Gudahtt added a commit that referenced this issue Aug 2, 2024
Remove invalid `providerConfig.id` state. This was one possible
explanation for some Sentry errors that we have been encountering in
production. The diagnostic state attached to the error was not
sufficient to confirm that this was the cause.

Relates to #26309
Gudahtt added a commit that referenced this issue Aug 2, 2024
Remove invalid `providerConfig.id` state. This was one possible
explanation for some Sentry errors that we have been encountering in
production. The diagnostic state attached to the error was not
sufficient to confirm that this was the cause.

Relates to #26309
Gudahtt added a commit that referenced this issue Aug 2, 2024
## **Description**

Remove invalid `providerConfig.id` state. This was one possible
explanation for some Sentry errors that we have been encountering in
production. The diagnostic state attached to the error was not
sufficient to confirm that this was the cause.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26310?quickstart=1)

## **Related issues**

Relates to #26309 and #26320

## **Manual testing steps**

N/A

## **Screenshots/Recordings**

N/A

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
Gudahtt added a commit that referenced this issue Aug 2, 2024
## **Description**

Remove invalid `providerConfig.id` state. This was one possible
explanation for some Sentry errors that we have been encountering in
production. The diagnostic state attached to the error was not
sufficient to confirm that this was the cause.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26310?quickstart=1)

## **Related issues**

Relates to #26309 and #26320

## **Manual testing steps**

N/A

## **Screenshots/Recordings**

N/A

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
@metamaskbot metamaskbot changed the title Error: networkConfigurationId 329bb3e7-6f60-48fd-90a3-41d770dbae27 does not match a configured networkCo... [Sentry] Error: networkConfigurationId 329bb3e7-6f60-48fd-90a3-41d770dbae27 does not match a configured networkCo... Aug 5, 2024
@metamaskbot metamaskbot added the area-Sentry error reporting to sentry label Aug 5, 2024
dawnseeker8 pushed a commit that referenced this issue Aug 12, 2024
## **Description**

Remove invalid `providerConfig.id` state. This was one possible
explanation for some Sentry errors that we have been encountering in
production. The diagnostic state attached to the error was not
sufficient to confirm that this was the cause.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26310?quickstart=1)

## **Related issues**

Relates to #26309 and #26320

## **Manual testing steps**

N/A

## **Screenshots/Recordings**

N/A

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
@Gudahtt Gudahtt changed the title [Sentry] Error: networkConfigurationId 329bb3e7-6f60-48fd-90a3-41d770dbae27 does not match a configured networkCo... [Sentry] Error: networkConfigurationId [UUID] does not match a configured networkCo... Aug 14, 2024
@Gudahtt Gudahtt changed the title [Sentry] Error: networkConfigurationId [UUID] does not match a configured networkCo... [Sentry] Error: networkConfigurationId [UUID] does not match a configured networkConfiguration or built-in network type Aug 14, 2024
@Gudahtt Gudahtt self-assigned this Aug 14, 2024
Gudahtt added a commit that referenced this issue Aug 14, 2024
The `SelectedNetworkController` state is cleared if any invalid
`networkConfigurationId`s are found in state. We are seeing reports of
this happening in production in v12.0.1.

The suspected cause is `NetworkController` state corruption. We
resolved a few cases of this in v12.0.1, but for users that were
affected by this, the invalid IDs may have propogated to the
`SelectedNetworkController` state already. That is what this migration
intends to fix.

Fixes #26309
Gudahtt added a commit that referenced this issue Aug 14, 2024
The `SelectedNetworkController` state is cleared if any invalid
`networkConfigurationId`s are found in state. We are seeing reports of
this happening in production in v12.0.1.

The suspected cause is `NetworkController` state corruption. We
resolved a few cases of this in v12.0.1, but for users that were
affected by this, the invalid IDs may have propogated to the
`SelectedNetworkController` state already. That is what this migration
intends to fix.

Fixes #26309
Gudahtt added a commit that referenced this issue Aug 14, 2024
## **Description**

The `SelectedNetworkController` state is cleared if any invalid
`networkConfigurationId`s are found in state. We are seeing reports of
this happening in production in v12.0.1.

The suspected cause is `NetworkController` state corruption. We resolved
a few cases of this in v12.0.1, but for users that were affected by
this, the invalid IDs may have propogated to the
`SelectedNetworkController` state already. That is what this migration
intends to fix.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26428?quickstart=1)

## **Related issues**

Fixes #26309

## **Manual testing steps**

We don't have clear reproduction steps for the bug itself. To
artificially reproduce the scenario by changing extension state, this
should work:

* Create a dev build from v12.0.2
* Install the dev build from the `dist/chrome` directory and proceed
through onboarding
* Visit the test dapp, refresh, and connect to it.
* Run this command in the background console:
  ```
  chrome.storage.local.get(
    null,
    (state) => {

state.data.SelectedNetworkController.domains['https://metamask.github.io']
= '123';
      chrome.storage.local.set(state, () => chrome.runtime.reload());
    }
  );
  ```
  * The linked error should now appear in the console of the popup
* Disable the extension
* Switch to this branch and create a dev build
* Enable and reload the extension
  * The error should no longer appear.

## **Screenshots/Recordings**

N/A

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
@github-project-automation github-project-automation bot moved this from To be fixed to Fixed in Bugs by team Aug 14, 2024
@github-project-automation github-project-automation bot moved this from To be fixed to Fixed in Bugs by severity Aug 14, 2024
Gudahtt added a commit that referenced this issue Aug 14, 2024
## **Description**

The `SelectedNetworkController` state is cleared if any invalid
`networkConfigurationId`s are found in state. We are seeing reports of
this happening in production in v12.0.1.

The suspected cause is `NetworkController` state corruption. We resolved
a few cases of this in v12.0.1, but for users that were affected by
this, the invalid IDs may have propogated to the
`SelectedNetworkController` state already. That is what this migration
intends to fix.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26428?quickstart=1)

## **Related issues**

Fixes #26309

## **Manual testing steps**

We don't have clear reproduction steps for the bug itself. To
artificially reproduce the scenario by changing extension state, this
should work:

* Create a dev build from v12.0.2
* Install the dev build from the `dist/chrome` directory and proceed
through onboarding
* Visit the test dapp, refresh, and connect to it.
* Run this command in the background console:
  ```
  chrome.storage.local.get(
    null,
    (state) => {

state.data.SelectedNetworkController.domains['https://metamask.github.io']
= '123';
      chrome.storage.local.set(state, () => chrome.runtime.reload());
    }
  );
  ```
  * The linked error should now appear in the console of the popup
* Disable the extension
* Switch to this branch and create a dev build
* Enable and reload the extension
  * The error should no longer appear.

## **Screenshots/Recordings**

N/A

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
@metamaskbot metamaskbot added the release-12.4.0 Issue or pull request that will be included in release 12.4.0 label Aug 14, 2024
Gudahtt added a commit that referenced this issue Aug 14, 2024
## **Description**

The `SelectedNetworkController` state is cleared if any invalid
`networkConfigurationId`s are found in state. We are seeing reports of
this happening in production in v12.0.1.

The suspected cause is `NetworkController` state corruption. We resolved
a few cases of this in v12.0.1, but for users that were affected by
this, the invalid IDs may have propogated to the
`SelectedNetworkController` state already. That is what this migration
intends to fix.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26428?quickstart=1)

## **Related issues**

Fixes #26309

## **Manual testing steps**

We don't have clear reproduction steps for the bug itself. To
artificially reproduce the scenario by changing extension state, this
should work:

* Create a dev build from v12.0.2
* Install the dev build from the `dist/chrome` directory and proceed
through onboarding
* Visit the test dapp, refresh, and connect to it.
* Run this command in the background console:
  ```
  chrome.storage.local.get(
    null,
    (state) => {

state.data.SelectedNetworkController.domains['https://metamask.github.io']
= '123';
      chrome.storage.local.set(state, () => chrome.runtime.reload());
    }
  );
  ```
  * The linked error should now appear in the console of the popup
* Disable the extension
* Switch to this branch and create a dev build
* Enable and reload the extension
  * The error should no longer appear.

## **Screenshots/Recordings**

N/A

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
@Gudahtt
Copy link
Member

Gudahtt commented Aug 15, 2024

We found another instance where this same state corruption could be introduced. Reopening.

@Gudahtt Gudahtt reopened this Aug 15, 2024
@github-project-automation github-project-automation bot moved this from Fixed to To be fixed in Bugs by team Aug 15, 2024
@Gudahtt
Copy link
Member

Gudahtt commented Aug 15, 2024

I found another case where this state is getting corrupted unfortunately. The issue we saw with #26072 involves a brief period of NetworkController state corruption in the case where the RPC URL for the current selected network is edited. We remove it first, then re-add it as a separate configuration (and switch to it).

The removal triggers the SelectedNetworkController to update the domains state for any domains with that network client ID selected, to switch it back to the globally selected network client as a default. But in that scenario, the globally selected network client is the same one, the one that was just removed, which is invalid. See https://github.com/MetaMask/core/blob/d1202fd926e84600b12cb37d2e081b3c96a84a38/packages/selected-network-controller/src/SelectedNetworkController.ts#L204

We need to fix the NetworkController state corruption to fix this, and replay migration 120.5 to resolve any new corruption caused by this.

jiexi added a commit to MetaMask/core that referenced this issue Aug 15, 2024
…tworkConfigurationId (#4614)

## Explanation

Currently it is not possible to change the rpcUrl for an existing
network configuration without first removing it then re-adding it. This
poses an issue on extension when the rpcUrl for the currently selected
network is changed via the `NetworkForm`. The NetworkForm first removes
the existing networkClient which causes the SelectedNetworkController to
replace any references to the networkClientId being removed with the
selectedNetworkClientId, but the problem is that the
selectedNetworkClientId is no longer valid at that point. Really what we
want in this case is to allow the network configuration to be updated in
place by id, but only if the rpcUrl isn't changing to one that already
exists on a different network configuration.

This PR achieves that by changing
`NetworkController.upsertNetworkConfiguration()` to accept an optional
`id` in the `NetworkConfiguration` param. When provided, it MUST match
to an existing network configuration. Additionally, it must match the id
for any network configuration that may match the target rpcUrl

## References

Related: MetaMask/metamask-extension#26309

## 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**: `NetworkController.upsertNetworkConfiguration()` accepts an
optional `id` property on the `NetworkConfiguration` param. It now
allows a network configuration to have its `rpcUrl` updated in place
when an `id` is specified, but only if that new `rpcUrl` does not
already exist on a different network configuration.

## 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
jiexi added a commit that referenced this issue Aug 16, 2024
…Form update in-place rather than remove and add for rpcUrl changes (#26453)

<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

Currently it is not possible to change the rpcUrl for an existing
network configuration without first removing it then re-adding it. This
poses an issue on extension when the rpcUrl for the currently selected
network is changed via the `NetworkForm`. The NetworkForm first removes
the existing networkClient which causes the SelectedNetworkController to
replace any references to the networkClientId being removed with the
selectedNetworkClientId, but the problem is that the
selectedNetworkClientId is no longer valid at that point and leaves the
SelectedNetworkController in a corrupted state.

Really what we want in this case is to allow the network configuration
to be updated in place by id, but only if the rpcUrl isn't changing to
one that already exists on a different network configuration.

This PR achieves that by getting rid of the
`removeNetworkConfiguration()` call triggered by `NetworkForm` and
patching the `NetworkController` with changes from
MetaMask/core#4614 which allow network
configurations to have their rpcUrl updated in place. It also keeps the
existing patch that removed a `lookupNetwork()` call in
`initializeProvider()`.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26453?quickstart=1)

## **Related issues**

Related: #26309

## **Manual testing steps**

1. Open extension in expanded view
2. Visit the Settings -> Networks
3. Add a network manually and add an rpc provider for Arbitrum One (for
your convenience, [chainlist.org](https://chainlist.org/chain/42161))
4. In the extension service worker console note the state via
`chrome.storage.local.get(console.log)` for
NetworkController.networkConfigurations
5. Visit the Network Form for that Network
6. Change the rpcUrl to a different valid one for Arbitrum 
7. In the extension service worker console check state via
`chrome.storage.local.get(console.log)`, the id for the network
configuration that was just edited should not have changed in
NetworkController.networkConfigurations
8. Visit a dapp, switch the chain to Arbitrum 
```
await window.ethereum.request({
  "method": "eth_requestAccounts",
});
await window.ethereum.request({
  "method": "wallet_switchEthereumChain",
  "params": [
    {
      "chainId": "0xa4b1"
    }
  ]
});
```
7. In the extension service worker console check state via
`chrome.storage.local.get(console.log)`, the dapp should have an entry
for the network client we added above SelectedNetworkController.domains
8. Again, Change the rpcUrl to a different valid one for Arbitrum 
9. In the extension service worker console check state via
`chrome.storage.local.get(console.log)`, the dapp should still be
pointed at the same network client id in
SelectedNetworkController.domains which should still exist in
NetworkController.networkConfigurations

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
jiexi added a commit that referenced this issue Aug 16, 2024
…Form update in-place rather than remove and add for rpcUrl changes (#26453)

<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

Currently it is not possible to change the rpcUrl for an existing
network configuration without first removing it then re-adding it. This
poses an issue on extension when the rpcUrl for the currently selected
network is changed via the `NetworkForm`. The NetworkForm first removes
the existing networkClient which causes the SelectedNetworkController to
replace any references to the networkClientId being removed with the
selectedNetworkClientId, but the problem is that the
selectedNetworkClientId is no longer valid at that point and leaves the
SelectedNetworkController in a corrupted state.

Really what we want in this case is to allow the network configuration
to be updated in place by id, but only if the rpcUrl isn't changing to
one that already exists on a different network configuration.

This PR achieves that by getting rid of the
`removeNetworkConfiguration()` call triggered by `NetworkForm` and
patching the `NetworkController` with changes from
MetaMask/core#4614 which allow network
configurations to have their rpcUrl updated in place. It also keeps the
existing patch that removed a `lookupNetwork()` call in
`initializeProvider()`.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26453?quickstart=1)

Related: #26309

1. Open extension in expanded view
2. Visit the Settings -> Networks
3. Add a network manually and add an rpc provider for Arbitrum One (for
your convenience, [chainlist.org](https://chainlist.org/chain/42161))
4. In the extension service worker console note the state via
`chrome.storage.local.get(console.log)` for
NetworkController.networkConfigurations
5. Visit the Network Form for that Network
6. Change the rpcUrl to a different valid one for Arbitrum
7. In the extension service worker console check state via
`chrome.storage.local.get(console.log)`, the id for the network
configuration that was just edited should not have changed in
NetworkController.networkConfigurations
8. Visit a dapp, switch the chain to Arbitrum
```
await window.ethereum.request({
  "method": "eth_requestAccounts",
});
await window.ethereum.request({
  "method": "wallet_switchEthereumChain",
  "params": [
    {
      "chainId": "0xa4b1"
    }
  ]
});
```
7. In the extension service worker console check state via
`chrome.storage.local.get(console.log)`, the dapp should have an entry
for the network client we added above SelectedNetworkController.domains
8. Again, Change the rpcUrl to a different valid one for Arbitrum
9. In the extension service worker console check state via
`chrome.storage.local.get(console.log)`, the dapp should still be
pointed at the same network client id in
SelectedNetworkController.domains which should still exist in
NetworkController.networkConfigurations

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

<!-- [screenshots/recordings] -->

<!-- [screenshots/recordings] -->

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
@github-project-automation github-project-automation bot moved this from To be fixed to Fixed in Bugs by team Aug 19, 2024
@gauthierpetetin gauthierpetetin added release-12.3.0 Issue or pull request that will be included in release 12.3.0 and removed release-12.4.0 Issue or pull request that will be included in release 12.4.0 labels Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Sentry error reporting to sentry regression-prod-12.0.0 Regression bug that was found in production in release 12.0.0 release-12.3.0 Issue or pull request that will be included in release 12.3.0 Sev1-high High severity; partial loss of service with severe impact upon users, with no workaround. team-wallet-framework type-bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants