fix(stability): use IndexedDB for StorageService data cp-13.46.0 - #44010
Conversation
Builds ready [9f311b8]
⚡ Performance Benchmarks (Total: 🟢 13 pass · 🟡 10 warn · 🔴 1 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
|
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. |
There was a problem hiding this comment.
Pull request overview
Moves the extension’s StorageService persistence from browser.storage.local to an IndexedDB-backed adapter to reduce pressure on the extension storage LevelDB, while retaining a storage.local fallback for environments where IndexedDB mutations are blocked (e.g., some Firefox private browsing modes).
Changes:
- Added
IndexedDBStorageAdapter(IndexedDB primary +browser.storage.locallegacy fallback) and wired wallet init to use it. - Extended
IndexedDBStorewith key enumeration (getKeys) and added unit coverage. - Added migration
222to copy existingstorageService:*keys frombrowser.storage.localinto IndexedDB (without overwriting existing IndexedDB values).
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| shared/lib/stores/indexeddb-store.ts | Adds getKeys to enumerate (and prefix-filter) IndexedDB keys. |
| shared/lib/stores/indexeddb-store.test.ts | Adds unit tests for getKeys. |
| shared/lib/stores/indexeddb-storage-adapter.ts | Introduces an IndexedDB-backed StorageService adapter with storage.local fallback and legacy reads/removals. |
| shared/lib/stores/indexeddb-storage-adapter.test.ts | Adds unit tests covering IndexedDB behavior and fallback behavior. |
| shared/lib/stores/browser-storage-adapter.test.ts | Updates adapter unit test imports (currently incorrect per review comment). |
| app/scripts/wallet-init/instance-options/storage-service.ts | Switches wallet StorageService initialization to the new IndexedDB adapter. |
| app/scripts/migrations/index.js | Registers the new migration entry. |
| app/scripts/migrations/222.ts | Migrates existing storageService:* data from browser.storage.local to IndexedDB (with mutation-blocked handling). |
| app/scripts/migrations/222.test.ts | Adds unit tests for migration 222 behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Builds ready [65635ad]
⚡ Performance Benchmarks (Total: 🟢 6 pass · 🟡 17 warn · 🔴 1 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: davidmurdoch <187813+davidmurdoch@users.noreply.github.com>
Builds ready [da2fc8c]
⚡ Performance Benchmarks (Total: 🟢 9 pass · 🟡 14 warn · 🔴 1 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Co-authored-by: Mark Stacey <mark.stacey@consensys.net>
Co-authored-by: Mark Stacey <mark.stacey@consensys.net>
Co-authored-by: Mark Stacey <mark.stacey@consensys.net>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit fa5fbde. Configure here.
Gudahtt
left a comment
There was a problem hiding this comment.
LGTM! I can re-review once the failing unit test is fixed.
Builds ready [fa5fbde]
⚡ Performance Benchmarks (Total: 🟢 13 pass · 🟡 8 warn · 🔴 3 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [23fbbd8]
⚡ Performance Benchmarks (Total: 🟢 15 pass · 🟡 6 warn · 🔴 4 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [ce00b53]
⚡ Performance Benchmarks (Total: 🟢 9 pass · 🟡 10 warn · 🔴 4 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
|
Builds ready [f0a23f4] [reused from ce00b53]
⚡ Performance Benchmarks (Total: 🟢 9 pass · 🟡 10 warn · 🔴 4 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Gudahtt
left a comment
There was a problem hiding this comment.
LGTM! I tested the migration process as well, with a build from git merge-base origin/main [this-pr], and the migration seemed to work perfectly.




Description
This PR moves the extension
StorageServiceadapter frombrowser.storage.localtoIndexedDBin Chromium browsers (and not in Firefox). The goal is to reduce pressure on Chrome extensionstorage.localLevelDB data by moving largeStorageServicevalues, such as Snap source code, into a separate IndexedDB database.It adds
IndexedDBStorageAdapter, extendsIndexedDBStorewith key enumeration, wires wallet initialization to the new adapter, and adds migration 223 to copy existingstorageService:*keys frombrowser.storage.localinto IndexedDB for users who already ran the older StorageService migrations.Firefox can block IndexedDB in some private browsing modes, and it doesn't benefit from moving it anyway, so we just don't move it.
Changelog
CHANGELOG entry: improves storage resilience and stability
Related issues
Fixes: #44251
Manual testing steps
browser.storage.local.Validation
yarn lint:changedyarn lint:tscyarn test:unit app/scripts/migrations/222.test.ts shared/lib/stores/indexeddb-storage-adapter.test.ts shared/lib/stores/indexeddb-store.test.ts shared/lib/stores/fixture-extension-store.test.ts app/scripts/wallet-init/instance-options/storage-service.test.ts app/scripts/lib/migrator/index.test.js --runInBandyarn test:unit:coverage --shard=6/6Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
One-time data migration and a new default persistence backend affect all StorageService-backed state (e.g. Snaps source); failures are partially mitigated by not deleting legacy keys on write errors and Firefox staying on storage.local.
Overview
StorageService on Chromium now persists through a new
IndexedDBStorageAdapter(withbrowser.storage.localfallback when IndexedDB is blocked) instead ofBrowserStorageAdapter, wired viagetStorageServiceInstanceOptions.IndexedDBStoregainsgetKeysprefix enumeration and sharedisIndexedDBMutationBlockedErrorhandling (also reused inpersistence-managerbackup open).A new migration (
223.ts, registered in the migrations index) copies legacystorageService:*keys out ofstorage.localinto themetamask-storage-serviceIndexedDB database on Chrome only: it skips keys already present in IndexedDB, removesstorage.localentries only after a successful write, and no-ops on Firefox or when IndexedDB is unavailable. Fixture seeding inFixtureExtensionStorefollows the same IndexedDB-first / fallback pattern.Tests and e2e fixtures bump the expected migration version to 223.
Reviewed by Cursor Bugbot for commit 27be20d. Bugbot is set up for automated code reviews on this repo. Configure here.