-
Notifications
You must be signed in to change notification settings - Fork 5.4k
fix: add resync mechanism to sync Snap accounts states with client accounts cp-13.11.0 #37987
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
Conversation
|
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. |
Builds ready [02a6c2a]
UI Startup Metrics (1200 ± 85 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
app/scripts/metamask-controller.js
Outdated
| // There is is/was a bug with Snap accounts that can be desynchronized (Solana). To | ||
| // automatically "fix" this corrupted state, we run this method which will re-sync | ||
| // MetaMask accounts and Snap accounts upon login. | ||
| await this.multichainAccountService.resyncAccounts(); |
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.
Do we need to init the AccountTreeController before syncing?
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.
Actually, let me rework this PR and see if we can do the same than on mobile (which is running all this "async"/non-awaited)
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.
I made it async now, so this will happen after all initialization!
app/scripts/metamask-controller.js
Outdated
| ///: BEGIN:ONLY_INCLUDE_IF(multichain) | ||
| // Init multichain accounts after creating internal accounts. | ||
| await this.multichainAccountService.init(); | ||
| // READ THIS CAREFULLY: |
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.
Can we add a reference to the bug in the comments
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.
I did add the reference now, even if this PR is more like a "mitigation" rather than a true fix, but still worth IMO!
|
|
||
| expect(mockResyncAccounts).toHaveBeenCalled(); | ||
| expect(mockAlignWallets).toHaveBeenCalled(); | ||
| }); |
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.
Bug: Race condition in async test verification
The test uses waitForAllPromises() which only waits for one process.nextTick, but the resyncAndAlignAccounts function contains two sequential await statements. This creates a race condition where the test assertions may execute before both resyncAccounts and alignWallets complete, causing intermittent test failures. The fire-and-forget pattern with void means the function execution isn't guaranteed to finish before the assertions run.
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.
That's ok for now, I'll keep this simple.
| // NOTE: We run this asynchronously on purpose, see FIXME^. | ||
| // eslint-disable-next-line no-void | ||
| void this.multichainAccountService.alignWallets(); | ||
| void resyncAndAlignAccounts(); |
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.
Bug: Unconditional multichain service calls cause runtime errors
The conditional compilation directives around multichainAccountService.init() were removed, but multichainAccountService is only defined in builds with the multichain flag enabled. This causes the code to attempt calling methods on undefined in non-multichain builds, resulting in runtime errors. The same issue affects the resyncAndAlignAccounts function which calls resyncAccounts() and alignWallets() on the potentially undefined service.
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.
I actually removed it cause we were already using the service without the codefence. Anyway, this code fence should be entirely remove at some point.
Builds ready [6771234]
UI Startup Metrics (1234 ± 100 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Co-authored-by: Mathieu Artu <mathieu.artu@consensys.net>
Builds ready [cfec6a9]
UI Startup Metrics (1205 ± 105 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Description
This will automatically fix corrupted states if users have desync'd accounts.
This should mitigate some errors that were spotted with the rewards system where some Solana address could not be registered.
Changelog
CHANGELOG entry: Automatically re-sync accounts between Snaps and MetaMask
Related issues
Fix for users that already encountered this bug (their "not found" accounts will automatically be re-created now, acting as a migration):
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
On unlock, asynchronously resync Snap and MetaMask accounts, then align wallets; adds tests to verify both are invoked.
app/scripts/metamask-controller.jssubmitPasswordOrEncryptionKey, after init and account-tree refresh, if multichain state2 is enabled, runmultichainAccountService.resyncAccounts()thenalignWallets()asynchronously via a helper.waitForAllPromisesutility.app/scripts/metamask-controller.test.jsassertsresyncAccountsandalignWalletsare called asynchronously aftersubmitPasswordOrEncryptionKey.Written by Cursor Bugbot for commit cfec6a9. This will update automatically on new commits. Configure here.