Skip to content

Conversation

@jiexi
Copy link
Contributor

@jiexi jiexi commented Aug 29, 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.

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.

Screenshots/Screencaps

Before

After

Manual Testing Steps

Pre-merge author checklist

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

Pre-merge reviewer checklist

  • Manual testing (e.g. pull and build branch, run in browser, test code being changed)
  • 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.

@github-actions
Copy link
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.

@socket-security
Copy link

socket-security bot commented Aug 30, 2023

Updated and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
@metamask/selected-network-controller 1.0.0...2.0.1 None +0/-1 27.3 kB metamaskbot

🚮 Removed packages: @metamask/network-controller@12.2.0

@jiexi jiexi added the team-wallet-api-platform-deprecated DEPRECATED: please use "team-wallet-integrations" instead label Aug 30, 2023
@jiexi
Copy link
Contributor Author

jiexi commented Aug 30, 2023

@metamaskbot update-policies

@metamaskbot
Copy link
Collaborator

Policies updated

@codecov
Copy link

codecov bot commented Aug 30, 2023

Codecov Report

Attention: 19 lines in your changes are missing coverage. Please review.

Comparison is base (fd84e8b) 68.54% compared to head (34fe4b8) 68.54%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #20652      +/-   ##
===========================================
+ Coverage    68.54%   68.54%   +0.01%     
===========================================
  Files         1029     1030       +1     
  Lines        41013    41037      +24     
  Branches     10963    10968       +5     
===========================================
+ Hits         28109    28128      +19     
- Misses       12904    12909       +5     
Files Coverage Δ
app/scripts/controllers/ens/ens.js 78.95% <100.00%> (+1.17%) ⬆️
app/scripts/controllers/ens/index.js 80.77% <100.00%> (+0.77%) ⬆️
app/scripts/controllers/swaps.js 81.14% <100.00%> (ø)
...s/transactions/EtherscanRemoteTransactionSource.ts 89.74% <100.00%> (ø)
...trollers/transactions/IncomingTransactionHelper.ts 93.97% <100.00%> (-0.20%) ⬇️
app/scripts/controllers/transactions/index.js 73.02% <100.00%> (+0.22%) ⬆️
...ripts/controllers/transactions/tx-state-manager.js 92.00% <100.00%> (-0.27%) ⬇️
app/scripts/lib/setupSentry.js 41.07% <ø> (ø)
app/scripts/migrations/101.ts 100.00% <100.00%> (ø)
app/scripts/migrations/index.js 100.00% <ø> (ø)
... and 17 more

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

@metamaskbot
Copy link
Collaborator

Builds ready [3b40e6b]
Page Load Metrics (1568 ± 94 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1071831272210
domContentLoaded14122125156619292
load14122151156819594
domInteractive14122124156619192
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -926 Bytes (-0.03%)
  • ui: -801 Bytes (-0.01%)
  • common: -1.33 KiB (-0.03%)

@jiexi
Copy link
Contributor Author

jiexi commented Sep 5, 2023

We expose networkVersion on the provider via window.ethereum.networkVersion. As always, since this has been exposed to the world, some dapps may rely on it. EIP1193 does not specify exposing this as a requirement of spec. We have a few options:

  1. Remove it. This is a breaking change, but can be worked around by making an async net_version request
  2. Keep it. We still need to make the request for net_version ourselves.
  3. We can do that in MetaMaskController (cache it, making only one request per chain change event) OR
  4. We can keep NetworkController.networkId around, but rename it to deprecatedNetworkId to make it very obvious developers should not be using it internally, and of course we will keep the changes in this PR that actual replace/remove its usage in extension

EDIT: Opting for a mix of 3 and 4. Exposed NetworkController.deprecatedGetNetworkId and will use it to fetch and cache the networkId value used in metamask_chainChanged events in MetaMaskController

EDIT2: See below

@pedronfigueiredo
Copy link
Contributor

Should we include a migration to remove networkId from the NetworkController state?

@adonesky1
Copy link
Contributor

@metamaskbot update-policies

@metamaskbot
Copy link
Collaborator

Policies updated

@jiexi
Copy link
Contributor Author

jiexi commented Oct 17, 2023

@metamaskbot update-policies

@metamaskbot
Copy link
Collaborator

Policies updated

@jiexi
Copy link
Contributor Author

jiexi commented Oct 17, 2023

Should we include a migration to remove networkId from the NetworkController state?

Yeah, we should be tidy. My bad. Added here: 1c3bb66

@jiexi jiexi force-pushed the jl/remove-network-id branch from 7371e74 to 8979f84 Compare October 17, 2023 22:42
@jiexi jiexi force-pushed the jl/remove-network-id branch from 8979f84 to bb46c3e Compare October 17, 2023 23:23
@metamaskbot
Copy link
Collaborator

Builds ready [34fe4b8]
Page Load Metrics (1040 ± 371 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint85122103126
domContentLoaded7111993157
load8218141040772371
domInteractive7111993157
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 178.03 KiB (4.63%)
  • ui: -1.3 KiB (-0.02%)
  • common: -102.71 KiB (-2.08%)

@jiexi
Copy link
Contributor Author

jiexi commented Oct 18, 2023

I guess this assumes that all chains support chain IDs? I mean they ought to, but is there any reason why we shouldn't do this?

All EVM chains support chain ID. I'm unsure of other chains. I can't think of a good reason not to do this besides not changing things if they aren't broken. This doesn't buy us any new features, just cleans up some tech debt

"@metamask/safe-event-emitter": "^2.0.0",
"@metamask/scure-bip39": "^2.0.3",
"@metamask/selected-network-controller": "^1.0.0",
"@metamask/selected-network-controller": "^2.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] Just curious, is this required for this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

selected-network-controller v1.0.0 had a peerDep of network-controller ^12.1.2.

v2.0.0 has a peerDep of 13

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. Obviously a ton of the same little changes here so hard to feel super confident without spending many hours pouring over each one in context. So hoping we can get at least a few more sets of eyes and some thorough QA done before we merge this.

@adonesky1 adonesky1 requested a review from tmashuang October 18, 2023 19:42
@adonesky1
Copy link
Contributor

@tmashuang do you have some bandwidth to give this a thorough QA?

@jiexi jiexi removed the needs-qa Label will automate into QA workspace label Oct 18, 2023
@jiexi
Copy link
Contributor Author

jiexi commented Oct 18, 2023

Thomas and I took another pass on this. I think we're good on the QA side

@jiexi jiexi merged commit 703f4ba into develop Oct 18, 2023
@jiexi jiexi deleted the jl/remove-network-id branch October 18, 2023 21:03
@github-actions github-actions bot locked and limited conversation to collaborators Oct 18, 2023
@metamaskbot metamaskbot added the release-11.5.0 Issue or pull request that will be included in release 11.5.0 label Oct 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-11.5.0 Issue or pull request that will be included in release 11.5.0 team-extension-platform Extension Platform 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