Consider non-canonical chains when finding common ancestor #9210
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.
PR Description
This PR enhances the findCommonAncestor method in ForkChoiceStrategy to consider non-canonical local chains when finding a common ancestor with a remote chain.
Previously, when comparing a remote chain to find a common ancestor, we only compared it with our canonical head. But if the chain we selected to sync is non-canonical for us, we might have a lot of blocks on that chain that we are not considering, thus we end up unnecessarily redownloading them.
The implementation now:
1.First tries to find a direct common ancestor between the two specific chains (using the original algorithm)
2.If no direct common ancestor is found or to find a better one, checks all local chain heads (including non-canonical ones)
3.Selects the common ancestor with the highest slot number to minimize the amount of data that needs to be redownloaded
A new test case was added to verify the correct behavior when dealing with non-canonical chains.
Fixed Issue(s)
fixes #9194
Documentation
doc-change-required
label to this PR if updates are required.Changelog