feat(keyring-controller): add withController for atomic operations over multiple keyrings#8416
Open
feat(keyring-controller): add withController for atomic operations over multiple keyrings#8416
withController for atomic operations over multiple keyrings#8416Conversation
7194e8d to
ece23cf
Compare
…er multiple keyrings
e1b0a6b to
001d092
Compare
withController for atomic operations over multiple keyrings
b74e2c3 to
02a9fac
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 3 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 02a9fac. Configure here.
packages/keyring-controller/src/KeyringController-method-action-types.ts
Outdated
Show resolved
Hide resolved
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
Today there's no way to make multiple operations in an "atomic" (read transactional) way.
A good example of this is if you want to use a keyring using
withKeyringthat's not existing yet (I'm omitting thecreateIfMissingvariants, as we wanted to move away from this pattern).To do this in a safe way, you usually have to use your own lock to make sure you can get-or-create the keyring and prevent concurrent keyring creations.
This new
withControlleris based on thewithKeyringbut with an access to a "restricted" state and methods of the controller. This way, you can interact with multiple keyring at once while being guarded (to prevent race-conditions) by the controller's global lock.The former problem can then be written that way now:
This will also be used to write the migration from the existing
SnapKeyring(1 for ALL Snaps) to multipleSnapKeyring(1 PER Snap) in a safe way like:References
N/A
Checklist
Note
Medium Risk
Adds new transactional mutation surface that can create/remove keyrings and update vault persistence/rollback semantics, so bugs could affect keyring lifecycle and vault state integrity.
Overview
Adds
KeyringController.withController(and messenger actionKeyringController:withController) to run single-lock, transaction-like operations across multiple keyrings via aRestrictedControllerview that supports stagedaddNewKeyring/removeKeyring, auto-persist on success, and rollback (including destroying newly created keyrings) on error.Updates types to export
KeyringEntry/RestrictedController, wireswithControllerinto the exposed messenger methods and action union, and expands tests to cover lock checks, immediate visibility of staged changes, commit/rollback behavior, and preventing returning raw keyring instances; test mocks add adestroy()method to support lifecycle assertions.Reviewed by Cursor Bugbot for commit 21276f6. Bugbot is set up for automated code reviews on this repo. Configure here.