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

COMMANDEERED by #4359: Retrieve global provider and block tracker dynamically #4004

Closed

Conversation

matthewwalsh0
Copy link
Member

@matthewwalsh0 matthewwalsh0 commented Feb 29, 2024

Note

This PR was commandeered by #4359

Explanation

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

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.
pedronfigueiredo added a commit to MetaMask/metamask-extension that referenced this pull request Mar 26, 2024
## **Description**

The temporary solution is to:

- Prevent two network controller requests by:
- Patch the network controller so that the lookup on
initializeProvidercan be avoided.
- Call that initializeProvider with the lookup: false argument right
after the network controller is constructed
- Call await this.networkController.lookupNetwork(); at the end of the
metamask controller if the onboarding has been completed
- Call await this.networkController.lookupNetwork(); once the onboarding
complete state changes
- Prevent one accounts tracker request by:
- Moving the blockTracker event listener from the constructor of the
controller to the start function

The long term solution will be
[#23005](#23005)
(currently blocked by [#4004 on
core](MetaMask/core#4004).


## **Related issues**

Fixes: MetaMask/MetaMask-planning#881

## **Manual testing steps**

1. Add `await new Promise((resolve) => setTimeout(resolve, 10000));` to
the top of initialize on the background.js file
2. Build the app
3. Load extension and immediately open the network tab on the background
console before the app initializes
4. No requests should happen

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**




https://github.com/MetaMask/metamask-extension/assets/7499938/73513327-90fb-4e9f-8af2-aa41c731b647





### **After**



https://github.com/MetaMask/metamask-extension/assets/7499938/d6dee1c6-fa13-48c8-9fe2-520e3d43d0b3



## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've clearly explained what problem this PR is solving and how it
is solved.
- [ ] I've linked related issues
- [ ] I've included manual testing steps
- [ ] I've included screenshots/recordings if applicable
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
- [ ] I’ve properly set the pull request status:
  - [ ] In case it's not yet "ready for review", I've set it to "draft".
- [ ] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

---------

Co-authored-by: Dan J Miller <danjm.com@gmail.com>
pedronfigueiredo added a commit to MetaMask/metamask-extension that referenced this pull request Mar 26, 2024
## **Description**

The temporary solution is to:

- Prevent two network controller requests by:
- Patch the network controller so that the lookup on
initializeProvidercan be avoided.
- Call that initializeProvider with the lookup: false argument right
after the network controller is constructed
- Call await this.networkController.lookupNetwork(); at the end of the
metamask controller if the onboarding has been completed
- Call await this.networkController.lookupNetwork(); once the onboarding
complete state changes
- Prevent one accounts tracker request by:
- Moving the blockTracker event listener from the constructor of the
controller to the start function

The long term solution will be
[#23005](#23005)
(currently blocked by [#4004 on
core](MetaMask/core#4004).


## **Related issues**

Fixes: MetaMask/MetaMask-planning#881

## **Manual testing steps**

1. Add `await new Promise((resolve) => setTimeout(resolve, 10000));` to
the top of initialize on the background.js file
2. Build the app
3. Load extension and immediately open the network tab on the background
console before the app initializes
4. No requests should happen

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**




https://github.com/MetaMask/metamask-extension/assets/7499938/73513327-90fb-4e9f-8af2-aa41c731b647





### **After**



https://github.com/MetaMask/metamask-extension/assets/7499938/d6dee1c6-fa13-48c8-9fe2-520e3d43d0b3



## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've clearly explained what problem this PR is solving and how it
is solved.
- [ ] I've linked related issues
- [ ] I've included manual testing steps
- [ ] I've included screenshots/recordings if applicable
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
- [ ] I’ve properly set the pull request status:
  - [ ] In case it's not yet "ready for review", I've set it to "draft".
- [ ] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

---------

Co-authored-by: Dan J Miller <danjm.com@gmail.com>
pedronfigueiredo added a commit to MetaMask/metamask-extension that referenced this pull request Mar 26, 2024
…) (#23730)

## **Description**

The temporary solution is to:

- Prevent two network controller requests by:
- Patch the network controller so that the lookup on
initializeProvidercan be avoided.
- Call that initializeProvider with the lookup: false argument right
after the network controller is constructed
- Call await this.networkController.lookupNetwork(); at the end of the
metamask controller if the onboarding has been completed
- Call await this.networkController.lookupNetwork(); once the onboarding
complete state changes
- Prevent one accounts tracker request by:
- Moving the blockTracker event listener from the constructor of the
controller to the start function

The long term solution will be
[#23005](#23005)
(currently blocked by [#4004 on
core](MetaMask/core#4004).


## **Related issues**

Fixes: MetaMask/MetaMask-planning#881

## **Manual testing steps**

1. Add `await new Promise((resolve) => setTimeout(resolve, 10000));` to
the top of initialize on the background.js file
2. Build the app
3. Load extension and immediately open the network tab on the background
console before the app initializes
4. No requests should happen

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**





https://github.com/MetaMask/metamask-extension/assets/7499938/73513327-90fb-4e9f-8af2-aa41c731b647





### **After**




https://github.com/MetaMask/metamask-extension/assets/7499938/d6dee1c6-fa13-48c8-9fe2-520e3d43d0b3



## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've clearly explained what problem this PR is solving and how it
is solved.
- [ ] I've linked related issues
- [ ] I've included manual testing steps
- [ ] I've included screenshots/recordings if applicable
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
- [ ] I’ve properly set the pull request status:
  - [ ] In case it's not yet "ready for review", I've set it to "draft".
- [ ] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

---------


<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/23730?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

Co-authored-by: Dan J Miller <danjm.com@gmail.com>
@legobeat
Copy link
Contributor

@matthewwalsh0 @pedronfigueiredo Is this still being pursued?

@pedronfigueiredo
Copy link
Contributor

@legobeat thanks for checking in on this. It has been handed over to the transactions team. More context here: https://consensys.slack.com/archives/C05B78N1T9B/p1714756558259079. cc: @dbrans

@dbrans dbrans self-assigned this May 29, 2024
@dbrans
Copy link
Contributor

dbrans commented Jun 3, 2024

@matthewwalsh0 I'm continuing this PR in #4359

@dbrans dbrans changed the title Retrieve global provider and block tracker dynamically COMMANDEERED by #4359: Retrieve global provider and block tracker dynamically Jun 4, 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.

None yet

4 participants