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

Create a Dependency that can load checkpoints from bundle #1316

Merged

Conversation

pacu
Copy link
Contributor

@pacu pacu commented Oct 30, 2023

Create a Dependency that can load checkpoints from bundle

Closes #1315

This PR introduces small changes on each commit.
Things done:

This 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

  • Self-review: Did you review your own code in GitHub's web interface? Code often looks different when reviewing the diff in a browser, making it easier to spot potential bugs.
  • Automated tests: Did you add appropriate automated tests for any code changes?
  • Code coverage: Did you check the code coverage report for the automated tests? While we are not looking for perfect coverage, the tool can point out potential cases that have been missed.
  • Documentation: Did you update Docs as appropiate? (E.g README.md, etc.)
  • Run the app: Did you run the app and try the changes?
  • Did you provide Screenshots of what the App looks like before and after your changes as part of the description of this PR? (only applicable to UI Changes)
  • Rebase and squash: Did you pull in the latest changes from the main branch and squash your commits before assigning a reviewer? Having your code up to date and squashed will make it easier for others to review. Use best judgement when squashing commits, as some changes (such as refactoring) might be easier to review as a separate commit.

Reviewer

  • Checklist review: Did you go through the code with the Code Review Guidelines checklist?
  • Ad hoc review: Did you perform an ad hoc review? In addition to a first pass using the code review guidelines, do a second pass using your best judgement and experience which may identify additional questions or comments. Research shows that code review is most effective when done in multiple passes, where reviewers look for different things through each pass.
  • Automated tests: Did you review the automated tests?
  • Manual tests: Did you review the manual tests?You will find manual testing guidelines under our manual testing section
  • How is Code Coverage affected by this PR? We encourage you to compare coverage befor and after your changes and when possible, leave it in a better place. Learn More...
  • Documentation: Did you review Docs, README.md, LICENSE.md, and Architecture.md as appropriate?
  • Run the app: Did you run the app and try the changes? While the CI server runs the app to look for build failures or crashes, humans running the app are more likely to notice unexpected log messages, UI inconsistencies, or bad output data.

Copy link
Contributor

@nuttycom nuttycom left a 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.

@pacu pacu force-pushed the custom-checkpoint-provisioning branch from d3f82c1 to d2016cc Compare October 31, 2023 17:43
@pacu
Copy link
Contributor Author

pacu commented Oct 31, 2023

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.

#1319

/// - 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`.
Copy link
Contributor

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).

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

Copy link
Contributor

@daira daira Nov 7, 2023

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 ?

Copy link
Collaborator

@str4d str4d Nov 7, 2023

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.

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 also getting more complicated shortly, as wallets may have differing Orchard and Sapling birthday heights in the future.

Copy link
Contributor Author

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.

Copy link
Contributor Author

@pacu pacu Nov 8, 2023

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

@@ -1,5 +1,5 @@
//
// WalletBirthday+Constants.swift
// Checkpoint+helpers.swift
// ZcashLightClientKit
//
// Created by Francisco Gindre on 7/28/21.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Created by Francisco Gindre on 7/28/21.
// Created by Francisco Gindre on 2021-07-28.

Copy link
Contributor

@daira daira left a 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.

@pacu
Copy link
Contributor Author

pacu commented Nov 7, 2023

Thank you @daira, I will address this comments and tidy up a bit the commits.

@pacu pacu force-pushed the custom-checkpoint-provisioning branch from 8b66a53 to 6139754 Compare November 8, 2023 18:13
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
@pacu pacu force-pushed the custom-checkpoint-provisioning branch from 6139754 to 6625ffd Compare November 8, 2023 18:46
@LukasKorba LukasKorba merged commit 5644f89 into Electric-Coin-Company:main Nov 15, 2023
1 check passed
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.

Create a Dependency that can load checkpoints from bundle
5 participants