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

Fix the storage of anchors in the state #2563

Merged
merged 3 commits into from
Aug 4, 2021
Merged

Conversation

conradoplg
Copy link
Collaborator

@conradoplg conradoplg commented Aug 3, 2021

Motivation

#2407 added note commitment trees and anchors to the state. However I got the storage wrong: we should store the root as a key with an empty value (to make it work as a set) instead of using the height as the key and the root as the value.

This fixes that.

Specifications

N/A

Designs

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

Solution

Use the correct key/value

Review

Anyone can review this.

This is blocking regenerating the cached state, which in turn is blocking testing other state work.

After this is accepted we can regenerate the cached state.

Reviewer Checklist

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

Follow Up Work

N/A


This change is Reviewable

@conradoplg conradoplg requested a review from a team August 3, 2021 21:37
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.

Looks good!

Normally, we would increment the state version for a format change like this.

But I don't think we need to right now, because:

  • the previous state version was in the last release, but Zebra is still in alpha
  • we're going to increment the version for value pools soon anyway
    • so we'll clear out any heights in that column family
  • heights and anchors have different sizes, so they will never compare equal
    • so we'll never try to deserialize an anchor as () and panic
  • RocksDB allows different-sized keys in the same column family
  • there is no FromDisk implementation for anchors, and we don't impl FromDisk for keys
    • so we'll never try to deserialize a height as an anchor and panic

Also, if I'm wrong, and we do panic or get errors, we can just tell that one user to delete their database and re-sync.

Can someone double-check my reasoning here, and approve the PR?

@teor2345
Copy link
Contributor

teor2345 commented Aug 3, 2021

Or we can just increment the format version anyway, it doesn't cost us anything, because we haven't rebuilt the cached state yet.

@conradoplg
Copy link
Collaborator Author

Can someone double-check my reasoning here, and approve the PR?

Or we can just increment the format version anyway, it doesn't cost us anything, because we haven't rebuilt the cached state yet.

I agree with the reasoning but I also agree that we can just increment the version. I've just did that and will regenerate the state using this branch while I wait for a final approval.

Copy link
Contributor

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

@dconnolly dconnolly enabled auto-merge (squash) August 4, 2021 18:45
@dconnolly dconnolly merged commit 8747d66 into main Aug 4, 2021
@dconnolly dconnolly deleted the fix-anchors-storage branch August 4, 2021 18:50
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