Use storage.local instead of localStorage#3083
Conversation
…anjm-1 Additions to the UseStorageLocalInstead branch
| try { | ||
| localStore.set(state) | ||
| } catch (err) { | ||
| log.error('error setting state in local store:', err) |
There was a problem hiding this comment.
i dont think these get submitted to sentry (but maybe they do)
There was a problem hiding this comment.
What does get submitted for sure?
There was a problem hiding this comment.
(we should document our correct logging practice)
There was a problem hiding this comment.
im not certain atm, but you can test it with the Test-Metamask sentry project on dev
app/scripts/lib/extension-store.js
Outdated
| const KEYS_TO_SYNC = ['KeyringController', 'PreferencesController'] | ||
| const FIREFOX_SYNC_DISABLED_MESSAGE = 'Please set webextensions.storage.sync.enabled to true in about:config' | ||
|
|
||
| const handleDisabledSyncAndResolve = (resolve, toResolve) => { |
There was a problem hiding this comment.
meaning of toResolve is not clear
There was a problem hiding this comment.
This is part of the original Ellieday PR, we aren't actually using this file in this PR, so I'm not sure I want to bother cleaning it up, I'd rather either:
- Delete the file and its test
- Ignore it for now
kumavis
left a comment
There was a problem hiding this comment.
Nice -- looking forward to it
added some questions / comments
app/scripts/lib/extension-store.js
Outdated
| } | ||
| async fetch() { | ||
| return new Promise((resolve) => { | ||
| extension.storage && extension.storage.sync.get(KEYS_TO_SYNC, (data) => { |
There was a problem hiding this comment.
we wanted to drop KEYS_TO_SYNC, right?
app/scripts/background.js
Outdated
| log.error('error fetching state from local store:', err) | ||
| } | ||
|
|
||
| // TODO: handle possible exceptions (https://developer.chrome.com/apps/runtime#property-lastError) |
There was a problem hiding this comment.
looks like this is somewhat handled in ExtensionStore
const lastError = extension.runtime.lastErrorThere was a problem hiding this comment.
I'm hesitant to merge a TODO in here, especially around error handling
| log.error('Storage local API not available.') | ||
| } | ||
| } | ||
| async get() { |
There was a problem hiding this comment.
doesnt need to be marked as async when manually returning a promise but maybe this is a good practice anyways
app/manifest.json
Outdated
| "http://localhost:8545/", | ||
| "https://*.infura.io/" | ||
| ], | ||
| "unlimitedStorage": true, |
There was a problem hiding this comment.
unlimitedStorage should be added to the permissions, the same as storage. Referenced: Declare Permissions
|
@heyellieday we used some of your code in this PR so we'd like to credit you with partial bounty reward of the original bounty (synced storage). Can you give an ethereum address here or emailed to |
|
cool, just needs QA then |
|
Added to that branch:
|
|
@kumavis, sorry, I missed these mentions! I'm glad some of my work was able to be used for this issue and thanks for crediting me part of the bounty! Here's an ethereum address to send to: 0x1ab4C79D96a05b64742AE1B0213B84fB984917C8. I'm hoping I can help out with more in the future :) |
- Don't persist undefined data - Write to new storage strategy without waiting for completion. - Continue writing to localStorage as fallback.
app/scripts/background.js
Outdated
| } | ||
|
|
||
| if (Object.keys(localData).length > 0) { | ||
| versionedData = localData |
There was a problem hiding this comment.
why do we do this
please add a comment
app/scripts/background.js
Outdated
| const migrator = new Migrator({ migrations }) | ||
| // read from disk | ||
| let versionedData = diskStore.getState() || migrator.generateInitialState(firstTimeState) | ||
| versionedData = diskStore.getState() || migrator.generateInitialState(firstTimeState) |
There was a problem hiding this comment.
maybe something like
versionedData = localData || diskStore.getState() || migrator.generateInitialState(firstTimeState)
There was a problem hiding this comment.
New commit moves storage.local loading before this assignment so I can use a similar format to what you suggest.
kumavis
left a comment
There was a problem hiding this comment.
im going to take another pass over this, please wait
|
Yes, they are migrated to the new storage model, and the old storage model is kept around, in case the new one fails. |
The disk store has not been written to since MetaMask v4.3.0, as it was removed in MetaMask#3083. It was kept around so that anything written to disk prior to v4.3.0 could still be restored. It has been a year and a half since that release, so I think it's time to remove the disk store altogether. The consequences of losing locally stored data are small anyway - it's an inconvenience at worst.
The disk store has not been written to since MetaMask v4.3.0, as it was removed in #3083. It was kept around so that anything written to disk prior to v4.3.0 could still be restored. It has been a year and a half since that release, so I think it's time to remove the disk store altogether. The consequences of losing locally stored data are small anyway - it's an inconvenience at worst.
Fixes #3076, needs thorough QA:
master, rebuild on this branch, see if MM continues seamlessly.localStoragedata manually, see if MM continues seamlessly.