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(state): Avoid temporary failures verifying the first non-finalized block or attempting to fork the chain before the final checkpoint #6810

Merged
merged 7 commits into from
Aug 21, 2023

Conversation

arya2
Copy link
Contributor

@arya2 arya2 commented Jun 2, 2023

Motivation

This PR updates the can_fork_chain_at() method in zebra-state to ignore blocks below the finalized tip and fixes a bug where the first block past the final checkpoint will fail verification if it arrives in zebra-state before the final checkpoint block is written to disk.

Close #6388
Close #5125

Part of #5709

Solution

  • Add a can_fork_chain_at_hashes flag to SentHashes
  • Add and use a can_fork_chain_at(hash) method to SentHashes that checks the new flag
  • When closing finalized block write channel:
    • Replace block_write_sent_hashes with an empty SentHashes and mark can_fork_chain_at_hashes as true
    • Start committing queued non-finalized child blocks of finalized tip

Related:

  • Adds shrink_to_fit() calls in prune_by_height()

Review

This is low-priority.

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?

@arya2 arya2 added A-consensus Area: Consensus rule updates C-cleanup Category: This is a cleanup P-Low ❄️ I-heavy Problems with excessive memory, disk, or CPU usage A-state Area: State / database changes C-tech-debt Category: Code maintainability issues labels Jun 2, 2023
@arya2 arya2 self-assigned this Jun 2, 2023
@github-actions github-actions bot added the C-bug Category: This is a bug label Jun 2, 2023
@arya2 arya2 marked this pull request as ready for review June 2, 2023 03:38
@arya2 arya2 requested a review from a team as a code owner June 2, 2023 03:38
@arya2 arya2 requested review from teor2345 and removed request for a team June 2, 2023 03:38
@codecov
Copy link

codecov bot commented Jun 2, 2023

Codecov Report

Merging #6810 (5b51b9f) into main (77ad91c) will increase coverage by 0.60%.
Report is 66 commits behind head on main.
The diff coverage is 68.88%.

❗ Current head 5b51b9f differs from pull request most recent head 55bf5af. Consider uploading reports for the commit 55bf5af to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6810      +/-   ##
==========================================
+ Coverage   77.53%   78.14%   +0.60%     
==========================================
  Files         310      308       -2     
  Lines       41933    41055     -878     
==========================================
- Hits        32513    32081     -432     
+ Misses       9420     8974     -446     

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.

"non-finalized" and "finalized" are outdated terms that we're trying to move away from, because they were very confusing during the audit. When we're talking about the verification status of blocks, we use "semantically verified", "checkpoint verified" or "contextually verified".

But it's ok to say "finalized queue" when talking about block storage, or which state blocks are queued for.

There's a list of name changes in ticket #6793 which might be helpful.

Edit: name changes have finished

@teor2345 teor2345 dismissed their stale review June 12, 2023 00:40

Moved blockers to another ticket

@teor2345 teor2345 added the do-not-merge Tells Mergify not to merge this PR label Jun 12, 2023
@dconnolly dconnolly removed the do-not-merge Tells Mergify not to merge this PR label Jun 14, 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.

Just marking this as needing changes.

@arya2 arya2 added the S-waiting-on-author Status: waiting on the ticket or PR author label Jun 21, 2023
@teor2345 teor2345 added do-not-merge Tells Mergify not to merge this PR and removed do-not-merge Tells Mergify not to merge this PR labels Jun 30, 2023
@arya2 arya2 marked this pull request as draft July 3, 2023 22:06
@teor2345
Copy link
Contributor

I updated my review because the name changes in ticket #6793 have merged.

(There's no need to work on this PR any time soon, please check with Pili first.)

@arya2 arya2 added do-not-merge Tells Mergify not to merge this PR and removed do-not-merge Tells Mergify not to merge this PR labels Jul 21, 2023
@arya2 arya2 marked this pull request as ready for review July 25, 2023 18:39
@arya2 arya2 removed the S-waiting-on-author Status: waiting on the ticket or PR author label Jul 25, 2023
@arya2 arya2 added the I-slow Problems with performance or responsiveness label Jul 25, 2023
@arya2 arya2 requested a review from teor2345 July 25, 2023 19:43
@arya2 arya2 changed the title fix(state): ignore blocks below the finalized tip in can_fork_chain_at() fix(state): Avoid trying to fork the chain before the final checkpoint and temporary failures verifying the first non-finalized block Jul 25, 2023
@arya2 arya2 dismissed teor2345’s stale review July 25, 2023 20:36

This PR has been simplified and rewritten

@arya2 arya2 added the no-review-reminders Turn off review reminders label Jul 25, 2023
@arya2 arya2 changed the title fix(state): Avoid trying to fork the chain before the final checkpoint and temporary failures verifying the first non-finalized block fix(state): Avoid temporary failures verifying the first non-finalized block or attempting to fork the chain before the final checkpoint Jul 25, 2023
@arya2
Copy link
Contributor Author

arya2 commented Aug 9, 2023

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Aug 9, 2023

update

✅ Branch has been successfully updated

@arya2 arya2 requested a review from oxarbitrage August 9, 2023 16:39
@arya2
Copy link
Contributor Author

arya2 commented Aug 11, 2023

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Aug 11, 2023

update

✅ Branch has been successfully updated

@arya2 arya2 removed the no-review-reminders Turn off review reminders label Aug 17, 2023
Copy link
Contributor

@oxarbitrage oxarbitrage left a comment

Choose a reason for hiding this comment

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

I think this looks good, is short, clear and it seems to work.

What i am not totally sure is if it closes all the stuff that are inside the related tickets.

I will like @teor2345 to make the final review as they have more context in the tickets this is closing. I think the next few days could be a good time to merge this in.

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 this fix!

What i am not totally sure is if it closes all the stuff that are inside the related tickets.

That's a good question.

#5125 is partially resolved, I opened #7352 with the remaining work. (Which I don't think we should fix unless it actually happens.)

I checked the logs and #5709 is not resolved, it seems to be just as frequent as before this fix. (The warnings are still there, and syncing takes about the same amount of time.)

mergify bot added a commit that referenced this pull request Aug 21, 2023
@mergify mergify bot merged commit b413e3e into main Aug 21, 2023
@mergify mergify bot deleted the fix-can-fork-chain-at branch August 21, 2023 06:36
@teor2345 teor2345 mentioned this pull request Sep 1, 2023
40 tasks
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-state Area: State / database changes C-bug Category: This is a bug C-cleanup Category: This is a cleanup 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
4 participants