Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.

[Address Book v2] Fix AB v2 migration#2345

Merged
katspaugh merged 4 commits into
address-book-v2from
fix-migration
May 27, 2021
Merged

[Address Book v2] Fix AB v2 migration#2345
katspaugh merged 4 commits into
address-book-v2from
fix-migration

Conversation

@katspaugh

@katspaugh katspaugh commented May 27, 2021

Copy link
Copy Markdown
Contributor

What it solves

Resolves #2315.

There was a bug that we didn't migrate the safe owners. It used to be an object with name and address, and now it's just an address string.

Because of this bug, ImmortalDB was writing an empty {} into the SAFES storage.

How this PR fixes it

It now maps owners to addresses.

How to test it

Create (or update) a localStorage key _immortal|v2_RINKEBY__SAFES and paste the content of this key on production.

Same with the _immortal|v2_RINKEBY__ADDRESS_BOOK_STORAGE_KEY key.

After a page reload, _immortal|v2_RINKEBY__SAFES should be migrated, and _immortal|v2_RINKEBY__ADDRESS_BOOK_STORAGE_KEY completely removed.

@github-actions

Copy link
Copy Markdown

CLA Assistant Lite All Contributors have signed the CLA.

if (safes) {
safes.forEach((safeProps) => {
dispatch(addOrUpdateSafe(buildSafe(safeProps)))
})

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.

Refactored this along the way.

@katspaugh katspaugh marked this pull request as draft May 27, 2021 12:11
@github-actions

github-actions Bot commented May 27, 2021

Copy link
Copy Markdown

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

@katspaugh katspaugh marked this pull request as ready for review May 27, 2021 12:13
state.findIndex(
({ address, chainId }) => chainId === addressBookEntry.chainId && sameAddress(address, addressBookEntry.address),
)

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.

A giant red blob following, but it's just a move to a different file.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

But I assume there are some changes after that file move, aren't there?

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.

Yes 😄

localStorage.setItem(addressBookKey, JSON.stringify(addressBookToStore))

// update stored safe
localStorage.setItem(safesKey, JSON.stringify(migratedSafes))

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.

@fernandomg as you see, I've added a redundant call to set the storage item directly, so that we don't run in any async issues with the saveSafes (on the following line).

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.

smart!

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.

Is there a possibility for some race condition with immortaldb?

@katspaugh katspaugh May 27, 2021

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.

@mikheevm this migration is executed on store import time, and ImmortalDB kicks in after that (in the main index.ts).

ImmortalDB's self-healing mechanism is quite... interesting, and if we want to be 100% on the safe side, I would disable the IndexedDB storage. And in future ultimately replace ImmortalDB with just localStorage for simplicity.

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.

@mikheevm do you mean immortalDB overwriting localStorage with the old data that's in indexedDB?

@katspaugh katspaugh May 27, 2021

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.

I'll merge this PR now to unblock further development on the epic branch. Let's discuss what we will do with ImmortalDB in #2346.

localStorage.setItem(newKey, JSON.stringify(migratedAddressBook))

// Remove the old Address Book storage
localStorage.removeItem(storageKey)

@katspaugh katspaugh May 27, 2021

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 removes the old item only from the localStorage but ImmortalDB actually also saves to the IndexDB. It will remain there forever.

@fernandomg fernandomg May 27, 2021

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.

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.

True, restoring 👍

@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

@fernandomg fernandomg left a comment

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.

Nice! Just tested locally and it worked great.

Sorry for the abuse of the .entries/.fromEntries methods. I promise to use them only when necessary. 😬

@katspaugh katspaugh merged commit 2308c1f into address-book-v2 May 27, 2021
@katspaugh katspaugh deleted the fix-migration branch May 27, 2021 13:52
@github-actions github-actions Bot locked and limited conversation to collaborators May 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants