-
-
Notifications
You must be signed in to change notification settings - Fork 245
feat(multichain-account-service): add :walletStatusChange
event + mutex for concurrent mutable operations
#6527
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
feat(multichain-account-service): add :walletStatusChange
event + mutex for concurrent mutable operations
#6527
Conversation
if (this.#isAlignmentInProgress) { | ||
return; // Prevent concurrent alignments | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, removed the old logic mainly cause this could be misleading.
If an alignement was in progress, calling alignGroups
would have returned right away, so you needed to check getIsAlignmentInProgress
to know if something was still running.
With the new #withLock
mechanisms. All those operations will naturally be "queued" until the lock got released. So, we won't be running those concurrently, but more sequentially instead.
packages/multichain-account-service/src/MultichainAccountWallet.ts
Outdated
Show resolved
Hide resolved
* wallet. Account groups will either be created or deleted during | ||
* this operation. | ||
*/ | ||
OperationInProgress = 'operation-in-progress', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I struggle to find a good name for this one... Maybe we should also split create/delete into 2 different status 🤔
(deleting is not possible for now though)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"CrudOperation"? "Mutation" ? No clue either 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually went with in-progress:create-accounts
, mainly because we don't have "delete operations".
packages/multichain-account-service/src/MultichainAccountWallet.ts
Outdated
Show resolved
Hide resolved
); | ||
return await operation(); | ||
} finally { | ||
this.#status = MultichainAccountWalletStatus.Ready; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need a Error
state?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question 🤔 the main problem I can see with this is... How to get back into the Ready
state if that happens? 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After thinking about it, I don't think we need any error state for the moment.
db27b9a
to
207f2ea
Compare
e16f62a
to
af6b40e
Compare
af6b40e
to
cc8a5bd
Compare
0bab851
to
a30e2a8
Compare
…utex for concurrent mutable operations
a30e2a8
to
eb9db81
Compare
) { | ||
const release = await this.#lock.acquire(); | ||
try { | ||
this.#status = status; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need to validate it's a valid status string, at runtime?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Explanation
Wallet operations are not behind a mutex. This ensure that only one mutable operation can be executed at a time.
Also publish new event, so we know in which state a wallet is.
Note
A follow-up PR will be using those events to add a new status in the
account-tree-controller
.Depends on this PR to be merged first:
References
N/A
Checklist