fix(keyring-snap-bridge): prevent deadlock in createAccounts (v2)#591
Merged
Conversation
createAccountscreateAccounts (v2)
hmalik88
previously approved these changes
Jul 9, 2026
hmalik88
approved these changes
Jul 9, 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.
We don't need to call
saveStatehere. That was an old trick used by v1 asynccreateAccountflow.Here, we expect every
SnapKeyring.createAccountsto be naturally wrapped in a:withKeyringV2or:withKeyringcall.This should also have a positive impact in terms of performance since updates can be pinpointed to a specific keyrings, rather than re-persisting everything for 1 keyring change (though, the
KeyringControllerstill re-serialize all keyrings today... So that might only be a perf improvement in case of non-change/idempotent calls).We stumbled upon this bug with the last change we made on the
multichain-account-service(wrappingcreateAccountscall in:withKeyringV2), see:keyring.v1for v1 account management Snaps core#9390Note
Medium Risk
Changes when keyring state is persisted for batch account creation; callers that invoke
createAccountsoutside a:withKeyringV2transaction would no longer get automatic persistence.Overview
Fixes a deadlock when batch account creation runs inside a
:withKeyringV2(or:withKeyring) transaction by removing thesaveStatecallback from v2SnapKeyring.createAccountsafter new accounts are written to in-memory state.createAccountsstill updates the keyring and returns new plus existing accounts, but persistence is left to the caller’s transaction wrapper—the same pattern as v1 batchcreateAccounts, unlike async v1createAccountwhich still persists on its own.Tests and the changelog now document that
saveStatemust not be invoked fromcreateAccounts(success, idempotent, concurrent batches, and rollback paths).Reviewed by Cursor Bugbot for commit ee5aef5. Bugbot is set up for automated code reviews on this repo. Configure here.