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

Add Accounts Controller #21437

Merged
merged 81 commits into from
Nov 30, 2023
Merged

Add Accounts Controller #21437

merged 81 commits into from
Nov 30, 2023

Conversation

montelaidev
Copy link
Contributor

@montelaidev montelaidev commented Oct 18, 2023

Description

Currently, MetaMask faces tight coupling between its UI and the keyring-controller. The UI heavily relies on the keyring-controller's state while also amalgamating information from various sources, such as preferences and balances.

However, this approach presents some challenges. The keyring-controller must be aware of the UI's limitations, like the need for instant account list provision to avoid lag. Moreover, it takes on the responsibility of adding metadata to accounts, such as the associated keyring type, required for displaying account details.

To address these issues, the introduction of the accounts-controller comes into play as a new abstraction layer between the UI and the keyring-controller. This separation of responsibilities allows the keyring-controller to focus on two main tasks:

  • Routing requests to the appropriate keyring.
  • Persisting the state of the keyrings.

This PR introduces @metamask/accounts-controller and InternalAccounts to the background script. It is one of several PRs that will be switching the usage of identities to internal accounts.

Changes:

  1. PermissionsController
  • getCaveatSpecifications and getPermissionSpecifications uses getInternalAccounts instead of getIdentities
  • captureKeyringTypesWithMissingIdentities uses the InternalAccount model instead of an identity
  1. IncomingTransactionHelper
  • getAccount now returns an InternalAccount, and uses the AccountsController's getSelectedAccount
  1. AlertController
  • Removed the preferenceStore
  • Added the accountsController and controllerMessenger
  • adds the subscription of selectedAccountChange from the AccountsController
  1. DetectTokenController
  • removes subscription of selectedAddress from the PreferencesController
  • adds the subscription of selectedAccountChange from the AccountsController
  1. AccountTracker
  • removes subscription of selectedAddress from the PreferencesController
  • adds the subscription of selectedAccountChange from the AccountsController
  1. Backup
  • adds backup of AccountsController
  1. MetamaskController
  • modifies TokensController's onPreferencesStateChange to subscribe to selectedAccountChange from the AccountsController
  • modifies the KeyringController constructor arguments
  • modifies metamaskMiddleware's getSelectedAddress to getSelectedAccount
  • modifies setupControllerEventSubscriptions to subscribe to selectedAccountChange from the accounts controller and removes subscribing to selectedAddress from the PreferencesController
  • modifies setAccountLabel to use setAccountName from the AccountsController
  • createNewVaultAndKeychain - awaits for updateAccounts and uses setSelectedAccount from the AccountsController

Additions:

  1. 105 migration file, this migration creates an InternalAccount for every identity and selectedAddress to selectedAccount on the AccountsController
  2. Adds AccountsController to the store and memStore
  3. Adds setSelectedInternalAccount and setAccountName to the api
  4. Changes selectFirstIdentity to selectFirstAccount
  5. Unlock hardware wallet to return internal accounts
  6. resetAccount to use getSelectedAccount
  7. Adds a new subscription, selectedAccountChange to change accounts in setupControllerEventSubscription

Related issues

Resolves https://github.com/MetaMask/accounts-planning/issues/133

Manual testing steps

  1. Use a hardware wallet to test all the flows

Screenshots/Recordings

No UI changes

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've clearly explained:
    • What problem this PR is solving.
    • How this problem was solved.
    • How reviewers can test my changes.
  • I’ve indicated what issue this PR is linked to: Fixes #???
  • I’ve included tests if applicable.
  • I’ve documented any added code.
  • I’ve applied the right labels on the PR (see labeling guidelines).
  • I’ve properly set the pull request status:
    • In case it's not yet "ready for review", I've set it to "draft".
    • In case it's "ready for review", I've changed it from "draft" to "non-draft".

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@github-actions
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@socket-security
Copy link

socket-security bot commented Oct 18, 2023

New and updated dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
@metamask/accounts-controller 4.0.0 None +1 179 kB metamaskbot
@metamask/eth-snap-keyring 1.0.0...2.0.0 None +0/-0 96.8 kB metamaskbot

package.json Outdated Show resolved Hide resolved
@socket-security
Copy link

socket-security bot commented Oct 24, 2023

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

@montelaidev
Copy link
Contributor Author

@metamaskbot update-policies

@metamaskbot
Copy link
Collaborator

Policy update failed. You can review the logs or retry the policy update here

@montelaidev
Copy link
Contributor Author

@metamaskbot update-policies

@metamaskbot
Copy link
Collaborator

Policies updated

@montelaidev
Copy link
Contributor Author

@metamaskbot update-policies

@metamaskbot
Copy link
Collaborator

Builds ready [1060e98]
Page Load Metrics (649 ± 271 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint83131104157
domContentLoaded6612393168
load781496649565271
domInteractive6612393168
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 17.59 KiB (0.48%)
  • ui: 0 Bytes (0.00%)
  • common: 71 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [9184101]
Page Load Metrics (279 ± 187 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint841149173
domContentLoaded691057794
load801251279389187
domInteractive691047794
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 17.59 KiB (0.48%)
  • ui: 0 Bytes (0.00%)
  • common: 71 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [d9f20a9]
Page Load Metrics (465 ± 251 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint871189274
domContentLoaded6811580126
load801260465522251
domInteractive6811580126

Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Looks good!

@plasmacorral plasmacorral added QA Passed DO-NOT-MERGE Pull requests that should not be merged and removed DO-NOT-MERGE Pull requests that should not be merged needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) QA Passed labels Nov 29, 2023
@plasmacorral
Copy link
Contributor

plasmacorral commented Nov 30, 2023

Tested commit d9f20a9 with Mac Sonoma 14.0 and primarily in chrome 117.0.5938.92 with some additional test on Firefox 119.0.1 and 120.0.0

Accounts tested:
Ledger Nano X with firmware 2.1.0
Keystone v3 with firmware 1.1.2
Trezor Model T with firmware 2.6.0
Trezor Classic with firmware 1.12.1
Lattice v2 with firmware 0.14.1 and router 0.49.0
Snap account in flask and stable with SSK v1.1.0
Imported private key
HD

Signing, sending, deploying contracts, changing account names, removing individual accounts, forgetting devices, re-adding and signing some more all functioned as expected. Testing with throttled 3G network speeds was conducted. Migration testing confirms that user edited account names persist and migrated accounts can sign and send post-migration with no issue.

@plasmacorral plasmacorral added QA Passed and removed DO-NOT-MERGE Pull requests that should not be merged labels Nov 30, 2023
@plasmacorral plasmacorral merged commit 9487e82 into develop Nov 30, 2023
69 of 75 checks passed
@plasmacorral plasmacorral deleted the feat/accounts-controller-2 branch November 30, 2023 17:07
@github-actions github-actions bot locked and limited conversation to collaborators Nov 30, 2023
@metamaskbot metamaskbot added the release-11.8.0 Issue or pull request that will be included in release 11.8.0 label Nov 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
QA Passed release-11.8.0 Issue or pull request that will be included in release 11.8.0 team-accounts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants