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): Stop re-downloading blocks that are in non-finalized side chains #6335

Merged
merged 15 commits into from
Mar 24, 2023

Conversation

arya2
Copy link
Contributor

@arya2 arya2 commented Mar 15, 2023

Motivation

The sync task, inbound downloader, and the block verifier need to check if a block hash is present in the state to avoid redundant work and unnecessary errors. They currently call the state service with Depth requests, but this only checks if a block hash has been committed to the best chain, and returns None when the block is in a side chain or queued for validation.

This PR adds a Contains request to the state for checking if a block hash is present in any chain and uses it from sync, inbound and the block verifier instead of Depth.

Closes #862.

Solution

  • Add a Contains request to the state service that responds with an Option<BlockLocation>
    • Checks if the block hash is in:
      • non-finalized best chain
      • non-finalized side chains
      • finalized best chain
  • Call state with Contains request from sync, inbound, and block verifier to check if the block hash is in any chain

Review

Anyone can review.

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 C-bug Category: This is a bug P-Medium ⚡ I-slow Problems with performance or responsiveness I-usability Zebra is hard to understand or use A-state Area: State / database changes C-audit Category: Issues arising from audit findings labels Mar 15, 2023
@arya2 arya2 requested review from a team as code owners March 15, 2023 20:43
@arya2 arya2 self-assigned this Mar 15, 2023
@arya2 arya2 requested review from oxarbitrage and removed request for a team March 15, 2023 20:43
@github-actions github-actions bot added C-enhancement Category: This is an improvement C-feature Category: New features labels Mar 15, 2023
@codecov
Copy link

codecov bot commented Mar 15, 2023

Codecov Report

Merging #6335 (2c15632) into main (fc32e68) will increase coverage by 0.12%.
The diff coverage is 71.11%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6335      +/-   ##
==========================================
+ Coverage   77.71%   77.83%   +0.12%     
==========================================
  Files         304      304              
  Lines       39583    39614      +31     
==========================================
+ Hits        30761    30835      +74     
+ Misses       8822     8779      -43     

Copy link
Member

@upbqdn upbqdn left a comment

Choose a reason for hiding this comment

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

Some sections mentioned in #862 are not in this PR or are outdated. I think we should update #862 before we merge this PR.

zebra-consensus/src/error.rs Outdated Show resolved Hide resolved
zebra-state/src/service/queued_blocks.rs Outdated Show resolved Hide resolved
zebra-state/src/service.rs Outdated Show resolved Hide resolved
@arya2 arya2 force-pushed the state-contains-request branch from 05ccefe to 26cc3da Compare March 21, 2023 18:02
@teor2345 teor2345 changed the title change(state): Add 'Contains' request for checking if a block is present in the state change(state): Add 'KnownBlock' request for checking if a block is present in the state Mar 21, 2023
@mpguerra mpguerra mentioned this pull request Mar 21, 2023
36 tasks
@arya2
Copy link
Contributor Author

arya2 commented Mar 22, 2023

did you want to catch up and talk it through?

Sure!

@mpguerra
Copy link
Contributor

did you want to catch up and talk it through?

Sure!

Can we have an update here once you both have a catch up? :)

@arya2 arya2 force-pushed the state-contains-request branch from 5c2b1ee to 2c15632 Compare March 23, 2023 19:40
@arya2 arya2 requested a review from teor2345 March 23, 2023 19:44
@arya2
Copy link
Contributor Author

arya2 commented Mar 23, 2023

@teor2345 it only checks the chains now, I'll open a follow-up PR for checking the queues.

@arya2 arya2 changed the title change(state): Stop re-downloading blocks that are in state queues or non-finalized side chains change(state): Stop re-downloading blocks that are in non-finalized side chains Mar 23, 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, this looks like a worthwhile change, and it's low risk.

@arya2
Copy link
Contributor Author

arya2 commented Mar 23, 2023

Can we have an update here once you both have a catch up? :)

We'll try merging this PR (which is low risk because it only checks for blocks that have been validated and committed), the follow-up PR that checks the queues is riskier and less important, so we'll try that too if it works well without any further changes but will close it otherwise.

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-audit Category: Issues arising from audit findings C-bug Category: This is a bug C-enhancement Category: This is an improvement C-security Category: Security issues I-heavy Problems with excessive memory, disk, or CPU usage I-slow Problems with performance or responsiveness I-usability Zebra is hard to understand or use
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make sync, inbound, and block verifier check if a block hash is in any chain or any queue
4 participants