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

zcash_client_sqlite: Ensure that Orchard and Sapling checkpoints are always available for the same block heights. #1262

Merged

Conversation

nuttycom
Copy link
Contributor

@nuttycom nuttycom commented Mar 12, 2024

This fixes an error that was causing it to be impossible to make cross-pool transactions when an anchor was needed for each pool, but alternating blocks held only Sapling or only Orchard notes. Prior to this fix, checkpoints were only created in the note commitment tree for a block for whatever pool had activity within that block; for example, if a block contained Orchard actions but no Sapling inputs or outputs, only an Orchard checkpoint was being created.

The fix for this issue requires that the initial tree state for each pool be available for each range of scanned blocks, so that we can be sure that we know the correct note commitment tree to position to checkpoint in that pool for a block that contains no inputs or outputs for the pool. As an ancillary benefit, this then will make the implementation of #982 trivial.

Copy link
Contributor

@str4d str4d left a comment

Choose a reason for hiding this comment

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

Flushing review comments as of e1c0f25

zcash_client_backend/src/data_api.rs Show resolved Hide resolved
zcash_client_backend/src/data_api/chain.rs Show resolved Hide resolved
zcash_client_sqlite/src/lib.rs Outdated Show resolved Hide resolved
zcash_client_sqlite/src/lib.rs Outdated Show resolved Hide resolved
zcash_client_sqlite/src/testing.rs Outdated Show resolved Hide resolved
zcash_client_sqlite/src/testing.rs Outdated Show resolved Hide resolved
zcash_client_sqlite/src/testing.rs Outdated Show resolved Hide resolved
@nuttycom nuttycom force-pushed the sqlite_wallet/fix_multi_pool_checkpointing branch 3 times, most recently from 47a7f1a to ae3f56d Compare March 12, 2024 22:56
Copy link

codecov bot commented Mar 12, 2024

Codecov Report

Attention: Patch coverage is 88.58447% with 25 lines in your changes are missing coverage. Please review.

Project coverage is 63.57%. Comparing base (a788fc9) to head (fb46ff9).

❗ Current head fb46ff9 differs from pull request most recent head a046088. Consider uploading reports for the commit a046088 to get more accurate results

Files Patch % Lines
zcash_client_sqlite/src/lib.rs 84.25% 17 Missing ⚠️
zcash_client_backend/src/data_api/chain.rs 66.66% 4 Missing ⚠️
zcash_client_sqlite/src/testing.rs 96.87% 3 Missing ⚠️
zcash_client_backend/src/scanning.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1262      +/-   ##
==========================================
+ Coverage   63.26%   63.57%   +0.31%     
==========================================
  Files         121      121              
  Lines       13509    13646     +137     
==========================================
+ Hits         8547     8676     +129     
- Misses       4962     4970       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nuttycom nuttycom force-pushed the sqlite_wallet/fix_multi_pool_checkpointing branch from cbb01e5 to 47866a7 Compare March 12, 2024 23:56
@nuttycom
Copy link
Contributor Author

nuttycom commented Mar 12, 2024

force-pushed to address comments from code review & disable tests that require test framework changes.

@nuttycom nuttycom marked this pull request as ready for review March 12, 2024 23:57
@nuttycom nuttycom changed the title Sqlite wallet/fix multi pool checkpointing zcash_client_sqlite: Ensure that Orchard and Sapling checkpoints are always available for the same block heights. Mar 13, 2024
@nuttycom nuttycom requested a review from str4d March 13, 2024 00:07
…anned range.

In order to support constructing the anchor for multiple pools with a
common anchor height, we must be able to checkpoint each note commitment
tree (and consequently compute the root) at that height. Since we may
not have the information in the tree needed to do so, we require that it
be provided.

As a bonus, this change makes it possible to improve the UX around
spendability, because we will no longer require subtree ranges below
received notes to be fully scanned; the inserted frontier provides
sufficient information to make them spendable.
@nuttycom nuttycom force-pushed the sqlite_wallet/fix_multi_pool_checkpointing branch from 47866a7 to fb46ff9 Compare March 13, 2024 00:15
@nuttycom
Copy link
Contributor Author

force-pushed to rebase on main

Copy link
Contributor

@str4d str4d left a comment

Choose a reason for hiding this comment

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

utACK a046088

Comment on lines +766 to +768
'a,
H,
I: Iterator<Item = &'a BlockHeight>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nit: I think the 'a, I: .. can be inlined by making the argument

checkpoint_heights: impl Iterator<Item = &'_ BlockHeight>,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fooled around with a couple of things and couldn't get it to work, so went with the simple thing. :)

@nuttycom nuttycom merged commit b3d06ba into zcash:main Mar 13, 2024
19 of 23 checks passed
@nuttycom nuttycom deleted the sqlite_wallet/fix_multi_pool_checkpointing branch March 13, 2024 01:01
@AArnott
Copy link
Contributor

AArnott commented Mar 17, 2024

Missing a CHANGELOG addition for this? Ideally it would include not just the changed APIs, but a brief explanation of how to come up with the new ChainState argument that these APIs now require.

@nuttycom
Copy link
Contributor Author

Missing a CHANGELOG addition for this? Ideally it would include not just the changed APIs, but a brief explanation of how to come up with the new ChainState argument that these APIs now require.

@AArnott thanks for noticing, I'll fix this up. The conversion you want is https://github.com/zcash/librustzcash/blob/main/zcash_client_backend/src/proto.rs#L297-L307

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.

3 participants