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

Remove networkId from NetworkController #1633

Merged
merged 40 commits into from
Sep 25, 2023
Merged

Remove networkId from NetworkController #1633

merged 40 commits into from
Sep 25, 2023

Conversation

jiexi
Copy link
Contributor

@jiexi jiexi commented Aug 24, 2023

Explanation

Wallets shouldn't be directly concerned about the network ID as this is more of a node concept for gossip. What wallets really care about is chain ID as that is the correct value to use to identify a chain, build transactions, etc. Although these two values usually match (ignoring hex/dec formatting), there are exceptions.

We want to remove networkId from the NetworkController state to encourage the replacement of networkId with chainId in any usage downstream (extension, mobile, etc). It will still be possible to get networkId using the rpc client to make a call to the net_version method for cases that truly still rely on it.

References

Changelog

@metamask/controller-utils

  • BREAKING: NETWORK_ID_TO_ETHERS_NETWORK_NAME_MAP renamed to CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP and is now a mapping of Hex chain ID to BuiltInNetworkName
  • REMOVED: NetworkId constant and type

@metamask/ens-controller

  • CHANGED: From Network state, uses providerConfig.chainId instead of networkId to determine ENS compatability

@metamask/network-controller

  • REMOVED: NetworkId type
  • REMOVED: From NetworkState removed networkId field
  • CHANGED: No longer calls net_version to determine network status (only relies on eth_getBlockByNumber now)
  • CHANGED: For Built-in Infura Networks, net_version is no longer locally resolved by the scaffold middleware

@metamask/transaction-controller

  • BREAKING: Uses chainId and txParams.chainId to determine if a TransactionMeta object belongs to the current chain. No longer considers networkID
  • BREAKING: TransactionMeta.chainId is now a required field
  • REMOVED: From RemoteTransactionSourceRequest removed currentNetworkId field
  • CHANGED: From RemoteTransactionSource updated isSupportedNetwork() params to exclude networkId
  • DEPRECATED: TransactionMeta.networkID is deprecated and marked readonly

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 jiexi requested a review from a team as a code owner August 24, 2023 22:18
@jiexi
Copy link
Contributor Author

jiexi commented Aug 28, 2023

@metamaskbot publish-preview

@github-actions
Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/address-book-controller": "3.1.0-preview.3dbf14f",
  "@metamask-previews/announcement-controller": "4.0.0-preview.3dbf14f",
  "@metamask-previews/approval-controller": "3.5.0-preview.3dbf14f",
  "@metamask-previews/assets-controllers": "11.0.1-preview.3dbf14f",
  "@metamask-previews/base-controller": "3.2.0-preview.3dbf14f",
  "@metamask-previews/composable-controller": "3.0.0-preview.3dbf14f",
  "@metamask-previews/controller-utils": "4.3.1-preview.3dbf14f",
  "@metamask-previews/ens-controller": "4.1.0-preview.3dbf14f",
  "@metamask-previews/gas-fee-controller": "6.1.1-preview.3dbf14f",
  "@metamask-previews/keyring-controller": "7.1.0-preview.3dbf14f",
  "@metamask-previews/logging-controller": "1.0.0-preview.3dbf14f",
  "@metamask-previews/message-manager": "7.3.0-preview.3dbf14f",
  "@metamask-previews/network-controller": "12.1.1-preview.3dbf14f",
  "@metamask-previews/notification-controller": "3.1.0-preview.3dbf14f",
  "@metamask-previews/permission-controller": "4.1.0-preview.3dbf14f",
  "@metamask-previews/phishing-controller": "6.0.0-preview.3dbf14f",
  "@metamask-previews/preferences-controller": "4.3.0-preview.3dbf14f",
  "@metamask-previews/rate-limit-controller": "3.0.0-preview.3dbf14f",
  "@metamask-previews/signature-controller": "5.3.0-preview.3dbf14f",
  "@metamask-previews/transaction-controller": "9.0.0-preview.3dbf14f"
}

@jiexi
Copy link
Contributor Author

jiexi commented Sep 5, 2023

@metamaskbot publish-preview

@github-actions
Copy link
Contributor

github-actions bot commented Sep 5, 2023

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/address-book-controller": "3.1.1-preview.b963821",
  "@metamask-previews/announcement-controller": "4.0.1-preview.b963821",
  "@metamask-previews/approval-controller": "3.5.1-preview.b963821",
  "@metamask-previews/assets-controllers": "11.1.0-preview.b963821",
  "@metamask-previews/base-controller": "3.2.1-preview.b963821",
  "@metamask-previews/composable-controller": "3.0.1-preview.b963821",
  "@metamask-previews/controller-utils": "4.3.2-preview.b963821",
  "@metamask-previews/ens-controller": "4.1.1-preview.b963821",
  "@metamask-previews/gas-fee-controller": "6.1.2-preview.b963821",
  "@metamask-previews/keyring-controller": "7.3.0-preview.b963821",
  "@metamask-previews/logging-controller": "1.0.1-preview.b963821",
  "@metamask-previews/message-manager": "7.3.1-preview.b963821",
  "@metamask-previews/name-controller": "0.0.0-preview.b963821",
  "@metamask-previews/network-controller": "12.1.2-preview.b963821",
  "@metamask-previews/notification-controller": "3.1.1-preview.b963821",
  "@metamask-previews/permission-controller": "4.1.1-preview.b963821",
  "@metamask-previews/phishing-controller": "6.0.1-preview.b963821",
  "@metamask-previews/preferences-controller": "4.4.0-preview.b963821",
  "@metamask-previews/rate-limit-controller": "3.0.1-preview.b963821",
  "@metamask-previews/signature-controller": "5.3.1-preview.b963821",
  "@metamask-previews/transaction-controller": "9.2.0-preview.b963821"
}

adonesky1
adonesky1 previously approved these changes Sep 18, 2023
Copy link
Contributor

@adonesky1 adonesky1 left a comment

Choose a reason for hiding this comment

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

LGTM! Would love to get at least one more set of eyes on it before we merge though, cc @Gudahtt @shanejonas @BelfordZ

@cryptotavares cryptotavares requested a review from a team September 19, 2023 09:12
@jiexi
Copy link
Contributor Author

jiexi commented Sep 20, 2023

@metamaskbot publish-preview

@github-actions
Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/address-book-controller": "3.1.1-preview.76bc0ab",
  "@metamask-previews/announcement-controller": "4.0.1-preview.76bc0ab",
  "@metamask-previews/approval-controller": "3.5.1-preview.76bc0ab",
  "@metamask-previews/assets-controllers": "11.1.0-preview.76bc0ab",
  "@metamask-previews/base-controller": "3.2.1-preview.76bc0ab",
  "@metamask-previews/composable-controller": "3.0.1-preview.76bc0ab",
  "@metamask-previews/controller-utils": "4.3.2-preview.76bc0ab",
  "@metamask-previews/ens-controller": "4.1.1-preview.76bc0ab",
  "@metamask-previews/gas-fee-controller": "6.1.2-preview.76bc0ab",
  "@metamask-previews/keyring-controller": "7.4.0-preview.76bc0ab",
  "@metamask-previews/logging-controller": "1.0.1-preview.76bc0ab",
  "@metamask-previews/message-manager": "7.3.1-preview.76bc0ab",
  "@metamask-previews/name-controller": "1.0.0-preview.76bc0ab",
  "@metamask-previews/network-controller": "12.1.2-preview.76bc0ab",
  "@metamask-previews/notification-controller": "3.1.1-preview.76bc0ab",
  "@metamask-previews/permission-controller": "4.1.1-preview.76bc0ab",
  "@metamask-previews/phishing-controller": "6.0.1-preview.76bc0ab",
  "@metamask-previews/preferences-controller": "4.4.0-preview.76bc0ab",
  "@metamask-previews/rate-limit-controller": "3.0.1-preview.76bc0ab",
  "@metamask-previews/selected-network-controller": "1.0.0-preview.76bc0ab",
  "@metamask-previews/signature-controller": "5.3.1-preview.76bc0ab",
  "@metamask-previews/transaction-controller": "10.0.0-preview.76bc0ab"
}

Copy link
Contributor

@adonesky1 adonesky1 left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for pushing through all the confusion with this one!

@jiexi jiexi merged commit c06ea78 into main Sep 25, 2023
103 checks passed
@jiexi jiexi deleted the jl/remove-network-id branch September 25, 2023 18:07
@Gudahtt Gudahtt mentioned this pull request Sep 25, 2023
jiexi added a commit to MetaMask/smart-transactions-controller that referenced this pull request Sep 27, 2023
Wallets shouldn't be directly concerned about the network ID as this more of a p2p concept for gossip. What wallets really care about is chain ID as that is the correct value to use to identify a chain, build transactions, etc. Although these two values usually match (ignoring hex/dec formatting), there are [exceptions](https://medium.com/@pedrouid/chainid-vs-networkid-how-do-they-differ-on-ethereum-eec2ed41635b).

We want to remove usage of `networkId` from the SmartTransactionController.

* Fixes [mmp-1068](MetaMask/MetaMask-planning#1068)
* See: [core-1633](MetaMask/core#1633)
* See: MetaMask/metamask-extension#20652
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
## Explanation

Wallets shouldn't be directly concerned about the network ID as this is
more of a node concept for gossip. What wallets really care about is
chain ID as that is the correct value to use to identify a chain, build
transactions, etc. Although these two values usually match (ignoring
hex/dec formatting), there are
[exceptions](https://medium.com/@pedrouid/chainid-vs-networkid-how-do-they-differ-on-ethereum-eec2ed41635b).

We want to remove `networkId` from the NetworkController state to
encourage the replacement of networkId with chainId in any usage
downstream (extension, mobile, etc). It will still be possible to get
networkId using the rpc client to make a call to the `net_version`
method for cases that truly still rely on it.

## References

* Fixes
[mmp-1068](MetaMask/MetaMask-planning#1068)

## Changelog

### `@metamask/controller-utils`

- **BREAKING**: `NETWORK_ID_TO_ETHERS_NETWORK_NAME_MAP` renamed to
`CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP ` and is now a mapping of `Hex`
chain ID to `BuiltInNetworkName`
- **REMOVED**: `NetworkId` constant and type

### `@metamask/ens-controller`

- **CHANGED**: From Network state, uses `providerConfig.chainId` instead
of `networkId` to determine ENS compatability

### `@metamask/network-controller`

- **REMOVED**: `NetworkId` type
- **REMOVED**:  From `NetworkState` removed `networkId` field
- **CHANGED**: No longer calls `net_version` to determine network status
(only relies on `eth_getBlockByNumber` now)
- **CHANGED**: For Built-in Infura Networks, `net_version` is no longer
locally resolved by the scaffold middleware


### `@metamask/transaction-controller`

- **BREAKING**: Uses `chainId` and `txParams.chainId` to determine if a
`TransactionMeta` object belongs to the current chain. No longer
considers `networkID`
- **BREAKING**: `TransactionMeta.chainId` is now a required field
- **REMOVED**: From `RemoteTransactionSourceRequest` removed
`currentNetworkId` field
- **CHANGED**: From `RemoteTransactionSource` updated
`isSupportedNetwork()` params to exclude networkId
- **DEPRECATED**: `TransactionMeta.networkID` is deprecated and marked
readonly
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
## Explanation

Wallets shouldn't be directly concerned about the network ID as this is
more of a node concept for gossip. What wallets really care about is
chain ID as that is the correct value to use to identify a chain, build
transactions, etc. Although these two values usually match (ignoring
hex/dec formatting), there are
[exceptions](https://medium.com/@pedrouid/chainid-vs-networkid-how-do-they-differ-on-ethereum-eec2ed41635b).

We want to remove `networkId` from the NetworkController state to
encourage the replacement of networkId with chainId in any usage
downstream (extension, mobile, etc). It will still be possible to get
networkId using the rpc client to make a call to the `net_version`
method for cases that truly still rely on it.

## References

* Fixes
[mmp-1068](MetaMask/MetaMask-planning#1068)

## Changelog

### `@metamask/controller-utils`

- **BREAKING**: `NETWORK_ID_TO_ETHERS_NETWORK_NAME_MAP` renamed to
`CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP ` and is now a mapping of `Hex`
chain ID to `BuiltInNetworkName`
- **REMOVED**: `NetworkId` constant and type

### `@metamask/ens-controller`

- **CHANGED**: From Network state, uses `providerConfig.chainId` instead
of `networkId` to determine ENS compatability

### `@metamask/network-controller`

- **REMOVED**: `NetworkId` type
- **REMOVED**:  From `NetworkState` removed `networkId` field
- **CHANGED**: No longer calls `net_version` to determine network status
(only relies on `eth_getBlockByNumber` now)
- **CHANGED**: For Built-in Infura Networks, `net_version` is no longer
locally resolved by the scaffold middleware


### `@metamask/transaction-controller`

- **BREAKING**: Uses `chainId` and `txParams.chainId` to determine if a
`TransactionMeta` object belongs to the current chain. No longer
considers `networkID`
- **BREAKING**: `TransactionMeta.chainId` is now a required field
- **REMOVED**: From `RemoteTransactionSourceRequest` removed
`currentNetworkId` field
- **CHANGED**: From `RemoteTransactionSource` updated
`isSupportedNetwork()` params to exclude networkId
- **DEPRECATED**: `TransactionMeta.networkID` is deprecated and marked
readonly
jiexi added a commit to MetaMask/metamask-extension that referenced this pull request Oct 18, 2023
## Explanation
Wallets shouldn't be directly concerned about the network ID as this
more of a p2p concept for gossip. What wallets really care about is
chain ID as that is the correct value to use to identify a chain, build
transactions, etc. Although these two values usually match (ignoring
hex/dec formatting), there are
[exceptions](https://medium.com/@pedrouid/chainid-vs-networkid-how-do-they-differ-on-ethereum-eec2ed41635b).

We want to remove usage of networkId and replace it with chainId where
appropriate and necessary.

This was a generally straight forward change to make, except for the
following cases:
* `networkVersion` on the `window.ethereum` provider object
* `metamaskNetworkId` on TransactionMeta objects

~~In both cases, we now use static mappings to assist in covering
chainId <-> networkId edge cases.~~ See comments in this PR for more
elaboration and the core PR linked below.

* Fixes
[mmp-1068](MetaMask/MetaMask-planning#1068)
* See: [core-1633](MetaMask/core#1633)
* See: https://github.com/MetaMask/smart-transactions-controller
<!--
Thanks for the pull request. Take a moment to answer these questions so
that reviewers have the information they need to properly understand
your changes:

* What is the current state of things and why does it need to change?
* What is the solution your changes offer and how does it work?

Are there any issues, Slack conversations, Zendesk issues, user stories,
etc. reviewers should consult to understand this pull request better?
For instance:

* Fixes #12345
* See: #67890
-->

## Screenshots/Screencaps

<!-- If you're making a change to the UI, make sure to capture a
screenshot or a short video showing off your work! -->

### Before

<!-- How did the UI you changed look before your changes? Drag your
file(s) below this line: -->

### After

<!-- How does it look now? Drag your file(s) below this line: -->

## Manual Testing Steps

<!--
How should reviewers and QA manually test your changes? For instance:

- Go to this screen
- Do this
- Then do this
-->

## Pre-merge author checklist

- [x] I've clearly explained:
  - [x] What problem this PR is solving
  - [x] How this problem was solved
  - [x] How reviewers can test my changes
- [x] Sufficient automated test coverage has been added

## Pre-merge reviewer checklist

- [x] Manual testing (e.g. pull and build branch, run in browser, test
code being changed)
- [x] PR is linked to the appropriate GitHub issue
- [ ] **IF** this PR fixes a bug in the release milestone, add this PR
to the release milestone

If further QA is required (e.g. new feature, complex testing steps,
large refactor), add the `Extension QA Board` label.

In this case, a QA Engineer approval will be be required.

---------

Co-authored-by: MetaMask Bot <[email protected]>
Co-authored-by: Alex Donesky <[email protected]>
k-g-j pushed a commit to MetaMask/metamask-extension that referenced this pull request Nov 1, 2023
## Explanation
Wallets shouldn't be directly concerned about the network ID as this
more of a p2p concept for gossip. What wallets really care about is
chain ID as that is the correct value to use to identify a chain, build
transactions, etc. Although these two values usually match (ignoring
hex/dec formatting), there are
[exceptions](https://medium.com/@pedrouid/chainid-vs-networkid-how-do-they-differ-on-ethereum-eec2ed41635b).

We want to remove usage of networkId and replace it with chainId where
appropriate and necessary.

This was a generally straight forward change to make, except for the
following cases:
* `networkVersion` on the `window.ethereum` provider object
* `metamaskNetworkId` on TransactionMeta objects

~~In both cases, we now use static mappings to assist in covering
chainId <-> networkId edge cases.~~ See comments in this PR for more
elaboration and the core PR linked below.

* Fixes
[mmp-1068](https://github.com/MetaMask/MetaMask-planning/issues/1068)
* See: [core-1633](MetaMask/core#1633)
* See: https://github.com/MetaMask/smart-transactions-controller
<!--
Thanks for the pull request. Take a moment to answer these questions so
that reviewers have the information they need to properly understand
your changes:

* What is the current state of things and why does it need to change?
* What is the solution your changes offer and how does it work?

Are there any issues, Slack conversations, Zendesk issues, user stories,
etc. reviewers should consult to understand this pull request better?
For instance:

* Fixes #12345
* See: #67890
-->

## Screenshots/Screencaps

<!-- If you're making a change to the UI, make sure to capture a
screenshot or a short video showing off your work! -->

### Before

<!-- How did the UI you changed look before your changes? Drag your
file(s) below this line: -->

### After

<!-- How does it look now? Drag your file(s) below this line: -->

## Manual Testing Steps

<!--
How should reviewers and QA manually test your changes? For instance:

- Go to this screen
- Do this
- Then do this
-->

## Pre-merge author checklist

- [x] I've clearly explained:
  - [x] What problem this PR is solving
  - [x] How this problem was solved
  - [x] How reviewers can test my changes
- [x] Sufficient automated test coverage has been added

## Pre-merge reviewer checklist

- [x] Manual testing (e.g. pull and build branch, run in browser, test
code being changed)
- [x] PR is linked to the appropriate GitHub issue
- [ ] **IF** this PR fixes a bug in the release milestone, add this PR
to the release milestone

If further QA is required (e.g. new feature, complex testing steps,
large refactor), add the `Extension QA Board` label.

In this case, a QA Engineer approval will be be required.

---------

Co-authored-by: MetaMask Bot <[email protected]>
Co-authored-by: Alex Donesky <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants