core icon indicating copy to clipboard operation
core copied to clipboard

feat: retrieve global provider and block tracker dynamically

Open dbrans opened this issue 1 year ago • 1 comments

[!NOTE] This PR is a commandeer of @matthewwalsh0's https://github.com/MetaMask/core/pull/4004.

This PR has been deprioritized. We are coordinating with the multichain team to figure out the best time to address it.

Explanation (by @matthewwalsh0)

Currently the global provider and blockTracker instances are required as constructor options in the TransactionController.

This means the clients must have the global provider available when the controller instance is created, usually on startup.

In order to support construction of the TransactionController before these are available, to facilitate use cases such as disabling provider access until onboarding is complete, this PR does the following:

  • Removes the provider and blockTracker constructor options.
  • Adds the getGlobalProviderAndBlockTracker callback option.
  • Updates all usages of the global network to retrieve the network client dynamically when required.
  • Updates all relevant public methods and helper classes to either gracefully ignore a missing network client, or throw an error.
  • Replace the blockTracker, getEthQuery and chainId constructor options in the helper classes with a single getNetworkClient option since all the previous values are either all available or all unavailable, meaning the associated validation becomes much simpler.
  • Dynamically create the global nonceTracker when first used since it is an alternate package and still requires a provider argument.
  • Dynamically create the MethodRegistry instance since it is also an alternate package and requires a provider argument.
  • Move the onBootCleanup logic into the public method initApprovedTransactions so it can be called by the client explicitly when suitable.
  • Fix logger used by MultichainTrackingHelper.

Note that any additional complexity or logic surrounding the global network specifically is temporary and can be removed once the clients enable the multichain flag, at which point all network clients and helpers will be dynamically synchronised with the NetworkController state.

Changelog

@metamask/transaction-controller

[PENDING]

Checklist

  • [ ] I've updated the test suite for new or updated code as appropriate
  • [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • [ ] I've highlighted breaking changes using the "BREAKING" category above as appropriate

dbrans avatar Jun 03 '24 13:06 dbrans

Looking at the existing tests, the existing set up with the block tracker and multiple providers looks s bit weird.

  • #4345

legobeat avatar Jun 04 '24 19:06 legobeat

@dbrans Any progress or blockers here?

legobeat avatar Jul 12 '24 00:07 legobeat

  • Closing this PR in favor on #4004

dbrans avatar Jul 30 '24 14:07 dbrans