-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
chore(runway): cherry-pick fix: freeze during swap with approval #11209
Merged
sethkfman
merged 3 commits into
release/7.31.0
from
runway-cherry-pick-7.31.0-1726259478
Sep 13, 2024
Merged
chore(runway): cherry-pick fix: freeze during swap with approval #11209
sethkfman
merged 3 commits into
release/7.31.0
from
runway-cherry-pick-7.31.0-1726259478
Sep 13, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
) ## **Description** The freeze was ultimately caused by a render loop inside `RootRPCMethodsUI` caused by the `TransactionController:unapprovedTransactionAdded` listener. More specifically: 1. When swaps are detected, the transaction is automatically approved via the `autoSign` function. 2. This registers a listener to send a completed metric once the transaction is confirmed. 3. This is triggered by adding the transaction ID to a queue via the `addTransactionMetaIdForListening` function. 4. This function updates React state, but was also using that same state as a dependency, meaning the callback was updated on every usage. 5. This function was a dependency of `autoSign` which was in turn a dependency of `onUnapprovedTransaction` which was the only dependency for a `useEffect` that re-created the `TransactionController:unapprovedTransactionAdded` listener. 6. The `ControllerMessenger` processes listeners using an iterator rather than a static list meaning each new listener was automatically ran which in turn created another listener and resulted in a very high CPU render loop. The core fix was to update the `addTransactionMetaIdForListening` to update the state using the callback override meaning it did not require the state dependency. However during testing it was discovered that this swaps completed metric was not functioning since the `swapsTransaction` state was being incorrectly populated with the `TransactionController` instance due to a legacy function argument that was not fully removed. This has been addressed, and all swaps transactions updates have been abstracted via a new `swaps-transactions` utility file. ## **Related issues** Fixes: [#11085](#11085) ## **Manual testing steps** Full swaps regression, including: - Swaps with approvals. - Smart swaps. - Metric support. - Multiple sequential swaps (with and without approvals). ## **Screenshots/Recordings** ### **Before** ### **After** ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.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: sethkfman <10342624+sethkfman@users.noreply.github.com>
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. |
sethkfman
approved these changes
Sep 13, 2024
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.
LGTM
Quality Gate passedIssues Measures |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The freeze was ultimately caused by a render loop inside
RootRPCMethodsUI
caused by theTransactionController:unapprovedTransactionAdded
listener.More specifically:
via the
autoSign
function.transaction is confirmed.
addTransactionMetaIdForListening
function.as a dependency, meaning the callback was updated on every usage.
autoSign
which was in turn adependency of
onUnapprovedTransaction
which was the only dependencyfor a
useEffect
that re-created theTransactionController:unapprovedTransactionAdded
listener.ControllerMessenger
processes listeners using an iteratorrather than a static list meaning each new listener was automatically
ran which in turn created another listener and resulted in a very high
CPU render loop.
The core fix was to update the
addTransactionMetaIdForListening
toupdate the state using the callback override meaning it did not require
the state dependency.
However during testing it was discovered that this swaps completed
metric was not functioning since the
swapsTransaction
state was beingincorrectly populated with the
TransactionController
instance due to alegacy function argument that was not fully removed.
This has been addressed, and all swaps transactions updates have been
abstracted via a new
swaps-transactions
utility file.Related issues
Fixes:
#11085
Manual testing steps
Full swaps regression, including:
Screenshots/Recordings
Before
After
Pre-merge author checklist
Docs and MetaMask Mobile
Coding
Standards.
if applicable
guidelines).
Not required for external contributors.
Pre-merge reviewer checklist
app, test code being changed).
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
Co-authored-by: sethkfman 10342624+sethkfman@users.noreply.github.com 059a391