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

change(state): Deduplicate note commitment trees in non-finalized state #7239

Merged
merged 17 commits into from
Jul 18, 2023

Conversation

upbqdn
Copy link
Member

@upbqdn upbqdn commented Jul 17, 2023

Motivation

Address a part of #4784.

Solution

This PR stores only the first tree in a series of identical trees in the non-finalized state.

Review

This PR doesn't contain any additional tests. If reviewers have suggestions for suitable tests, I'd be glad to hear them.

Reviewer Checklist

  • Will the PR name make sense to users?
    • Does it need extra CHANGELOG info? (new features, breaking changes, large changes)
  • Are the PR labels correct?
  • Does the code do what the ticket and PR says?
    • Does it change concurrent code, unsafe code, or consensus rules?
  • How do you know it works? Does it have tests?

@upbqdn upbqdn added A-rust Area: Updates to Rust code I-heavy Problems with excessive memory, disk, or CPU usage I-slow Problems with performance or responsiveness A-state Area: State / database changes C-tech-debt Category: Code maintainability issues labels Jul 17, 2023
@upbqdn upbqdn requested a review from a team as a code owner July 17, 2023 23:02
@upbqdn upbqdn self-assigned this Jul 17, 2023
@upbqdn upbqdn requested review from dconnolly and removed request for a team July 17, 2023 23:02
@teor2345
Copy link
Contributor

It looks like this contains a copy of PR #7218. Do you mind if I change the PR base to make the diff smaller to review?

(I'm a big fan of this PR and I'm glad we're getting it done.)

@upbqdn
Copy link
Member Author

upbqdn commented Jul 17, 2023

This PR is built atop #7218, so we should merge that first. I forgot to target that branch instead of main. I don't think I can change it now.

@teor2345 teor2345 changed the base branch from main to fix-height-in-tests July 17, 2023 23:05
@teor2345
Copy link
Contributor

This PR is built atop #7218, so we should merge that first. I forgot to target that branch instead of main. I don't think I can change it now.

The base branch can be changed using the PR name edit button. (It's a bit weird but it works.)

IMG_3953

@upbqdn
Copy link
Member Author

upbqdn commented Jul 17, 2023

Excellent, I thought you couldn't change the base branch. It turns out you can.

@upbqdn
Copy link
Member Author

upbqdn commented Jul 17, 2023

(I wrote the two comments above at the same time as you posted yours, so they might seem a bit off.)

teor2345
teor2345 previously approved these changes Jul 17, 2023
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 all looks pretty good!

I want to check we handle chain forks correctly, is there a test we can do to make sure it works?

I think we have a lot of unit and proptest coverage already. But we could manually query the last 100 or so heights using the RPC, and do it in a loop?

I don't know if we need to check the RPC responses against zcashd or an unmodified Zebra. Do you think it's more important to test for panics or wrong data?

@upbqdn
Copy link
Member Author

upbqdn commented Jul 17, 2023

Do you think it's more important to test for panics or wrong data?

Both would have a severe impact, so they seem equally important to me.

I'll try the RPC on the last 100 blocks. I'll compare it to an unmodified Zebra.

@teor2345
Copy link
Contributor

Thanks!

If you have a script I'm happy to run it as well, it would be good to do a test during a fork.

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.

generally looks good, just one q about panics vs returning errors around Height

Base automatically changed from fix-height-in-tests to main July 18, 2023 04:54
@mergify mergify bot dismissed teor2345’s stale review July 18, 2023 04:54

The base branch was changed.

@upbqdn
Copy link
Member Author

upbqdn commented Jul 18, 2023

I synced the last ~ 1% of the Mainnet chain with this PR with no issues. Then, I got the tip with

zcash-cli getblockcount

which was 2160512. Then, I got the Sapling and Orchard treestates of the last 200 blocks with

for height in $(seq 2160312 2160512); do
    zcash-cli z_gettreestate "${height}"
done

Then, I switched to the main branch and collected the treestates of the same 200 blocks again. Zebra was still at the same tip after I collected the second batch. I diffed them, and there was no difference.

@upbqdn
Copy link
Member Author

upbqdn commented Jul 18, 2023

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 for the tests, that seems like a comprehensive check.

mergify bot added a commit that referenced this pull request Jul 18, 2023
@mergify mergify bot merged commit 1db4f56 into main Jul 18, 2023
@mergify mergify bot deleted the dedup-trees-in-nfs branch July 18, 2023 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rust Area: Updates to Rust code A-state Area: State / database changes C-tech-debt Category: Code maintainability issues I-heavy Problems with excessive memory, disk, or CPU usage I-slow Problems with performance or responsiveness
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Store only the first tree state in each series of identical tree states
4 participants