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: ban peers when do reorg after client restart #166

Merged

Conversation

yangby-cryptape
Copy link
Collaborator

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

Description

This PR will fix #145.

If the first new "last state" after light client restarted is a fork state, the light client will do reorg to change its state to the new chain.

Let's denote

  • the number of old "last state" as $n_{old}$.
  • the number of new "last state" as $n_{new}$.
  • the parameter LAST_N_BLOCKS as $N$.

The blocks before $n_{old}$ (included) are called as "reorg blocks", "reorg blocks" must be continuous.
The last n continuous blocks before $n_{new}$ (included) are called as "last n blocks"; non-continuous blocks are "sampled blocks".

If the restart is too soon, $n_{new} - n_{old} < N$, the "last n blocks" will not enough, then light client will throw the error InvalidReorgHeaders and ban the peer who sent the proof.

How to fix?

If light client received all blocks between the fork block to the new "last state", then light client could use the reorg blocks to fill the "last n blocks".

Commits

  • test: reproduce the bug that peers will be banned when do reorg after client restart
  • fix: ban peers when do reorg after client restart

@codecov-commenter
Copy link

codecov-commenter commented Dec 20, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (e0a060a) 71.14% compared to head (78e099a) 71.41%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #166      +/-   ##
===========================================
+ Coverage    71.14%   71.41%   +0.26%     
===========================================
  Files           25       25              
  Lines         6457     6478      +21     
===========================================
+ Hits          4594     4626      +32     
+ Misses        1863     1852      -11     
Flag Coverage Δ
unittests 71.41% <100.00%> (+0.26%) ⬆️

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 20, 2023 05:56
@quake quake merged commit f788a1c into nervosnetwork:develop Dec 20, 2023
6 checks passed
@yangby-cryptape yangby-cryptape deleted the bugfix/reorg-after-restart branch December 20, 2023 08:48
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.

Panic received: "no previous prove state but has reorg blocks".
4 participants