node: Send local block if iteration is lower #2417
Open
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.
If the node receives a block with higher iteration than the local block, it sends back the local block. The peer is expected to revert and accept it, unless the block sent to us has been finalized.
This commit also refactors on_block_event to unify the handling of remote_blk.height < tip.height and remote_blk.height == tip.height. These two cases are in fact equivalent and should be treated the same.
The unification of the two cases greatly improves readability and maintenance. A bug is also fixed, due to which the node erroneously switched to OutOfSync if reverting a block lower than the tip.