fix: ban peers when do reorg after client restart #166
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
LAST_N_BLOCKS
asThe blocks before$n_{old}$ (included) are called as "reorg blocks", "reorg blocks" must be continuous.$n_{new}$ (included) are called as "last n blocks"; non-continuous blocks are "sampled blocks".
The last n continuous blocks before
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