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: don't sync block filter hashes if finalized checkpoint is too less than the last proved header #169

Conversation

yangby-cryptape
Copy link
Collaborator

@yangby-cryptape yangby-cryptape commented Dec 28, 2023

Why < self.check_point_interval * 2?

fn if_require_next_check_point(&self, last_proved_number: BlockNumber) -> bool {
self.number_of_next_check_point() + self.check_point_interval * 2 <= last_proved_number
}

Because light client don't finalize the latest checkpoint, light client will keep a checkpoint as a safe distance, so it doesn't have to rollback such many blocks even there is a fork. (N.B. Light client won't handle a long fork.)

  • If the last number is $N$, denote check_point_interval as $I$, light client will use the $(| \frac{N-I+1}{I}| - 1)\mathrm{-th}$ checkpoint as finalized checkpoint if there are more than $\frac{1}{2}\mathrm{MAX\_OUTBOUND\_PEERS}$ peers have this checkpoint.
  • Before the finalized checkpoint (include), light client will only sync all checkpoints.
  • After the finalized checkpoint, light client will sync all block filter hashes.

So, as an approximated value, I use < self.check_point_interval * 2 here.

Ref: the 2nd issue in #168 (comment).

@codecov-commenter
Copy link

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (fc45e35) 71.41% compared to head (82a46db) 71.39%.

Files Patch % Lines
src/protocols/light_client/peers.rs 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #169      +/-   ##
===========================================
- Coverage    71.41%   71.39%   -0.02%     
===========================================
  Files           25       25              
  Lines         6478     6479       +1     
===========================================
  Hits          4626     4626              
- Misses        1852     1853       +1     
Flag Coverage Δ
unittests 71.39% <50.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@yangby-cryptape yangby-cryptape marked this pull request as ready for review December 28, 2023 13:56
@quake quake merged commit 86865db into nervosnetwork:develop Dec 29, 2023
6 checks passed
@yangby-cryptape yangby-cryptape deleted the bugfix/sync-too-many-block-filter-hashes branch December 29, 2023 08:18
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