Skip to content
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

improv: account syncing performance #4726

Merged
merged 8 commits into from
Sep 25, 2024
Merged

Conversation

mathieuartu
Copy link
Contributor

@mathieuartu mathieuartu commented Sep 23, 2024

Explanation

This PR adds multiple improvements for the account syncing process, namely:

  • check if the account is of EVM type before saving it to user storage
  • check if the account keyring type is either HD or simple
  • wait for AccountsController:accountAdded event to fire before adding another account

References

NOTIFY-1158

Changelog

@metamask/profile-sync-controller

  • FIXED: various account syncing performance improvements and bug fixes.
    • check if isEvmAccountType before saving an account in user storage in account syncing
    • check for correct KeyringType before saving an account in user storage in account syncing
    • wait for AccountsController:accountAdded event to fire before adding another account in account syncing

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

@mathieuartu
Copy link
Contributor Author

@metamaskbot publish-preview

Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "18.2.1-preview-7e35ac6",
  "@metamask-previews/address-book-controller": "6.0.1-preview-7e35ac6",
  "@metamask-previews/announcement-controller": "7.0.1-preview-7e35ac6",
  "@metamask-previews/approval-controller": "7.0.4-preview-7e35ac6",
  "@metamask-previews/assets-controllers": "38.0.1-preview-7e35ac6",
  "@metamask-previews/base-controller": "7.0.1-preview-7e35ac6",
  "@metamask-previews/build-utils": "3.0.1-preview-7e35ac6",
  "@metamask-previews/chain-controller": "0.1.2-preview-7e35ac6",
  "@metamask-previews/composable-controller": "9.0.1-preview-7e35ac6",
  "@metamask-previews/controller-utils": "11.3.0-preview-7e35ac6",
  "@metamask-previews/ens-controller": "14.0.1-preview-7e35ac6",
  "@metamask-previews/eth-json-rpc-provider": "4.1.4-preview-7e35ac6",
  "@metamask-previews/gas-fee-controller": "20.0.1-preview-7e35ac6",
  "@metamask-previews/json-rpc-engine": "9.0.3-preview-7e35ac6",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.3-preview-7e35ac6",
  "@metamask-previews/keyring-controller": "17.2.1-preview-7e35ac6",
  "@metamask-previews/logging-controller": "6.0.1-preview-7e35ac6",
  "@metamask-previews/message-manager": "10.1.1-preview-7e35ac6",
  "@metamask-previews/name-controller": "8.0.1-preview-7e35ac6",
  "@metamask-previews/network-controller": "21.0.1-preview-7e35ac6",
  "@metamask-previews/notification-controller": "6.0.1-preview-7e35ac6",
  "@metamask-previews/notification-services-controller": "0.8.0-preview-7e35ac6",
  "@metamask-previews/permission-controller": "11.0.2-preview-7e35ac6",
  "@metamask-previews/permission-log-controller": "3.0.1-preview-7e35ac6",
  "@metamask-previews/phishing-controller": "12.0.3-preview-7e35ac6",
  "@metamask-previews/polling-controller": "10.0.1-preview-7e35ac6",
  "@metamask-previews/preferences-controller": "13.0.3-preview-7e35ac6",
  "@metamask-previews/profile-sync-controller": "0.9.0-preview-7e35ac6",
  "@metamask-previews/queued-request-controller": "5.0.1-preview-7e35ac6",
  "@metamask-previews/rate-limit-controller": "6.0.1-preview-7e35ac6",
  "@metamask-previews/selected-network-controller": "18.0.1-preview-7e35ac6",
  "@metamask-previews/signature-controller": "19.1.0-preview-7e35ac6",
  "@metamask-previews/transaction-controller": "37.0.0-preview-7e35ac6",
  "@metamask-previews/user-operation-controller": "15.0.1-preview-7e35ac6"
}

@mathieuartu
Copy link
Contributor Author

@metamaskbot publish-preview

Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "18.2.1-preview-88fd50e",
  "@metamask-previews/address-book-controller": "6.0.1-preview-88fd50e",
  "@metamask-previews/announcement-controller": "7.0.1-preview-88fd50e",
  "@metamask-previews/approval-controller": "7.0.4-preview-88fd50e",
  "@metamask-previews/assets-controllers": "38.0.1-preview-88fd50e",
  "@metamask-previews/base-controller": "7.0.1-preview-88fd50e",
  "@metamask-previews/build-utils": "3.0.1-preview-88fd50e",
  "@metamask-previews/chain-controller": "0.1.2-preview-88fd50e",
  "@metamask-previews/composable-controller": "9.0.1-preview-88fd50e",
  "@metamask-previews/controller-utils": "11.3.0-preview-88fd50e",
  "@metamask-previews/ens-controller": "14.0.1-preview-88fd50e",
  "@metamask-previews/eth-json-rpc-provider": "4.1.4-preview-88fd50e",
  "@metamask-previews/gas-fee-controller": "20.0.1-preview-88fd50e",
  "@metamask-previews/json-rpc-engine": "9.0.3-preview-88fd50e",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.3-preview-88fd50e",
  "@metamask-previews/keyring-controller": "17.2.1-preview-88fd50e",
  "@metamask-previews/logging-controller": "6.0.1-preview-88fd50e",
  "@metamask-previews/message-manager": "10.1.1-preview-88fd50e",
  "@metamask-previews/name-controller": "8.0.1-preview-88fd50e",
  "@metamask-previews/network-controller": "21.0.1-preview-88fd50e",
  "@metamask-previews/notification-controller": "6.0.1-preview-88fd50e",
  "@metamask-previews/notification-services-controller": "0.8.0-preview-88fd50e",
  "@metamask-previews/permission-controller": "11.0.2-preview-88fd50e",
  "@metamask-previews/permission-log-controller": "3.0.1-preview-88fd50e",
  "@metamask-previews/phishing-controller": "12.0.3-preview-88fd50e",
  "@metamask-previews/polling-controller": "10.0.1-preview-88fd50e",
  "@metamask-previews/preferences-controller": "13.0.3-preview-88fd50e",
  "@metamask-previews/profile-sync-controller": "0.9.0-preview-88fd50e",
  "@metamask-previews/queued-request-controller": "5.0.1-preview-88fd50e",
  "@metamask-previews/rate-limit-controller": "6.0.1-preview-88fd50e",
  "@metamask-previews/selected-network-controller": "18.0.1-preview-88fd50e",
  "@metamask-previews/signature-controller": "19.1.0-preview-88fd50e",
  "@metamask-previews/transaction-controller": "37.0.0-preview-88fd50e",
  "@metamask-previews/user-operation-controller": "15.0.1-preview-88fd50e"
}

@mathieuartu
Copy link
Contributor Author

@metamaskbot publish-preview

Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "18.2.1-preview-8c52345",
  "@metamask-previews/address-book-controller": "6.0.1-preview-8c52345",
  "@metamask-previews/announcement-controller": "7.0.1-preview-8c52345",
  "@metamask-previews/approval-controller": "7.0.4-preview-8c52345",
  "@metamask-previews/assets-controllers": "38.0.1-preview-8c52345",
  "@metamask-previews/base-controller": "7.0.1-preview-8c52345",
  "@metamask-previews/build-utils": "3.0.1-preview-8c52345",
  "@metamask-previews/chain-controller": "0.1.2-preview-8c52345",
  "@metamask-previews/composable-controller": "9.0.1-preview-8c52345",
  "@metamask-previews/controller-utils": "11.3.0-preview-8c52345",
  "@metamask-previews/ens-controller": "14.0.1-preview-8c52345",
  "@metamask-previews/eth-json-rpc-provider": "4.1.4-preview-8c52345",
  "@metamask-previews/gas-fee-controller": "20.0.1-preview-8c52345",
  "@metamask-previews/json-rpc-engine": "9.0.3-preview-8c52345",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.3-preview-8c52345",
  "@metamask-previews/keyring-controller": "17.2.1-preview-8c52345",
  "@metamask-previews/logging-controller": "6.0.1-preview-8c52345",
  "@metamask-previews/message-manager": "10.1.1-preview-8c52345",
  "@metamask-previews/name-controller": "8.0.1-preview-8c52345",
  "@metamask-previews/network-controller": "21.0.1-preview-8c52345",
  "@metamask-previews/notification-controller": "6.0.1-preview-8c52345",
  "@metamask-previews/notification-services-controller": "0.8.0-preview-8c52345",
  "@metamask-previews/permission-controller": "11.0.2-preview-8c52345",
  "@metamask-previews/permission-log-controller": "3.0.1-preview-8c52345",
  "@metamask-previews/phishing-controller": "12.0.3-preview-8c52345",
  "@metamask-previews/polling-controller": "10.0.1-preview-8c52345",
  "@metamask-previews/preferences-controller": "13.0.3-preview-8c52345",
  "@metamask-previews/profile-sync-controller": "0.9.0-preview-8c52345",
  "@metamask-previews/queued-request-controller": "5.0.1-preview-8c52345",
  "@metamask-previews/rate-limit-controller": "6.0.1-preview-8c52345",
  "@metamask-previews/selected-network-controller": "18.0.1-preview-8c52345",
  "@metamask-previews/signature-controller": "19.1.0-preview-8c52345",
  "@metamask-previews/transaction-controller": "37.0.0-preview-8c52345",
  "@metamask-previews/user-operation-controller": "15.0.1-preview-8c52345"
}

@mathieuartu
Copy link
Contributor Author

@metamaskbot publish-preview

1 similar comment
@mathieuartu
Copy link
Contributor Author

@metamaskbot publish-preview

@mathieuartu
Copy link
Contributor Author

@metamaskbot publish-preview

Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "18.2.1-preview-f6589ba6",
  "@metamask-previews/address-book-controller": "6.0.1-preview-f6589ba6",
  "@metamask-previews/announcement-controller": "7.0.1-preview-f6589ba6",
  "@metamask-previews/approval-controller": "7.0.4-preview-f6589ba6",
  "@metamask-previews/assets-controllers": "38.0.1-preview-f6589ba6",
  "@metamask-previews/base-controller": "7.0.1-preview-f6589ba6",
  "@metamask-previews/build-utils": "3.0.1-preview-f6589ba6",
  "@metamask-previews/chain-controller": "0.1.2-preview-f6589ba6",
  "@metamask-previews/composable-controller": "9.0.1-preview-f6589ba6",
  "@metamask-previews/controller-utils": "11.3.0-preview-f6589ba6",
  "@metamask-previews/ens-controller": "14.0.1-preview-f6589ba6",
  "@metamask-previews/eth-json-rpc-provider": "4.1.4-preview-f6589ba6",
  "@metamask-previews/gas-fee-controller": "20.0.1-preview-f6589ba6",
  "@metamask-previews/json-rpc-engine": "9.0.3-preview-f6589ba6",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.3-preview-f6589ba6",
  "@metamask-previews/keyring-controller": "17.2.1-preview-f6589ba6",
  "@metamask-previews/logging-controller": "6.0.1-preview-f6589ba6",
  "@metamask-previews/message-manager": "10.1.1-preview-f6589ba6",
  "@metamask-previews/name-controller": "8.0.1-preview-f6589ba6",
  "@metamask-previews/network-controller": "21.0.1-preview-f6589ba6",
  "@metamask-previews/notification-controller": "6.0.1-preview-f6589ba6",
  "@metamask-previews/notification-services-controller": "0.8.0-preview-f6589ba6",
  "@metamask-previews/permission-controller": "11.0.2-preview-f6589ba6",
  "@metamask-previews/permission-log-controller": "3.0.1-preview-f6589ba6",
  "@metamask-previews/phishing-controller": "12.0.3-preview-f6589ba6",
  "@metamask-previews/polling-controller": "10.0.1-preview-f6589ba6",
  "@metamask-previews/preferences-controller": "13.0.3-preview-f6589ba6",
  "@metamask-previews/profile-sync-controller": "0.9.0-preview-f6589ba6",
  "@metamask-previews/queued-request-controller": "5.0.1-preview-f6589ba6",
  "@metamask-previews/rate-limit-controller": "6.0.1-preview-f6589ba6",
  "@metamask-previews/selected-network-controller": "18.0.1-preview-f6589ba6",
  "@metamask-previews/signature-controller": "19.1.0-preview-f6589ba6",
  "@metamask-previews/transaction-controller": "37.0.0-preview-f6589ba6",
  "@metamask-previews/user-operation-controller": "15.0.1-preview-f6589ba6"
}

@mathieuartu mathieuartu marked this pull request as ready for review September 25, 2024 07:10
@mathieuartu mathieuartu requested a review from a team as a code owner September 25, 2024 07:10
await this.messagingSystem.call('KeyringController:addNewAccount');
await waitForExpectedValue(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehe, nice

if (!this.#accounts.canSync()) {
if (
!this.#accounts.canSync() ||
!isEvmAccountType(internalAccount.type) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is okay. I find that once we have more than 1 boolean operand (&&/||) it gets a little confusing. Maybe could split out into a separate func?

* @returns A promise that resolves when the expected value is returned
* or rejects if the timeout is reached.
*/
export function waitForExpectedValue<TVariable>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we had to resort to this, really nice util.

Copy link
Contributor

@matteoscurati matteoscurati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mathieuartu mathieuartu merged commit 644c90c into main Sep 25, 2024
116 checks passed
@mathieuartu mathieuartu deleted the improv/account_sync_performance branch September 25, 2024 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants