-
-
Notifications
You must be signed in to change notification settings - Fork 201
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
fix(accounts-controller): re-use current internal state in updateAccounts
#5161
Draft
ccharly
wants to merge
6
commits into
main
Choose a base branch
from
fix/do-not-overwrite-internal-accounts-from-state
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
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
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
danroc
reviewed
Jan 16, 2025
danroc
reviewed
Jan 16, 2025
danroc
reviewed
Jan 16, 2025
danroc
reviewed
Jan 16, 2025
ccharly
changed the title
fix(accounts-controller): re-use internal state in updateAccounts state update
fix(accounts-controller): re-use internal state in Jan 16, 2025
updateAccounts
state update
danroc
reviewed
Jan 16, 2025
ccharly
changed the title
fix(accounts-controller): re-use internal state in
fix(accounts-controller): re-use current internal state in Jan 16, 2025
updateAccounts
state updateupdateAccounts
danroc
reviewed
Jan 16, 2025
Co-authored-by: Daniel Rocha <[email protected]>
ccharly
force-pushed
the
fix/do-not-overwrite-internal-accounts-from-state
branch
from
January 16, 2025 11:19
49b28e1
to
d2b96e9
Compare
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
ccharly
force-pushed
the
fix/do-not-overwrite-internal-accounts-from-state
branch
from
January 16, 2025 11:50
d2b96e9
to
5b0a5fe
Compare
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Explanation
The
AccountsController
sometimes re-build its state by querying all accounts from every keyrings. This makes sure it's in-sync with theKeyringController
's state (mirroring).However, the way this was done was preventing clients from doing migrations to the
AccountsController
's state (mainly on the fields owned by him, like theInternalAccount
's fields).The previous logic was re-creating all internal accounts with a new copy of all "keyring accounts", thus overriding changes done to the
state.AccountsController.internalAccounts
object.This issue was found while adding the new required
scopes
field with a migration, see:scopes
field toKeyringAccount
metamask-extension#29195Detailed explanations (for the extension):
scopes
to each accounts (see here)updateAccounts
to re-create the internal stateupdateAccounts
fetches accounts from each keyrings:scopes
since we were using the previous Snap keyring state (the migration only affects theAccountsController
state) which did not have thescopes
field, noscopes
was added when re-creating the internal state here.This logic was overwriting the migration state update, resulting in a non-consistent state where we had
scopes
for all "normal" accounts, but anundefined
scopes
for ALL Snap accounts.The fix
To prevent this from happening, we are now re-using the current internal state if the account already exists, thus, keeping its current "representation" (in our case, this representation got migrated and now has a new
scopes
for all existing accounts).However, if the account does not exist on the current internal state, we are then just adding it to the state "as-is".
References
scopes
field toKeyringAccount
metamask-extension#29195Changelog
@metamask/accounts-controller
updateAccounts
Checklist