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

refactor: use block tracker to poll incoming transactions #6998

Merged
merged 6 commits into from
Aug 22, 2023

Conversation

matthewwalsh0
Copy link
Member

@matthewwalsh0 matthewwalsh0 commented Aug 16, 2023

Description

Currently the mobile client uses a version of the core TransactionController where incoming transactions are polled on request via a fetchAll method called from the frontend in a polling loop and explicitly on events such as the network changing.

In addition, the client is currently responsible for specifying what block number to search from and therefore is also responsible for maintaining it's own object in the persisted state to track the last fetched block number per account per network.

This PR primarily updates the TransactionController to a version which both polls internally for incoming transactions using a block tracker referencing the current network, and maintains its own last fetched block number object.

Note that this update is via a patch due to additional breaking changes blocking a direct version update.

As a result, this PR also includes the following changes:

  • Remove all usage of the fetchAll controller method.
  • Remove the Engine.refreshTransactionHistory method.
  • Use the controller startIncomingTransactionPolling and stopIncomingTransactionPolling methods to control internal polling.
  • Use the updateIncomingTransactions controller method when immediate updates are required such as when changing networks.
  • Add the eth-block-tracker and @metamask/swappable-obj-proxy packages to support the patched TransactionController.

Issue

Fixes #1195

Checklist

  • There is a related GitHub issue
  • Tests are included if applicable
  • Any added code is fully documented

@github-actions
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@matthewwalsh0 matthewwalsh0 changed the title Use block tracker to poll for incoming transactions Use block tracker to poll incoming transactions Aug 16, 2023
@socket-security
Copy link

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

Packages Version New capabilities Transitives Size Publisher
@metamask/swappable-obj-proxy 2.1.0 None +0 30.1 kB metamaskbot
eth-block-tracker 7.1.0 None +4 262 kB gudahtt

@socket-security
Copy link

socket-security bot commented Aug 16, 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: @metamask/eth-json-rpc-provider@1.0.1, @metamask/swappable-obj-proxy@2.1.0, @metamask/safe-event-emitter@3.0.0

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

@matthewwalsh0 matthewwalsh0 added the team-confirmations-system DEPRECATED: please use "team-confirmations" label instead label Aug 18, 2023
@matthewwalsh0 matthewwalsh0 changed the title Use block tracker to poll incoming transactions refactor: use block tracker to poll incoming transactions Aug 18, 2023
@codecov-commenter
Copy link

codecov-commenter commented Aug 18, 2023

Codecov Report

Merging #6998 (356524f) into main (2c4ab04) will increase coverage by 0.04%.
The diff coverage is 16.66%.

@@            Coverage Diff             @@
##             main    #6998      +/-   ##
==========================================
+ Coverage   32.65%   32.69%   +0.04%     
==========================================
  Files         994      993       -1     
  Lines       26646    26606      -40     
  Branches     2089     2083       -6     
==========================================
  Hits         8700     8700              
+ Misses      17532    17492      -40     
  Partials      414      414              
Files Changed Coverage Δ
app/components/Nav/Main/index.js 6.87% <0.00%> (+0.20%) ⬆️
app/components/UI/Transactions/index.js 3.55% <0.00%> (-0.02%) ⬇️
app/components/Views/Asset/index.js 2.98% <0.00%> (-0.03%) ⬇️
...mponents/Views/NetworkSelector/NetworkSelector.tsx 64.61% <0.00%> (-1.06%) ⬇️
...Settings/NetworksSettings/NetworkSettings/index.js 2.69% <0.00%> (ø)
...omponents/Views/Settings/NetworksSettings/index.js 3.96% <0.00%> (ø)
app/core/AppConstants.js 100.00% <ø> (ø)
app/core/Engine.ts 57.63% <66.66%> (+6.06%) ⬆️

@matthewwalsh0
Copy link
Member Author

@SocketSecurity ignore-all

@matthewwalsh0 matthewwalsh0 marked this pull request as ready for review August 18, 2023 12:46
@matthewwalsh0 matthewwalsh0 requested a review from a team as a code owner August 18, 2023 12:46
Copy link
Contributor

@vinistevam vinistevam left a comment

Choose a reason for hiding this comment

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

🚀 🚀 Awesome work! Great to see this on mobile.

@sonarcloud
Copy link

sonarcloud bot commented Aug 22, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug C 3 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

15.4% 15.4% Coverage
0.0% 0.0% Duplication

warning The version of Java (11.0.20) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17.
Read more here

@matthewwalsh0 matthewwalsh0 added the QA Passed A successful QA run through has been done label Aug 22, 2023
@matthewwalsh0 matthewwalsh0 merged commit fbc5b9d into main Aug 22, 2023
13 checks passed
@matthewwalsh0 matthewwalsh0 deleted the refactor/incoming-transactions-block-tracker branch August 22, 2023 10:51
@github-actions github-actions bot locked and limited conversation to collaborators Aug 22, 2023
@metamaskbot metamaskbot added the release-7.7.0 Issue or pull request that will be included in release 7.7.0 label Aug 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
QA Passed A successful QA run through has been done release-7.7.0 Issue or pull request that will be included in release 7.7.0 team-confirmations-system DEPRECATED: please use "team-confirmations" label instead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants