-
-
Notifications
You must be signed in to change notification settings - Fork 254
fix(multichain-account-service)!: wait for Snap platform to be ready #7266
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
base: main
Are you sure you want to change the base?
Conversation
|
|
||
| readonly #trace: TraceCallback; | ||
|
|
||
| protected static ensureSnapPlatformIsReadyPromise: Promise<void> | null = |
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.
Mainly using a protected static here so we can write tests and update this without exposing it completely publicly (consumers could still hack this easily 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.
Question: Should we have a 1 promise per Snap? This would allow to wait for the Snap to be ready rather than the Snap platform itself?
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.
Wouldn't the snap be ready if the platform is?
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 guess so yes, so I think we can keep this as-is!
| abstract isAccountCompatible(account: Bip44Account<InternalAccount>): boolean; | ||
|
|
||
| abstract createAccounts(options: { | ||
| abstract runCreateAccounts(options: { |
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.
Now providers have to implements those run* methods, so we can automatically call this.ensureSnapPlatformIsReady for any of those actions.
Explanation
Snap requests are now delayed after the onboarding, to avoid starting requests "too soon" on the clients, we now have a logic to wait for the Snap platform to be ready.
This makes sure that any calls that uses retries or timeouts will start their calls AFTER the Snap platform is ready to process anything.
We stumbled upon this bug during the concurrent requests/Snap state inconsistency investigation. Initial account providers requests were usually timing out because they were hitting their limit because they were starting a bit "late" since the Snap platform was not ready yet. (This was also still causing concurrent requests, despite the
maxConcurrency: 1, since Snaps were still processing the timed out request while receiving new ones).To future-proof this and fully await for the Snap platform to be ready, we now send 1 simple Snap request and wait for it to be executed (being successful or not). Then, we start processing all Snap requests with our usual logic (timeouts, semaphore, retries, etc...)
References
Checklist
Note
Waits for the Snap platform to be ready before any provider operations, renaming abstract create/discover methods to run* and updating providers/tests accordingly.
ensureSnapPlatformIsReady(singleton promise) and call it in constructor and beforecreateAccounts,discoverAccounts,resyncAccounts, and Snap keyring access.KeyringRpcMethod.GetAccount/ListAccountsthroughKeyringClient.createAccounts/discoverAccountsto await readiness, delegating to new abstractrunCreateAccounts/runDiscoverAccounts.BaseBip44AccountProvider.getAnyAccount()to support fast ping selection.SolAccountProvider,BtcAccountProvider,TrxAccountProviderto userunCreateAccounts/runDiscoverAccounts(renamed fromcreateAccounts/discoverAccounts).Written by Cursor Bugbot for commit 0ccef45. This will update automatically on new commits. Configure here.