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

Behavior for NetworkController.findNetworkClientIdByChainId method/action is potentially surprising if more than one network has same chain ID #3686

Open
mcmire opened this issue Dec 19, 2023 · 7 comments · May be fixed by #5344
Assignees
Labels
bug Something isn't working team-wallet-framework

Comments

@mcmire
Copy link
Contributor

mcmire commented Dec 19, 2023

This method returns the network client that hits the chain with the given identifier. This is a problem because more than one network client can be assigned to the same chain ID. This method just returns the first one that matches, but that may not be the network client that the consumer expected, especially if the user has added a custom network that overrides a built-in one (for instance, Mainnet).

@Gudahtt
Copy link
Member

Gudahtt commented Dec 20, 2023

We intentionally mirrored the behavior of wallet_switchEthereumChain when implementing this. It prefers built-in networks first, and second to that it prefers older configurations to newer ones.

I wouldn't call it undefined, but it's certainly not a reasonable solution. For wallet_switchEthereumChain, I believe the plan was to update the UI to let the user choose a specific RPC endpoint. I'm not sure what other cases exist though, that solution might not be applicable to all of them.

@mcmire mcmire changed the title Behavior for NetworkController.findNetworkClientIdByChainId method/action is undefined if more than one network has same chain ID Behavior for NetworkController.findNetworkClientIdByChainId method/action is potentially surprising if more than one network has same chain ID Jan 3, 2024
@mcmire
Copy link
Contributor Author

mcmire commented Jan 3, 2024

Right, it's coming back to me now, thanks for the pointer on that. I've updated the PR title to be more accurate.

The reason I'm bringing up this method is that now that it's part of the public API, we might be tempted to use it in order to get from chain ID to network client ID (in fact I've seen it pop up in a PR recently). The existence of this method implies that there is a one-to-one mapping between chain ID and network client ID, but that's not true at all. So it's a pretty big footgun — but you wouldn't know it if you just stumbled across this.

Considering that we had to create this for wallet_switchEthereumChain, but this is the only use case, I'm wondering if we should make this method intentionally difficult to use somehow — push this on to the consumer. Or at least we should rename this method so that people understand it's not safe to use.

@Gudahtt
Copy link
Member

Gudahtt commented Jan 3, 2024

We can mark it as deprecated, that would work as a warning against using it

@mcmire
Copy link
Contributor Author

mcmire commented Oct 24, 2024

This issue is still relevant, and I would mark it as a defect that we need to rectify. The Wallet API team can still use this method but I agree with deprecating it so that people do not use it long-term.

@desi
Copy link
Contributor

desi commented Nov 14, 2024

We believe we can fix the method now rather than deprecate it.

@desi
Copy link
Contributor

desi commented Nov 14, 2024

This might impact work on the Assets team.

@mcmire
Copy link
Contributor Author

mcmire commented Nov 19, 2024

For more details on how we can fix the method, we can now:

  • look up a network configuration with the given chain ID
  • use the defaultRpcEndpointIndex to find the default RPC endpoint for that network configuration
  • get the network client ID for that RPC endpoint
  • look up the network client with that ID

@mcmire mcmire added the bug Something isn't working label Feb 14, 2025
@mcmire mcmire linked a pull request Feb 14, 2025 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working team-wallet-framework
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants