nervosnetwork / ckb-light-client

CKB light client reference implementation
MIT License
14 stars 16 forks source link

fix: ban peers when do reorg after client restart #166

Closed yangby-cryptape closed 8 months ago

yangby-cryptape commented 8 months ago

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 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

codecov-commenter commented 8 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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

Additional details and impacted files ```diff @@ 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](https://app.codecov.io/gh/nervosnetwork/ckb-light-client/pull/166/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nervosnetwork) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/nervosnetwork/ckb-light-client/pull/166/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nervosnetwork) | `71.41% <100.00%> (+0.26%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nervosnetwork#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.