Fix warp-synced node getting stuck on a reverted fork#12286
Open
dimartiro wants to merge 1 commit into
Open
Conversation
c7b4983 to
28a20a4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Closes #10398.
Right after warp sync, a node can import a few blocks that turn out to belong to a fork which is later reverted. It then ends up with its best block on a dead fork a few blocks above the last finalized block, and every attempt to import the canonical successor fails with
block has an unknown parent— the node never recovers on its own (only wiping the database and re-warp-syncing helps).Root cause
After importing the (later reverted) fork, the affected peers'
common_numberis inflated up to our forked best, which sits above the finalized block. Both ancestor-search recovery paths are gated off for this case:on_validated_block_announceskips ancestor search during major sync (intentional, to avoid pulling peers out of the download pool — covered byno_ancestry_search_during_major_sync).block_requestsonly triggers whenbest_queued - common_number > MAX_BLOCKS_TO_LOOK_BACKWARDS(1024) andcommon_number < finalized— a short fork of a few blocks meets neither.On the
UnknownParentimport error,on_blocks_processedcallsrestart(), but during major sync the import queue is usually larger thanMAJOR_SYNC_BLOCKS, soadd_peer_innerre-adds peers assuming the common block is our (forked) best instead of starting an ancestor search. The node then loops: request the canonical successor →UnknownParent→ restart → assume common = fork tip → repeat, and ends up idle on the wrong best block.Fix
On an
UnknownParentimport error, afterrestart(), re-anchor every peer'scommon_numberdown to the finalized block — the highest block we are certain is shared with honest peers. This makes the next round of block requests re-download the canonical chain from the actual fork point, so the node recovers without operator intervention.