feat(keyring-controller): add withController for atomic operations over multiple keyrings#8416
Draft
feat(keyring-controller): add withController for atomic operations over multiple keyrings#8416
Conversation
…er multiple keyrings
7194e8d to
ece23cf
Compare
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