Skip to content

Support optional networkClientId in usePPOM()#85

Closed
jiexi wants to merge 16 commits intomainfrom
jl/use-networkClientId-3
Closed

Support optional networkClientId in usePPOM()#85
jiexi wants to merge 16 commits intomainfrom
jl/use-networkClientId-3

Conversation

@jiexi
Copy link
Member

@jiexi jiexi commented Nov 8, 2023

  • onNetworkChange now updates state.chainStatus for networkState.providerConfig.chaindId and each network configuration in networkState.networkConfigurations
  • usePPOM() now accepts an optional networkClientId as the last param which will be used to override the default chainId and provider
  • PPOM Messenger now needs permission to call NetworkController:getNetworkClientById

@jiexi jiexi requested a review from a team as a code owner November 8, 2023 18:54
@socket-security
Copy link

New dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
@metamask/controller-utils 5.0.2 None +39 8.58 MB metamaskbot

@socket-security
Copy link

socket-security bot commented Nov 8, 2023

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

Ignoring: @spruceid/siwe-parser@1.1.3, setimmediate@1.0.5, bs58@4.0.1, ripemd160@2.0.2, md5.js@1.3.5, rlp@2.2.7

Next steps

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of package-name@version specifiers. e.g. @SocketSecurity ignore foo@1.0.0 bar@* or ignore all packages with @SocketSecurity ignore-all

jiexi and others added 2 commits November 8, 2023 15:59
Co-authored-by: Jongsun Suh <jongsun.suh@icloud.com>
Co-authored-by: Jongsun Suh <jongsun.suh@icloud.com>
);
this.#deleteOldChainIds();
this.#checkScheduleFileDownloadForAllChains();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

this.#updateChainStatus should be called for all chains recently seen, also I think should we called for chainId in usePPOM

Copy link
Member Author

Choose a reason for hiding this comment

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

What does "recently seen" mean here?

Copy link
Member Author

Choose a reason for hiding this comment

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

updateChainStatus in usePPOM added here 383b860

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also wondering if there is a callback in network controller now which can be used to add networks to chainStatus as soon as user connects to it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not from the network controller. Connecting to a network really just means that the network is permissioned for a certain dapp(s). Maybe we could get this from the PermissionsController?

Choose a reason for hiding this comment

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

Hey @jpuri I think we may need to talk through a better way to identify a chain status since as Jiexi said above, in the upcoming multichain API

Connecting to a network really just means that the network is permissioned for a certain dapp(s)

if chainStatus is used to determine whether an incoming request might come for that chain we can't rely on "connection" status since it is really just has a dapp been granted permission to interact with that chain. This is very different from how it works now where we just permission accounts and then the user can "connect" to whatever chain and the dapp automatically gets "connected" to that chain. Long run we need to be able to serve requests that come from any of the "permissioned" chains many of which may not actually be active. So we should think of some protocol for warming up a given chain status when a first RPC request comes in for that chain and pausing any updates when it has been inactive for a while.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In chainStatus we cache data for a chain so that for repeated requests we have it in cache, it is useful to add network to chainStatus as soon as user start interacting with it so that we have the data cache ready to be used when transaction is submitted.

Is there a way for us to identify when a user opens a DAPP connected to any chainId ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we could do this. That would mean going from connections -> origin -> networkClientId -> chainId and passing that to PPOM.

Can we tackle this as part of a separate PR?

Copy link

@adonesky1 adonesky1 Nov 28, 2023

Choose a reason for hiding this comment

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

Can we tackle this as part of a separate PR?

const chainId = addHexPrefix(networkConfig.chainId);
this.#updateChainStatus(chainId);
},
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

We want to cache files only for recently visited networks (visited in past 1 week)

Copy link
Member Author

Choose a reason for hiding this comment

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

what exactly does "visited" mean here? sounds like you don't consider a network "visited" just because it shows up in the list of added networks. Does that mean "visited" is only true for the selected chain and any chains used inside usePPOM()?

Copy link
Collaborator

Choose a reason for hiding this comment

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

lastVisited is the time network was last visited. We fetch files only for networks visited in last 1 week. If we fetch files for all possible networks it will be too many files.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If we can know when user connects to a new network we can add it to chainStatus it will be useful as it will also give chance to download network files before transaction comes.

@jiexi
Copy link
Member Author

jiexi commented Nov 13, 2023

@SocketSecurity ignore setimmediate@1.0.5
@SocketSecurity ignore bs58@4.0.1
@SocketSecurity ignore ripemd160@2.0.2
@SocketSecurity ignore md5.js@1.3.5

unmaintained

@jiexi
Copy link
Member Author

jiexi commented Nov 13, 2023

@SocketSecurity ignore @spruceid/siwe-parser@1.1.3

The github repo itself has a README and has almost 1k stars

@jiexi
Copy link
Member Author

jiexi commented Nov 13, 2023

@SocketSecurity ignore rlp@2.2.7

ralxz has contributed to numerous ethereumjs projects already

@MajorLift
Copy link
Contributor

I added some any fixes here: #89.
Most importantly, it applies the Provider type from @metamask/network-controller.

Comment on lines +34 to +36
"@metamask/base-controller": "^3.2.1",
"@metamask/controller-utils": "^5.0.0",
"@metamask/network-controller": "^15.2.0",

Choose a reason for hiding this comment

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

[nit] Not strictly necessary but all of these have newer versions available now.

@mcmire
Copy link
Collaborator

mcmire commented Nov 29, 2023

Hi, just checking in — what's the status of this PR? Is this waiting on further review?

@mcmire
Copy link
Collaborator

mcmire commented Jan 18, 2024

@jpuri @jiexi Do we know if this PR is necessary anymore? I notice that #130 got merged recently, so I don't know if that was intended to replace this, or if this PR addresses something else.

@jiexi jiexi closed this Mar 27, 2024
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