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

feat: vks birthdays #1415

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

feat: vks birthdays #1415

wants to merge 6 commits into from

Conversation

mateuszjasiuk
Copy link
Collaborator

@mateuszjasiuk mateuszjasiuk commented Dec 17, 2024

  • Adds vks birthdays
  • Adds migration

How it works?

  • when you create a new account we store a timestamp and the source of the account, either imported or generated
  • based on source we create DatedViewingKeys in namadillo. For imported accounts block_height in DatedViewingKeys is always 0(as it was created before, and we do not have the UI to insert timestamp or block_height). For generated accounts we get the timestamp and query indexer for corresponding block height(we look for block which timestamp is exactly the same or slightly lower)

How to test?

  • Add new account using import flow, look at shielded sync - it should start from 0%
  • Add new account using generate flow, look at shielded sync - it should start from the last processed block

Migrations

To migrate the data I've added schemas for each versions of Vault and the logic is as follows:

  • we check the version of the data by decoding it using schemas, starting from the newest version(more about it in code)
  • once we know persisted version we apply migrations starting from persisted and ending at newest
  • example: currently persisted data is at version 2. newest version is 4. We try to decode data starting from schemaV4 -> schemaV3 -> schemaV2. Once we know that data is at version 2 we apply migrations: v2->v3, v3-v4 and persist the Vault
  • next time when you run migration it does nothing as detected version is 4

To test migrations you can checkout main, add account, then checkout this branch and check if entries in vault have source and timestamp specified

@mateuszjasiuk mateuszjasiuk changed the title Feat/vks birthdays feat: vks birthdays Dec 17, 2024
@mateuszjasiuk mateuszjasiuk marked this pull request as ready for review December 19, 2024 09:04
@mateuszjasiuk mateuszjasiuk requested review from jurevans, euharrison and pedrorezende and removed request for jurevans and euharrison December 19, 2024 09:35
const isShielded = type === AccountType.ShieldedKeys;
const account: Account = {
alias,
address,
type,
pseudoExtendedKey,
source,
timestamp,
};
if (isShielded) {
account.viewingKey = owner;
Copy link
Collaborator

@jurevans jurevans Dec 19, 2024

Choose a reason for hiding this comment

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

Once thought: Move pseudoExtendedKey (and maybe timestamp if it's only used for shielded accounts) down here, so we don't return undefined values in transparent accounts. If we don't need source in Namadillo, I would vote to drop it from here. Maybe timestamp can be a shielded-only thing too?

@@ -185,12 +185,13 @@ export const toPublicAccount = (derivedAccount: DerivedAccount): Account => {
alias,
address,
type,
pseudoExtendedKey,
source,
Copy link
Collaborator

Choose a reason for hiding this comment

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

One last comment - if we don't need source on transparent, I would maybe omit it here. It gets appended below for shielded which makes sense!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I forgot to remove the line :D

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done!

Copy link
Collaborator

@jurevans jurevans left a comment

Choose a reason for hiding this comment

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

Code LGTM! Just one comment about whether source should be included in transparent accounts. Tested migrating from old store, works great!

Copy link
Contributor

@euharrison euharrison left a comment

Choose a reason for hiding this comment

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

Very nice! ✅

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.

4 participants