-
Notifications
You must be signed in to change notification settings - Fork 34
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
Create a Dependency that can load checkpoints from bundle #1316
Create a Dependency that can load checkpoints from bundle #1316
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK with minor reservations about the default BundleCheckpointURLProvider.
Sources/ZcashLightClientKit/Checkpoint/BundleCheckpointURLProvider.swift
Show resolved
Hide resolved
d3f82c1
to
d2016cc
Compare
Github Action keeps failing. I tested if updating to the latest release of Xcode fixes it and it does. I don't have much details about that because the logs don't show any details. I created another PR for that so that change is not mixed up with this one. |
d2016cc
to
b6edb62
Compare
/// - Returns: a `Checkpoint` that will allow the wallet to manage funds from the given `height` | ||
/// onwards. | ||
/// - Note: When the user knows the exact height of the first received funds for a wallet, | ||
/// the effective birthday of that wallet is `transaction.height - 1`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I misremembering what we decided for this? I thought that wallets were supposed to scan the block at the birthday height (thus making the - 1
here unnecessary).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be me having outdated concepts in my mind. Last time I discussed checkpoints with @str4d he had mentioned that to spend funds at block X, one would have to know tree state of height X - 1
or prior. If it's not the case I should change this documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That could be correct; my understanding of this might not be up-to-date. @str4d ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In zcash/librustzcash#907 the definition of "wallet birthday" was changed from "height at which the wallet was created" (which is by construction before any block containing a wallet transaction) to "height at which the wallet first received a transaction". The old definition meant that the highest valid value for wallet birthday was indeed transaction.height - 1
, but with the new definition it is just transaction.height
. The X - 1
is now handled in the create_account
API: you are required to pass in a Sapling tree state that is for height X - 1
(meaning that if what you have is the wallet's seed phrase and birthday, you need to look up the checkpoint at birthday - 1
), and the wallet's birthday is calculated internally by the Rust side from that as tree_state.height + 1
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also getting more complicated shortly, as wallets may have differing Orchard and Sapling birthday heights in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on what @str4d commented, then the note is accurate.
The current checkpoint from bundle logic is to retrieve the given height if available and or return the closes preceding height available.
If the bundle has heights 1000 and 999, if you request 1000 it will give you 1000, not 999. That logic of -1 or +1 is actually is left to the caller.
Do we agree this is the needed behavior? Otherwise we can file a new issue for it and make those changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also getting more complicated shortly, as wallets may have differing Orchard and Sapling birthday heights in the future.
🫠 probably it is for the best to actually keep themin(saplingBirthday, orchardBirthday)
so be "the" birthday for UX purposes, where None
is mapped to BlockHeight.max
so it picks the available value if one is absent
Sources/ZcashLightClientKit/Checkpoint/BundleCheckpointSource.swift
Outdated
Show resolved
Hide resolved
Sources/ZcashLightClientKit/Checkpoint/BundleCheckpointURLProvider.swift
Outdated
Show resolved
Hide resolved
Sources/ZcashLightClientKit/Checkpoint/BundleCheckpointURLProvider.swift
Outdated
Show resolved
Hide resolved
Sources/ZcashLightClientKit/Checkpoint/BundleCheckpointURLProvider.swift
Outdated
Show resolved
Hide resolved
@@ -1,5 +1,5 @@ | |||
// | |||
// WalletBirthday+Constants.swift | |||
// Checkpoint+helpers.swift | |||
// ZcashLightClientKit | |||
// | |||
// Created by Francisco Gindre on 7/28/21. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Created by Francisco Gindre on 7/28/21. | |
// Created by Francisco Gindre on 2021-07-28. |
Sources/ZcashLightClientKit/Checkpoint/CheckpointSourceFactory.swift
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK with minor comments.
Thank you @daira, I will address this comments and tidy up a bit the commits. |
8b66a53
to
6139754
Compare
Closes Electric-Coin-Company#1315 This PR introduces small changes on each commit. Things done: rename Checkpoint+Constants to Checkpoint+helpers Move `Checkpoint` from Model folder to Checkpoint folder Remove unused function `ofLatestCheckpoint` from BlockHeight Create a protocol called `CheckpointSource` that contains the relevant functionality to get checkpoints from Bundle Create a set of tests that check that functionality is maintained when a `CheckpointSource` is used instead of Checkpoint helpers Implement `BundleCheckpointSource` and add Tests Code clean up: move `BundleCheckpointURLProvider` to its own file Code clean up: `Checkpoint+helpers` match file header Replace use of `Checkpoint.birthday(with:network)` with CheckpointSource Revert "Remove unused function `ofLatestCheckpoint` from BlockHeight" addresses PR comment from @daira This reverts commit d0e154d, since it modifies a public API and it was not the goal of this PR. Update Sources/ZcashLightClientKit/Checkpoint/BundleCheckpointSource.swift Use a decent Date Format Co-authored-by: Daira Emma Hopwood <[email protected]> Improve documentation on BundleCheckpointURLProvider Co-authored-by: Daira Emma Hopwood <[email protected]> Improve documentation on BundleCheckpointURLProvider Co-authored-by: Daira Emma Hopwood <[email protected]> use YYYY-mm-dd on file header author: @daira Co-authored-by: Daira Emma Hopwood <[email protected]> Add test that verifies that the exact height is returned if available
6139754
to
6625ffd
Compare
Create a Dependency that can load checkpoints from bundle
Closes #1315
This PR introduces small changes on each commit.
Things done:
Checkpoint
to their own filesThis code review checklist is intended to serve as a starting point for the author and reviewer, although it may not be appropriate for all types of changes (e.g. fixing a spelling typo in documentation). For more in-depth discussion of how we think about code review, please see Code Review Guidelines.
Author
Reviewer