-
-
Notifications
You must be signed in to change notification settings - Fork 206
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
CAIP-2 Chain ID #1489
CAIP-2 Chain ID #1489
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thoughts? I think we revert these changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the reason for this change? How does it relate to the CAIP-2 migration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see the name just changed for the type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
@@ -34,15 +33,15 @@ export enum AddressType { | |||
* AddressBookEntry representation | |||
* @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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
@@ -31,7 +31,7 @@ | |||
"dependencies": { | |||
"@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we note this in the changelog?
@@ -30,7 +30,7 @@ | |||
}, | |||
"dependencies": { | |||
"@metamask/base-controller": "workspace:^", | |||
"@metamask/utils": "^6.2.0", | |||
"@metamask/utils": "^7.1.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we note this in the changelog?
@@ -43,7 +43,7 @@ | |||
"@metamask/network-controller": "workspace:^", | |||
"@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
@@ -30,7 +30,7 @@ | |||
}, | |||
"dependencies": { | |||
"@metamask/base-controller": "workspace:^", | |||
"@metamask/utils": "^6.2.0", | |||
"@metamask/utils": "^7.1.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we note this in the changelog?
@@ -32,7 +32,7 @@ | |||
"@metamask/approval-controller": "workspace:^", | |||
"@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we note this in the changelog?
@@ -33,7 +33,7 @@ | |||
"@metamask/base-controller": "workspace:^", | |||
"@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we note this in the changelog?
@@ -36,7 +36,7 @@ | |||
"@metamask/controller-utils": "workspace:^", | |||
"@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(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
chainId
tocaipChainId
See: MetaMask/utils#116
See: MetaMask/metamask-extension#19991
References
Changelog
NOTE: field change from
chainId
tocaipChainId
(or_CHAIN_ID
to_CAIP_CHAIN_ID
) also implies type change fromHex
toCaipChainId
@metamask/address-book-controller
this.state.addressBook
is now keyed byCaipChainId
instead ofHex
this.state.addressBook[CaipChainId][address].chainId
field changed tocaipChainId
set()
defaults thecaipChainId
arg (previouslychainId
) toeip155:1
@metamask/assets-controllers/AssetsContractController
options.chainId
to beoptions.caipChainId
formatIconUrlWithProxy()
expectsparams.chainId
to beparams.caipChainId
isTokenDetectionSupportedForNetwork
expectschainId
arg to becaipChainId
@metamask/assets-controllers/AssetsContractController
options.chainId
to beoptions.caipChainId
@metamask/assets-controllers/NFTController
options.chainId
to beoptions.caipChainId
this.state. allNftContracts[userAddress]
is now keyed byCaipChainId
instead ofHex
this.state. allNfts[userAddress]
is now keyed byCaipChainId
instead ofHex
updateNestedNftState()
expectspassedConfig.chainId
to bepassedConfig.caipChainId
onNetworkStateChange()
expectsproviderConfig.chainId
to beproviderConfig.caipChainId
addNft()
expectsaccountParams.chainId
to now beaccountParams.caipChainId
checkAndUpdateSingleNftOwnershipStatus()
expectsaccountParams.chainId
to beaccountParams.caipChainId
findNftByAddressAndTokenId()
expectschainId
arg to now becaipChainId
updateNft()
expectschainId
arg to becaipChainId
resetNftTransactionStatusByTransactionId()
expectschainId
arg to becaipChainId
@metamask/assets-controllers/NFTDetectionController
options.chainId
to beoptions.caipChainId
@metamask/assets-controllers/TokenDetectionController
options.chainId
to beoptions.caipChainId
onNetworkStateChange()
expectsproviderConfig.chainId
to beproviderConfig.caipChainId
@metamask/assets-controllers/TokenListController
options.chainId
to beoptions.caipChainId
onNetworkStateChange()
expectsproviderConfig.chainId
to beproviderConfig.caipChainId
this.state.tokensChainsCache
is now keyed byCaipChainId
instead ofHex
@metamask/assets-controllers/TokensRatesController
options.chainId
to beoptions.caipChainId
onNetworkStateChange()
expectsproviderConfig.chainId
to now beproviderConfig.caipChainId
findChainSlug()
expectschainId
arg to now becaipChainId
this.chainId
changed tothis.caipChainId
@metamask/assets-controllers/TokensController
options.chainId
to beoptions.caipChainId
onNetworkStateChange()
expectsproviderConfig.chainId
to now beproviderConfig.caipChainId
this.state. allTokens
is now keyed byCaipChainId
instead ofHex
this.state.allIgnoredTokens
is now keyed byCaipChainId
instead ofHex
this.state.allDetectedTokens
is now keyed byCaipChainId
instead ofHex
addDetectedTokens()
expectsdetectionDetails.chainId
to now bedetectionDetails.caipChainId
@metamask/controller-utils
isEthCaipChainId()
expects any value and returns true if the value is a valid CaipChainId with namespaceeip155
toEthCaipChainId()
expects decimal or 0x prefixed hex string and returnsCaipChainId
toEthChainId()
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_ID
changed toGANACHE_CAIP_CHAIN_ID
BUILT_IN_NETWORKS[networkType].chainId
field is nowcaipChainId
ChainId
(hex values) changed toBuiltInCaipChainId
NetworkId
renamed toInfuraNetworkId
@metamask/ens-controller
@metamask/gas-fee-controller
options.getChainId()
to beoptions.getCaipChainId()
onNetworkStateChange()
expectsproviderConfig.chainId
to now beproviderConfig.caipChainId
this.messagingSystem.call('NetworkController:getState')
expectsproviderConfig.chainId
to now beproviderConfig.caipChainId
@metamask/message-manager/AbstractMessageManager
options.getCurrentChainId()
to beoptions.getCurrentCaipChainId()
@metamask/message-manager/TypedMessageManager
options.getCurrentChainId()
to beoptions.getCurrentCaipChainId()
@metamask/network-controller
ProviderConfig.chainId
changed toProviderConfig.caipChainId
NetworkConfiguration.chainId
changed toNetworkConfiguration.caipChainId
this.state.providerConfig.chainId
changed tothis.state.providerConfig.caipChainId
@metamask/signature-controller
options.getCurrentChainId()
to beoptions.getCurrentCaipChainId()
@metamask/transaction-controller
Transaction.chainId
changed toTransaction.caipChainId
changed tooptions.getNetworkState()
to return to includeproviderConfig.caipChainId
instead ofproviderConfig.chainId
Checklist