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

Track anchors and note commitment trees in zebra-state #2458

Merged
merged 49 commits into from
Jul 29, 2021
Merged

Conversation

dconnolly
Copy link
Contributor

@dconnolly dconnolly commented Jul 7, 2021

Motivation

In order to maintain shielded note commitment trees, we will need to update our state for non-finalized and finalized chains, keep those trees up to date in the non-finalized state as we validate blocks, and save down the serialized trees to finalized state for the tip, and update our validated anchor sets as we update the trees.

Specifications

Designs

#2425

Solution

Depends on #2407
Resolves #1320

Review

Reviewer Checklist

  • Code implements Specs and Designs
  • Tests for Expected Behaviour
  • Tests for Errors

Follow Up Work

Use the new state requests to look up anchors during transaction validation.


This change is Reviewable

@dconnolly dconnolly added A-consensus Area: Consensus rule updates A-rust Area: Updates to Rust code labels Jul 7, 2021
@teor2345 teor2345 changed the base branch from main to incremental-note-commitment-trees July 8, 2021 02:08
@teor2345 teor2345 changed the base branch from incremental-note-commitment-trees to main July 8, 2021 02:08
Copy link
Contributor

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

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

This PR also contains changes from #2407.

We'll need to rebase on #2407 and change the merge base before we can do a review.

Copy link
Contributor

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

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

This PR looks ok so far, but we will probably want to make the following changes before we merge:

  • split the sprout-specific code into another PR, because there are no sprout note commitment trees yet
  • add tests

Copy link
Collaborator

@conradoplg conradoplg left a comment

Choose a reason for hiding this comment

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

I've addressed comments and advanced a bit on the implementation.

There is one point in particular that I'd like feedback on, I've mentioned in the design ticket. But I think the first approach I've mentioned is being used for nullifiers too so I think it seems the best approach. You can check aee5e8f specifically to validate if the approach makes sense.

Current status:
I implemented the finalized state handling of Orchard anchors and trees. I implemented serde::(De)Serialize for the Orchard tree node (to allow using incrementalmerkletree serialization) and still need to call it from (Into)FromDisk. Because of that tests are currently failing.

@conradoplg conradoplg force-pushed the tree-state branch 3 times, most recently from e17e547 to 423fd22 Compare July 20, 2021 23:00
@dconnolly
Copy link
Contributor Author

I think we're almost ready to merge, I just have 2 final questions:

  1. How can we have sapling note commitments in block 1, before sapling activation?
  2. Have we tested a full sync with the new state version, up to the current tip on testnet and mainnet?

On 1, I made a comment:
#2458 (comment)

@dconnolly
Copy link
Contributor Author

I've just realized that this PR uses sapling_note_commitment_tree but 0005-state-updates.md uses sapling_incremental and similarly for Orchard. Which one is best?

Since we have multiple trees, I like the naming in this PR

@dconnolly
Copy link
Contributor Author

dconnolly commented Jul 28, 2021

I think we're almost ready to merge, I just have 2 final questions:

  1. How can we have sapling note commitments in block 1, before sapling activation?
  2. Have we tested a full sync with the new state version, up to the current tip on testnet and mainnet?

On 2, I've kicked off a single node sync for Mainnet (https://github.com/ZcashFoundation/zebra/actions/runs/1073455087) based on this branch. EDIT: synced at least to block height 1212205 on Mainnet https://console.cloud.google.com/logs/query;query=insertId%3D%221v1sdh9o692ecbd7a%22%20timestamp%3E%222021-07-27T12:22:17.617Z%22%20resource.type%3D%22gce_instance%22%20resource.labels.instance_id%3D%222142592117257369472%22%20resource.labels.zone%3D%22us-central1-a%22%20severity%3E%3DDEFAULT;timeRange=2021-07-28T12:21:07.000Z%2F2021-07-28T12:21:07.000Z--PT0S?authuser=1&project=zealous-zebra

Copy link
Contributor Author

@dconnolly dconnolly left a comment

Choose a reason for hiding this comment

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

Made it to block height 1333338 on mainnet, lgtm!

Reviewed 1 of 11 files at r1, 2 of 14 files at r2, 5 of 10 files at r5, 13 of 13 files at r8, 3 of 3 files at r9, 1 of 2 files at r10, 1 of 1 files at r11.
Reviewable status: all files reviewed, 18 unresolved discussions (waiting on @conradoplg, @dconnolly, @jvff, and @teor2345)

@dconnolly dconnolly requested a review from teor2345 July 28, 2021 17:53
@dconnolly
Copy link
Contributor Author

@conradoplg since I originally opened this PR, I can't approve it, or commandeer it, but I'm good to merge, maybe @teor2345 can give final merge approval?

@dconnolly dconnolly closed this Jul 28, 2021
@dconnolly
Copy link
Contributor Author

dconnolly commented Jul 28, 2021

@conradoplg since I originally opened this PR, I can't approve it, or commandeer it, but I'm good to merge, maybe @teor2345 can give final merge approval?

Or I could do an admin override merge 😏
(oops accidental close)

@dconnolly dconnolly reopened this Jul 28, 2021
@conradoplg
Copy link
Collaborator

@dconnolly thanks for testing that!

There's a pending request change from @teor2345, though you have already answered it. I'm fine with dismissing it if you think it's OK, or we can just wait for their approval.

@teor2345
Copy link
Contributor

@dconnolly thanks for testing that!

There's a pending request change from @teor2345, though you have already answered it. I'm fine with dismissing it if you think it's OK, or we can just wait for their approval.

I'd like to do a quick fix to the comments and test variable names to avoid confusion.

Also please remind @mpguerra to update the changelog, if you merge this PR before the release is tagged.

conradoplg added a commit that referenced this pull request Jul 28, 2021
teor2345
teor2345 previously approved these changes Jul 28, 2021
Copy link
Contributor

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

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

Thanks this is great!

I'm having a bit of trouble keeping track of all the conversations and reviewable comments, if I've missed one, please merge anyway.

@dconnolly dconnolly merged commit e719c46 into main Jul 29, 2021
@dconnolly dconnolly deleted the tree-state branch July 29, 2021 13:37
mpguerra added a commit that referenced this pull request Jul 29, 2021
mpguerra added a commit that referenced this pull request Jul 29, 2021
* Draft CHANGELOG for Zebra 1.0.0-alpha.14

* Add PR #2533 to CHANGELOG

* Apply suggestions from code review

Co-authored-by: teor <teor@riseup.net>

* Remove entry about updating the changelog

* move #2497

* add #2529

* Add a missing space

* Add #2458, #2525, #2486, #2542 and  #2539 to CHANGELOG

Co-authored-by: teor <teor@riseup.net>
Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>
conradoplg added a commit that referenced this pull request Aug 3, 2021
* Add Orchard support to HistoryTree

* Handle network upgrades in HistoryTree

* Add additional methods to save/load HistoryTree

* Apply suggestions from code review

Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>

* Clarification of Entry documentation

* Improvements from code review

* Add HistoryTree tests

* Improved test comments and variable names based on feedback from #2458 on similar test

* Update zebra-chain/src/history_tree.rs

Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>

* Use type aliases for V1 and V2 history trees

Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>
Co-authored-by: teor <teor@riseup.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-consensus Area: Consensus rule updates A-rust Area: Updates to Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add sapling and orchard anchors to zebra-state
4 participants