-
-
Notifications
You must be signed in to change notification settings - Fork 256
feat: add ProfileMetricsController to @metamask/profile-metrics-controller
#7196
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
Conversation
…ser-profile-controller-queue
522b8f7 to
747f8f7
Compare
…ser-profile-controller-queue
…ser-profile-controller-queue
…ser-profile-controller-queue
packages/profile-metrics-controller/src/ProfileMetricsController.ts
Outdated
Show resolved
Hide resolved
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
packages/profile-metrics-controller/src/ProfileMetricsController.ts
Outdated
Show resolved
Hide resolved
packages/profile-metrics-controller/src/ProfileMetricsController.ts
Outdated
Show resolved
Hide resolved
packages/profile-metrics-controller/src/ProfileMetricsController.ts
Outdated
Show resolved
Hide resolved
…tadata` Co-authored-by: Daniel Rocha <68558152+danroc@users.noreply.github.com>
f4611d4
packages/profile-metrics-controller/src/ProfileMetricsController.test.ts
Outdated
Show resolved
Hide resolved
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
| state.syncQueue[key] = []; | ||
| } | ||
| state.syncQueue[key].push(...newGroupedAccounts[key]); | ||
| } |
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.
Bug: Duplicate accounts added to queue during initial sync
The #queueFirstSyncIfNeeded method appends all accounts from listAccounts to syncQueue without checking if they already exist. If AccountsController:accountAdded events fire before KeyringController:unlock (possible during wallet setup), accounts added by #addAccountToQueue will be duplicated when #queueFirstSyncIfNeeded runs on unlock. The code checks if syncQueue[key] exists but then blindly pushes accounts rather than deduplicating, causing the same accounts to be submitted multiple times to ProfileMetricsService.
cryptodev-2s
left a comment
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
This PR adds
ProfileMetricsControllerto@metamask/profile-metrics-controller.The new controller manages a queue of addresses that need to be sent to
ProfileMetricsServiceThe queue is updated in the following scenarios:
firstSyncCompletedisfalse(i.e., first sync has not been completed yet)The queue is processed at regular intervals (every 10 seconds by default). At each polling interval, if there are items in the queue, the controller will attempt to call
ProfileMetricsServicethrough the messenger to sync addresses in batches, grouped by their entropy source. Accounts with no entropy source will be batched together.The queue is persisted to storage, so that if the app is closed and reopened, the sync process can continue from where it left off. If one of the batch syncs fails, the same batch will be retried in the next interval.
References
Checklist
Note
Adds
ProfileMetricsControllerthat queues accounts and periodically submits grouped metrics via messenger, with persistence, mutexing, and comprehensive tests.src/ProfileMetricsController.tsStaticIntervalPollingController(default 10s) to callProfileMetricsService:submitMetrics.syncQueuegrouped by entropy source (nullfor none); guarded byasync-mutex.KeyringController:unlock/lockandAccountsController:accountAdded/accountRemovedto enqueue/dequeue; initial enqueue on unlock if not completed.initialEnqueueCompleted,syncQueue).src/ProfileMetricsController.test.tscovering subscriptions, polling behavior, batching, failure handling, and state metadata.src/index.tsto export controller types and helpers.@metamask/accounts-controller,@metamask/keyring-controller,@metamask/polling-controller,async-mutex(and dev@metamask/keyring-internal-api).tsconfig.jsonandtsconfig.build.json.CHANGELOG.mdentry for initial release.Written by Cursor Bugbot for commit bc80feb. This will update automatically on new commits. Configure here.