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

Store Sapling & Orchard note commitment trees in finalized and non-finalized state #3563

Closed
1 task
Tracked by #3134
conradoplg opened this issue Feb 16, 2022 · 11 comments · Fixed by #3818
Closed
1 task
Tracked by #3134

Store Sapling & Orchard note commitment trees in finalized and non-finalized state #3563

conradoplg opened this issue Feb 16, 2022 · 11 comments · Fixed by #3818
Assignees
Labels
A-state Area: State / database changes C-enhancement Category: This is an improvement lightwalletd any work associated with lightwalletd

Comments

@conradoplg
Copy link
Collaborator

conradoplg commented Feb 16, 2022

Motivation

For #3156 we need to be able to return a Sapling & Orchard tree state (a note commitment tree, represented as a frontier, like we already do) for multiple block heights. However, while we do store the Sprout trees for every height, for Sapling and Orchard we only store it for the finalized tip (and also for non-finalized tips, in memory).

ZecWallet Lite expects to have a tree state for every block from Sapling or Orchard activation, for good performance on first use.

We don't need to store them for every height since z_gettreestate supports a skipHash return value that requests the caller to look up a tree in a previous height. But we do need to store them every X blocks for some value of X.

Designs

  • Change the sync to store all the Orchard & Sapling note commitment trees in the finalized and non-finalized state. This will require a database version bump.

Follow Up Tasks

Optimisation:

@conradoplg conradoplg added C-enhancement Category: This is an improvement S-needs-triage Status: A bug report needs triage labels Feb 16, 2022
@teor2345

This comment was marked as resolved.

@teor2345

This comment was marked as resolved.

@ftm1000
Copy link

ftm1000 commented Feb 17, 2022

@ftm1000 ftm1000 assigned conradoplg and upbqdn and unassigned conradoplg and upbqdn Feb 18, 2022
@ftm1000 ftm1000 removed the S-needs-triage Status: A bug report needs triage label Feb 21, 2022
@conradoplg conradoplg added P-High 🔥 A-state Area: State / database changes labels Feb 24, 2022
@teor2345
Copy link
Contributor

teor2345 commented Feb 24, 2022

Aditya told us that ZecWallet requires every block's tree state for good performance. This will cost us about 1.5 GB for Sapling.

@upbqdn
Copy link
Member

upbqdn commented Mar 3, 2022

Should the note commitment trees be included in the non-finalized state as well?

@conradoplg
Copy link
Collaborator Author

Should the note commitment trees be included in the non-finalized state as well?

I think so, since the non-finalized blocks can be queried too

@upbqdn
Copy link
Member

upbqdn commented Mar 4, 2022

Note: We store and query Sprout note commitment trees by anchors, not heights. I updated the description of the issue so that it reflects this.

Since #3156 will query the note commitment trees by heights, we will have to have two more column families in the database: sapling_note_commitment_tree_by_height and orchard_note_commitment_tree_by_height. Similarly, for the non-finalized state, the Chain structure will have two more members. I will use the same names for those.

I'm not going to include the Sprout note commitment trees because lightwalletd doesn't require them.

@upbqdn upbqdn changed the title Store additional tree states in the database Store Sapling & Orchard note commitment trees in finalized and non-finalized state Mar 4, 2022
@teor2345
Copy link
Contributor

teor2345 commented Mar 7, 2022

Since #3156 will query the note commitment trees by heights, we will have to have two more column families in the database: sapling_note_commitment_tree_by_height and orchard_note_commitment_tree_by_height. Similarly, for the non-finalized state, the Chain structure will have two more members. I will use the same names for those.

It looks like we already store sapling and orchard trees by height in the finalized state?
(But we delete every height except for the latest height.)

https://github.com/ZcashFoundation/zebra/blob/main/book/src/dev/rfcs/0005-state-updates.md#rocksdb-data-structures

self.zs_insert(
sapling_note_commitment_tree_cf,
height,
note_commitment_trees.sapling,
);
self.zs_insert(
orchard_note_commitment_tree_cf,
height,
note_commitment_trees.orchard,
);

@teor2345
Copy link
Contributor

teor2345 commented Mar 7, 2022

I split out this optimisation task, because it's optional:

But we might need it to get better performance.

@ftm1000 ftm1000 added the lightwalletd any work associated with lightwalletd label Mar 16, 2022
@upbqdn
Copy link
Member

upbqdn commented Mar 17, 2022

I realized I forgot to mention this issue in the corresponding PR, so it didn't get closed. Should we close this?

@conradoplg
Copy link
Collaborator Author

I realized I forgot to mention this issue in the corresponding PR, so it didn't get closed. Should we close this?

Sure! I linked the PR and I'm closing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-state Area: State / database changes C-enhancement Category: This is an improvement lightwalletd any work associated with lightwalletd
Projects
None yet
4 participants