fix(snap-account-service)!: relax keyring messages/methods handling#8860
Merged
ccharly merged 7 commits intoJun 2, 2026
Merged
Conversation
Contributor
Author
|
@metamaskbot publish-preview |
Contributor
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
hmalik88
approved these changes
Jun 2, 2026
This file contains hidden or 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
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
We used to always auto-create the legacy Snap keyring (and in the future, Snap keyring v2 instances) automatically when handling events/methods, but this can sometimes cause some deadlock, especially with v1 events (e.g. you call
keyring.removeAccountwhich will send anotify:accountDeleted).This was working fine before cause a lot of consumers were creating the Snap keyring in an unsafe way (combining
getKeyringsByTypeandaddNewKeyring).We now only delegate those calls to the Snap keyring only when this makes sense!
References
N/A
Checklist
Note
High Risk
Changes keyring acquisition and auto-create rules on account-management Snap paths; integrators must wire withKeyringUnsafe and may see new errors or empty getSelectedAccounts when the keyring is missing.
Overview
Snap account service no longer auto-creates the legacy Snap keyring on every keyring Snap message or selected-account forward. It first resolves the keyring via
KeyringController:withKeyringUnsafe(new required messenger action) and only creates the keyring when handlingnotify:accountCreated.handleKeyringSnapMessagenow returns[]forgetSelectedAccountsif the keyring is missing (early Snap init), throws for other events when the keyring is absent, and still delegates when the keyring exists. Selected-account forwarding (account tree / unlock) skips quietly when no legacy keyring is present instead of triggeringwithControllercreation.Tests and changelog document the double-lock fix;
@metamask/keyring-apiand@metamask/keyring-snap-sdkwere added as dependencies.Reviewed by Cursor Bugbot for commit 82ea938. Bugbot is set up for automated code reviews on this repo. Configure here.