Skip to content

Use storage.local instead of localStorage#3083

Merged
kumavis merged 33 commits intomasterfrom
i3076-UseStorageLocalInstead
Mar 13, 2018
Merged

Use storage.local instead of localStorage#3083
kumavis merged 33 commits intomasterfrom
i3076-UseStorageLocalInstead

Conversation

@danfinlay
Copy link
Copy Markdown
Contributor

Fixes #3076, needs thorough QA:

  • Create a vault on master, rebuild on this branch, see if MM continues seamlessly.
  • Try destroying the old localStorage data manually, see if MM continues seamlessly.
  • Do full QA on this branch, to ensure it's internally reliable.
  • Maybe try filling up storage manually somehow. Could be by creating tons of accounts or tons of testnet transactions that publish large contracts.

try {
localStore.set(state)
} catch (err) {
log.error('error setting state in local store:', err)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i dont think these get submitted to sentry (but maybe they do)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What does get submitted for sure?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

(we should document our correct logging practice)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

im not certain atm, but you can test it with the Test-Metamask sentry project on dev

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) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

meaning of toResolve is not clear

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

@kumavis kumavis left a comment

Choose a reason for hiding this comment

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

Nice -- looking forward to it

added some questions / comments

}
async fetch() {
return new Promise((resolve) => {
extension.storage && extension.storage.sync.get(KEYS_TO_SYNC, (data) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we wanted to drop KEYS_TO_SYNC, right?

log.error('error fetching state from local store:', err)
}

// TODO: handle possible exceptions (https://developer.chrome.com/apps/runtime#property-lastError)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks like this is somewhat handled in ExtensionStore

 const lastError = extension.runtime.lastError

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm hesitant to merge a TODO in here, especially around error handling

log.error('Storage local API not available.')
}
}
async get() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

doesnt need to be marked as async when manually returning a promise but maybe this is a good practice anyways

"http://localhost:8545/",
"https://*.infura.io/"
],
"unlimitedStorage": true,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

unlimitedStorage should be added to the permissions, the same as storage. Referenced: Declare Permissions

@kumavis
Copy link
Copy Markdown
Member

kumavis commented Jan 24, 2018

@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 aaron at kumavis dot me thanks/

@kumavis
Copy link
Copy Markdown
Member

kumavis commented Jan 24, 2018

cool, just needs QA then

@danfinlay
Copy link
Copy Markdown
Contributor Author

Added to that branch:

  • No longer writes to localStorage.
  • Fixed issue where quantity of write attempts overwhelmed our pump to storage.local stream.

@heyellieday
Copy link
Copy Markdown
Contributor

@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.
}

if (Object.keys(localData).length > 0) {
versionedData = localData
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why do we do this
please add a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment added.

const migrator = new Migrator({ migrations })
// read from disk
let versionedData = diskStore.getState() || migrator.generateInitialState(firstTimeState)
versionedData = diskStore.getState() || migrator.generateInitialState(firstTimeState)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe something like
versionedData = localData || diskStore.getState() || migrator.generateInitialState(firstTimeState)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

New commit moves storage.local loading before this assignment so I can use a similar format to what you suggest.

kumavis
kumavis previously requested changes Mar 7, 2018
Copy link
Copy Markdown
Member

@kumavis kumavis left a comment

Choose a reason for hiding this comment

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

im going to take another pass over this, please wait

@kumavis kumavis dismissed their stale review March 8, 2018 22:17

made the cleanups i wanted

@kumavis kumavis merged commit 5fbfb0b into master Mar 13, 2018
@kumavis kumavis deleted the i3076-UseStorageLocalInstead branch March 13, 2018 22:48
@danfinlay danfinlay restored the i3076-UseStorageLocalInstead branch March 14, 2018 17:10
@danfinlay
Copy link
Copy Markdown
Contributor Author

Yes, they are migrated to the new storage model, and the old storage model is kept around, in case the new one fails.

Gudahtt added a commit to Gudahtt/metamask-extension that referenced this pull request Sep 16, 2019
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.
@Gudahtt Gudahtt mentioned this pull request Sep 16, 2019
Gudahtt added a commit that referenced this pull request Sep 16, 2019
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.
@whymarrh whymarrh deleted the i3076-UseStorageLocalInstead branch November 19, 2019 14:59
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.

5 participants