-
-
Notifications
You must be signed in to change notification settings - Fork 192
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
feat: retrieve global provider and block tracker dynamically #4359
Conversation
Dynamically retrieve selected network client when required. Throw or ignore in all public methods and helpers. Replace helper options with network client.
Cache global nonce tracker after first creation.
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.
@metamask/transactions-controller
tests are failing.
Looking at the existing tests, the existing set up with the block tracker and multiple providers looks s bit weird. |
@@ -293,6 +292,9 @@ export type TransactionControllerOptions = { | |||
getGasFeeEstimates?: ( | |||
options: FetchGasFeeEstimateOptions, | |||
) => Promise<GasFeeState>; | |||
getGlobalProviderAndBlockTracker: () => |
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.
Heads up: We are trying to phase out passing functions to constructors to get information that essentially comes from other controllers. This has always been a legacy pattern, and as we transition controllers fully to BaseController v2, it's better to make use of the messenger system to access information instead.
The globally selected network is captured in NetworkController as the state property selectedNetworkClientId
. This property is guaranteed to be present since a network must always be selected at all times. The combination of provider and block tracker is known as a "network client". Therefore, a more future-looking approach would be to allowlist NetworkController:getState
and NetworkController:getNetworkClientById
for the transaction controller messenger, and then wherever we need to access the network client for the currently selected network, we can say:
const { selectedNetworkClientId } = this.messagingSystem.call('NetworkController:getState');
const networkClient = this.messagingSystem.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
Now we can access networkClient.provider
or networkClient.blockTracker
as needed. They are guaranteed to point to the same network, since they are created at the same time.
Is it possible to use this pattern for this controller?
@dbrans Any progress or blockers here? |
|
Note
Closed: this PR was a commandeer of @matthewwalsh0's #4004. Passing it back to Matt Walsh.
Explanation (by @matthewwalsh0)
Currently the global
provider
andblockTracker
instances are required as constructor options in theTransactionController
.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:provider
andblockTracker
constructor options.getGlobalProviderAndBlockTracker
callback option.blockTracker
,getEthQuery
andchainId
constructor options in the helper classes with a singlegetNetworkClient
option since all the previous values are either all available or all unavailable, meaning the associated validation becomes much simpler.nonceTracker
when first used since it is an alternate package and still requires aprovider
argument.MethodRegistry
instance since it is also an alternate package and requires aprovider
argument.onBootCleanup
logic into the public methodinitApprovedTransactions
so it can be called by the client explicitly when suitable.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