fix: make full nodes not resync infinitely on flush - #614
Open
pablocampogo wants to merge 2 commits into
Open
pablocampogo wants to merge 2 commits into
pablocampogo wants to merge 2 commits into
Conversation
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.
Fix full-node stall: trigger an active resync when the block inbox backs up
Summary
Full nodes (non-validators) could permanently stall on new block messages and only recover after a restart. The existing 80% inbox dead-letter flush did not fix it — in one production incident the flush fired 16 times over ~2 hours and the node still never resynced. This PR makes a backed-up block inbox trigger an active resync instead of just dropping the backlog.
Root cause
Inbound
BLOCKmessages funnel into a single shared channel consumed by eitherListenForBlock()(steady state) orSync()(catch-up). The only pre-existing way for a synced full node to re-enterSync()was thesyncDetector(NewHeightTracker) inListenForBlock(), which requires ≥ 1/3 of peers to each deliver a freshErrNewHeightblock.That recovery path structurally starves exactly when it's needed:
ErrNewHeightgossip thatsyncDetectorneeds to count toward its 1/3 threshold, so the trigger never fires.MessageCache) and applied strictly in-order, so any height dropped by the flush never arrives again on its own. OnlySync()re-requests specific heights — and there was no path from "I dropped blocks" → "request them back."Net effect: the node churns (flush → refill → flush) forever and never transitions to sync. A restart worked only because boot unconditionally runs
Sync(). This was full-node-only because the DLQ is disabled for validators.Additionally, the flush was actively harmful during a sync: it would drop the in-order block responses
Sync()depends on, causing timeout/re-request livelock.Changes
p2p/p2p.go: added asyncingflag (SetSyncing/IsSyncing) and a coalescedmustResyncchannel exposed viaMustResync()/signalResync().p2p/conn.go(dropInboxIfBackedUp): for theBLOCKtopic on a full node, do nothing while a sync is already running (soSync()keeps its in-order responses, matching validator behavior), otherwise signal a resync before draining the backlog.controller/block.go(ListenForBlock): nowselects on bothInbox(Block)andMustResync(); on a resync signal it launchesSync()and cleanly hands off consumption.controller/consensus.go:Sync()is idempotent viaisSyncing.CompareAndSwap(prevents duplicateInbox(Block)consumers now that there are multiple trigger paths) and togglesP2P.SetSyncing(true/false)inSync()/finishSyncing().Behavior after fix