Skip to content
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

metadata: encryption version migration #8825

Closed
wants to merge 6 commits into from

Conversation

mroz22
Copy link
Contributor

@mroz22 mroz22 commented Jun 28, 2023

Based on #8646 which is a PR that introduces changes to metadata data model in reducers. That PR is basically ready to be merged but as it does not bring any new features I am hesitant to do it. Also I dont want to bloat it with more changes so I decided to build on it instead. I am also stealing some ideas from #8567

Commits

Todos:

  • unit tests
  • e2e tests
  • couple of todos and areas for improvements

How does it work

  1. user tries to add a label, initation process kicks in as usual
  2. once data provider is connected and metadata keys (for the latest encryption version) are derived we fetch list of all files from data provider
  3. if all labelable entities (currently discovered) have associated file in what we fetchted in 2 no further action is needed
  4. else we separate labelable entities that don't have their counterpart in dataprovider and derive legacy keys for them
  5. then we fetch legacy files from data provider
  6. we decrypt legacy files using legacy keys, load them into application memory and encrypt them using new keys and upload them to data provider.
  7. if there was no legacy file match in 5, we create dummy files and upload them as well. this ensures that next time metadata is initiated, we are likely to be able to stop at point 3 (unless user created a new account in the meantime somewhere else)

Testing tips

  1. create an empty account on dropbox
  2. go to https://suite.trezor.io/web
  3. create some labels
  4. open build of this branch
  5. enable labeling
  6. labels should be there
  7. forget device, enable labeling again. you should not be prompted on device. labels should still be there

Drawbacks

  • we can not migrate all labels at once because we simply can't be sure we know them. Labels are bound to 'labelable entities' which are now accounts and wallets. So whenever user adds a labelable entity, we must run "metadata discovery" including migration if needed. So it is very well possible that user might migrate his data on day, they might be using suite without "enable labeling prompt" for years, and then, after adding some long unused passphrase or account, user will need to confirm labeling on device again.
  • possibility of mismatch between versions of suite. after this is release user opens updated version of suite, migrates data, then opens outdated version of suite and works with labeling. Under current implementation labels added in the outdated version will be lost.

@mroz22 mroz22 force-pushed the metadata-migrations branch 2 times, most recently from bf8966e to ea07c7a Compare June 30, 2023 15:40
@mroz22 mroz22 changed the title [wip] metadata: next steps [wip] metadata: encryption version migration Jun 30, 2023
@mroz22 mroz22 force-pushed the metadata-migrations branch 2 times, most recently from 37254af to 8bbad83 Compare July 7, 2023 09:15
Comment on lines +354 to +360
if (entity.type === 'device' && entity.status !== 'enabled') {
return;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

why this? sometimes not fetch?

Copy link
Contributor

Choose a reason for hiding this comment

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

this is for TS. but basically, what would you fetch if you don't have metadata enabled? 🤔

Comment on lines +358 to +365
const entityData = entity[encryptionVersion];
if (!entityData) {
return;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this makes me think "what does entityData mean?"
what about just?

if (!entity[encryptionVersion]) return

Copy link
Contributor

Choose a reason for hiding this comment

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

but then there is const { fileName, aesKey } = entityData; on the next line anyways

Comment on lines 957 to 964
const defaultEntityData =
entity.type === 'account'
? ({
accountLabel: '',
outputLabels: {},
addressLabels: {},
} as AccountLabels)
: ({ walletLabel: '' } as WalletLabels);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just a nitpick to think about. I think we are already defining this on a couple of places, maybe it could go to some single point of definition

Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines 993 to 977
if (!filesToMigrate || !filesToMigrate.length) {
return;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

nitpick according to m personal taste

!filesToMigrate?.length

Copy link
Contributor

Choose a reason for hiding this comment

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

@dahaca dahaca force-pushed the metadata-new-structure branch 2 times, most recently from c6a3cb9 to 6736de5 Compare July 21, 2023 15:08
@dahaca dahaca force-pushed the metadata-migrations branch 2 times, most recently from ab6f1f0 to 913bf8a Compare July 24, 2023 12:39
@dahaca dahaca marked this pull request as ready for review July 24, 2023 12:39
@dahaca dahaca changed the title [wip] metadata: encryption version migration metadata: encryption version migration Jul 24, 2023
@matejkriz matejkriz self-assigned this Jul 26, 2023
@dahaca dahaca added the labelling Naming of transactions and accounts label Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
labelling Naming of transactions and accounts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants