Conversation
There was a problem hiding this comment.
thoughts? I think we revert these changes
There was a problem hiding this comment.
I think having this controller take a CAIP chain ID makes sense from a consistency perspective. It also means that the consumer has to do less work in order to use it, even for an Ethereum network. However, we could update the constructor to pull the caipChainId from the network state in addition to the networkId and then notset a provider if it's not an Ethereum chain ID. This wouldn't prevent consumers from using set, get, etc., but they wouldn't do anything, because reverseResolveAddress wouldn't do anything, either. So, I feel like these changes are okay. What are your thoughts?
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
packages/network-controller/src/create-auto-managed-network-client.test.ts
Show resolved
Hide resolved
|
Needs to be a breaking changelog entry indicating that |
| NetworkId, | ||
| InfuraNetworkId, | ||
| NetworkType | ||
| > = { | ||
| [NetworkId.goerli]: NetworkType.goerli, | ||
| [NetworkId.sepolia]: NetworkType.sepolia, | ||
| [NetworkId.mainnet]: NetworkType.mainnet, | ||
| [NetworkId['linea-goerli']]: NetworkType['linea-goerli'], | ||
| [NetworkId['linea-mainnet']]: NetworkType['linea-mainnet'], | ||
| [InfuraNetworkId.goerli]: NetworkType.goerli, | ||
| [InfuraNetworkId.sepolia]: NetworkType.sepolia, | ||
| [InfuraNetworkId.mainnet]: NetworkType.mainnet, | ||
| [InfuraNetworkId['linea-goerli']]: NetworkType['linea-goerli'], | ||
| [InfuraNetworkId['linea-mainnet']]: NetworkType['linea-mainnet'], |
There was a problem hiding this comment.
What was the reason for this change? How does it relate to the CAIP-2 migration?
There was a problem hiding this comment.
Oh I see the name just changed for the type
There was a problem hiding this comment.
correct. unrelated to CAIP, but wanted to help disambiguate NetworkId and ChainId more by this naming. Happy to revert though
|
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
There was a problem hiding this comment.
Did a pass over this. I noticed some questions you asked in code comments as I was going over this and it's possible I didn't catch all of them. I will do another pass later.
One thing that stood out to me, though, was that we are renaming chainId across various pieces of state and configuration, and I wonder whether that is a good idea, or whether it would just be enough to change the names of the types. My concern is that this would spawn a ton of changes across extension and mobile when upgrading to newer versions of these packages (changing the names of the types will spawn enough changes as it is). The more changes we have to make, the more we risk introducing a bug.
So, I'm curious about the reasoning/context. Was it just to hammer home the fact that this is a CAIP chain ID and not a "legacy" chain ID? Was it to ensure that consumers are using the correct chain ID when they upgrade? My understanding is that we are moving to a world in which chain ID always means CAIP-2 chain ID, so when that happens, eventually the "Caip" part of the name will become redundant. But, are we at a point where we can't guarantee that a chain ID is always a CAIP-2 chain ID?
| * @property address - Hex address of a recipient account | ||
| * @property name - Nickname associated with this address | ||
| * @property chainId - Chain id identifies the current chain | ||
| * @property caipChainId - CAIP chain ID identifies the current chain |
There was a problem hiding this comment.
Nit: Since we're already saying "identifies" I wonder if we can make this a little more succinct:
| * @property caipChainId - CAIP chain ID identifies the current chain | |
| * @property caipChainId - CAIP-2 identifier for the current chain |
| "@metamask/base-controller": "workspace:^", | ||
| "@metamask/controller-utils": "workspace:^", | ||
| "@metamask/utils": "^6.2.0" | ||
| "@metamask/utils": "^7.1.0" |
There was a problem hiding this comment.
Should we note this in the changelog?
| "dependencies": { | ||
| "@metamask/base-controller": "workspace:^", | ||
| "@metamask/utils": "^6.2.0", | ||
| "@metamask/utils": "^7.1.0", |
There was a problem hiding this comment.
Should we note this in the changelog?
| "@metamask/preferences-controller": "workspace:^", | ||
| "@metamask/rpc-errors": "^5.1.1", | ||
| "@metamask/utils": "^6.2.0", | ||
| "@metamask/utils": "^7.1.0", |
There was a problem hiding this comment.
Should we note this in the changelog?
| import { toHex } from './util'; | ||
|
|
||
| /** | ||
| * Checks whether the given value is a valid CAIP chain ID string for Ethereum. |
There was a problem hiding this comment.
Isn't a CAIP chain ID always a string? If so I wonder whether this would still be understandable:
| * Checks whether the given value is a valid CAIP chain ID string for Ethereum. | |
| * Checks whether the given value is a valid CAIP chain ID for Ethereum. |
| "dependencies": { | ||
| "@metamask/base-controller": "workspace:^", | ||
| "@metamask/utils": "^6.2.0", | ||
| "@metamask/utils": "^7.1.0", |
There was a problem hiding this comment.
Should we note this in the changelog?
| "@metamask/base-controller": "workspace:^", | ||
| "@metamask/controller-utils": "workspace:^", | ||
| "@metamask/utils": "^6.2.0", | ||
| "@metamask/utils": "^7.1.0", |
There was a problem hiding this comment.
Should we note this in the changelog?
| "@metamask/controller-utils": "workspace:^", | ||
| "@metamask/message-manager": "workspace:^", | ||
| "@metamask/utils": "^6.2.0", | ||
| "@metamask/utils": "^7.1.0", |
There was a problem hiding this comment.
Should we note this in the changelog?
| "@metamask/eth-query": "^3.0.1", | ||
| "@metamask/network-controller": "workspace:^", | ||
| "@metamask/utils": "^6.2.0", | ||
| "@metamask/utils": "^7.1.0", |
There was a problem hiding this comment.
Should we note this in the changelog?
| const key = `${transaction.nonce}-${ | ||
| chainId ? convertHexToDecimal(chainId) : networkID | ||
| }-${new Date(time).toDateString()}`; | ||
| const networkChainId = caipChainId || networkID; // is this right? |
There was a problem hiding this comment.
It might be good to keep the same behavior and convert the CAIP chain ID to decimal so that keys for existing transactions are the same. Otherwise transactions that are already in state might get accidentally dropped.
There was a problem hiding this comment.
(Side note: it might be good to ask these questions in GitHub comments rather than code comments so they don't get accidentally committed.)
|
Postponed. Not sure if/when will be picked back up. |
Explanation
chainIdtocaipChainIdSee: MetaMask/utils#116
See: MetaMask/metamask-extension#19991
References
Changelog
NOTE: field change from
chainIdtocaipChainId(or_CHAIN_IDto_CAIP_CHAIN_ID) also implies type change fromHextoCaipChainId@metamask/address-book-controllerthis.state.addressBookis now keyed byCaipChainIdinstead ofHexthis.state.addressBook[CaipChainId][address].chainIdfield changed tocaipChainIdset()defaults thecaipChainIdarg (previouslychainId) toeip155:1@metamask/assets-controllers/AssetsContractControlleroptions.chainIdto beoptions.caipChainIdformatIconUrlWithProxy()expectsparams.chainIdto beparams.caipChainIdisTokenDetectionSupportedForNetworkexpectschainIdarg to becaipChainId@metamask/assets-controllers/AssetsContractControlleroptions.chainIdto beoptions.caipChainId@metamask/assets-controllers/NFTControlleroptions.chainIdto beoptions.caipChainIdthis.state. allNftContracts[userAddress]is now keyed byCaipChainIdinstead ofHexthis.state. allNfts[userAddress]is now keyed byCaipChainIdinstead ofHexupdateNestedNftState()expectspassedConfig.chainIdto bepassedConfig.caipChainIdonNetworkStateChange()expectsproviderConfig.chainIdto beproviderConfig.caipChainIdaddNft()expectsaccountParams.chainIdto now beaccountParams.caipChainIdcheckAndUpdateSingleNftOwnershipStatus()expectsaccountParams.chainIdto beaccountParams.caipChainIdfindNftByAddressAndTokenId()expectschainIdarg to now becaipChainIdupdateNft()expectschainIdarg to becaipChainIdresetNftTransactionStatusByTransactionId()expectschainIdarg to becaipChainId@metamask/assets-controllers/NFTDetectionControlleroptions.chainIdto beoptions.caipChainId@metamask/assets-controllers/TokenDetectionControlleroptions.chainIdto beoptions.caipChainIdonNetworkStateChange()expectsproviderConfig.chainIdto beproviderConfig.caipChainId@metamask/assets-controllers/TokenListControlleroptions.chainIdto beoptions.caipChainIdonNetworkStateChange()expectsproviderConfig.chainIdto beproviderConfig.caipChainIdthis.state.tokensChainsCacheis now keyed byCaipChainIdinstead ofHex@metamask/assets-controllers/TokensRatesControlleroptions.chainIdto beoptions.caipChainIdonNetworkStateChange()expectsproviderConfig.chainIdto now beproviderConfig.caipChainIdfindChainSlug()expectschainIdarg to now becaipChainIdthis.chainIdchanged tothis.caipChainId@metamask/assets-controllers/TokensControlleroptions.chainIdto beoptions.caipChainIdonNetworkStateChange()expectsproviderConfig.chainIdto now beproviderConfig.caipChainIdthis.state. allTokensis now keyed byCaipChainIdinstead ofHexthis.state.allIgnoredTokensis now keyed byCaipChainIdinstead ofHexthis.state.allDetectedTokensis now keyed byCaipChainIdinstead ofHexaddDetectedTokens()expectsdetectionDetails.chainIdto now bedetectionDetails.caipChainId@metamask/controller-utilsisEthCaipChainId()expects any value and returns true if the value is a valid CaipChainId with namespaceeip155toEthCaipChainId()expects decimal or 0x prefixed hex string and returnsCaipChainIdtoEthChainId()expects CaipChainId and returns reference as decimal stringtoEthChainIdHex()expects CaipChainId and returns reference as 0x prefixed hex stringtoEthChainIdInt()expects CaipChainId and returns reference as numberGANACHE_CHAIN_IDchanged toGANACHE_CAIP_CHAIN_IDBUILT_IN_NETWORKS[networkType].chainIdfield is nowcaipChainIdChainId(hex values) changed toBuiltInCaipChainIdNetworkIdrenamed toInfuraNetworkId@metamask/ens-controller@metamask/gas-fee-controlleroptions.getChainId()to beoptions.getCaipChainId()onNetworkStateChange()expectsproviderConfig.chainIdto now beproviderConfig.caipChainIdthis.messagingSystem.call('NetworkController:getState')expectsproviderConfig.chainIdto now beproviderConfig.caipChainId@metamask/message-manager/AbstractMessageManageroptions.getCurrentChainId()to beoptions.getCurrentCaipChainId()@metamask/message-manager/TypedMessageManageroptions.getCurrentChainId()to beoptions.getCurrentCaipChainId()@metamask/network-controllerProviderConfig.chainIdchanged toProviderConfig.caipChainIdNetworkConfiguration.chainIdchanged toNetworkConfiguration.caipChainIdthis.state.providerConfig.chainIdchanged tothis.state.providerConfig.caipChainId@metamask/signature-controlleroptions.getCurrentChainId()to beoptions.getCurrentCaipChainId()@metamask/transaction-controllerTransaction.chainIdchanged toTransaction.caipChainIdchanged tooptions.getNetworkState()to return to includeproviderConfig.caipChainIdinstead ofproviderConfig.chainIdChecklist