← Back to Pull requests

discovery: start live update horizon in the past #11634

Merged
ziggie1984 merged 3 files (126 lines) on Nov 26, 2026 00:53 UTC
View on GitHub
ziggie1984 ziggie1984 commented on Nov 25, 2026 14:00 UTC
Author

Found while debugging the recurring backwards compatibility test failure in the nightly (run): no route from alice to dave for 10000 sat within 60s.

This PR doesn't stop that flake on its own. The fix is on the requesting side: only a node running it is protected. In the test, the node that lost the policy (alice) runs the base release for the whole run. Only bob and dave are upgraded. The plan:

1. Merge this PR.
2. Backport it to v0.21.x-branch. There won't be another 0.20.x release.
3. Once a 0.21.x patch release includes the fix, bump the test's base version (LND_LATEST_VERSION, currently v0.20.0-beta) to it. Then alice runs the fix, and the nightly exercises it under the same conditions that triggered the failure.

Until step 3 the nightly can still hit this race. We're keeping the test unchanged on purpose instead of hiding the trigger (e.g. with --nobootstrap).

Problem

When we switch a peer to an active sync, we send it a GossipTimestampRange starting at time.Now(). The peer filters relayed gossip by the timestamp the message was signed with (FilterGossipMsgs), not by when it accepted the message itself.

We learn the peer's graph from two sources, and they're supposed to add up to everything:

1. Query replies: a snapshot of what the peer has committed at the time it answers.
2. Live relay: what the peer accepts afterwards, filtered to signed timestamp ≥ our horizon.

An update that is signed before our horizon but still in flight at the peer when it answers (queued for validation, waiting on its channel announcement, or relayed to it late over several hops) isn't in either one. A range sync only compares channel IDs, so that half of the channel policy is never requested again.

From the bw-compat node logs (all nodes on v0.20.0, so this isn't a recent regression):

03:11:28      charlie signs his update for charlie<->dave
03:11:30.418  bob receives it, waits on the chan ann + serialized validation
03:11:31.68   alice redials bob (bootstrapper), new syncer
03:11:31.793  bob answers alice's query: chan ann + only dave's update
              alice sends horizon first_stamp=03:11:31
03:11:31.925  bob commits charlie's update -> ts 28 < 31 -> filtered for alice

Alice never gets charlie's direction and can't route to dave.

The Nov 23 nightly failed the same way, with a different channel:

03:15:41      update for chan 124244814004224 signed (both directions)
03:15:42.108  bob receives both directions
03:15:43.235  alice redials bob (bootstrapper), new syncer
03:15:43.342  bob answers alice: only direction 0 (direction 1 still queued)
03:15:43.343  alice horizon = 43
03:15:43.616  bob commits direction 1 -> ts 41 < 43 -> filtered for alice
03:15:51      alice: "Skipped adding edge 124244814004224 due to nil policy" -> no_route

Fix

Start the live update horizon updateHorizonSlack (5 minutes) in the past. That covers validation at the peer and a few relay hops at the default 90s trickle delay. The cost is the peer re-sending that window's updates from its DB on each active-sync (re)start and rotation, unless it runs with ignore-historical-gossip-filters. We drop those updates as stale. The replay shares the peer's per-peer gossip rate limit (default 50 KiB/s) with live updates, so it can delay live updates by a few seconds while it runs, but it doesn't drop them. This stays within BOLT 7: we only ask for a wider window.

Testing

TestGossipSyncerLiveHorizonCoversInFlightUpdates drives the horizon from a real active-sync transition into the peer-side relay filter, using an update signed 3s earlier. It fails with the slack set to 0 (in-flight channel update was not relayed) and passes with the fix. TestGossipSyncerSyncTransitions now asserts the shifted horizon.

Diff: 126 lines (+118 / -8) across 3 files Reviewer: saubyk Review duration: 653m
All Vouch review confidence checks passed
Residual risk 0.04 = Change Risk (0.35) × (1 − Review Confidence (0.87)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.35 · 126 lines diff across 3 files
0.35
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.90 · 5 substantive comment(s)
0.90
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
87%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.290
Real PR Conversation Timeline
12 items
saubyk saubyk commented on code on Nov 25, 2026 18:44 UTC
Code Review
discovery/syncer.go:1
@@ -2035,7 +2059,7 @@ func (g *GossipSyncer) handleSyncTransition(ctx context.Context,
 	// If an active sync has been requested, then we should resume receiving
 	// new graph updates from the remote peer.
 	case ActiveSync, PinnedSync:
-		firstTimestamp = time.Now()
+		firstTimestamp = liveUpdateHorizonStart(time.Now())

Since lnd peers now replay the last 10 minutes from their DB on every active-sync (re)start and rotation (3 active syncers, rotated every 20 min by default), do we have a rough sense of the extra traffic on mainnet? And can that replay delay fresh live updates under peer-msg-rate-bytes? Fine as a follow-up if it's negligible.

saubyk saubyk commented on code on Nov 25, 2026 18:44 UTC
Code Review
discovery/syncer.go:1
@@ -191,6 +191,22 @@ const (
 
 	// syncerBufferSize is the size of the syncer's buffers.
 	syncerBufferSize = 50
+
+	// updateHorizonSlack is how far into the past we start the update
+	// horizon we send to a peer when we want to receive live graph
+	// updates from it.
+	//
+	// The remote peer filters the gossip it relays to us by the timestamp
+	// the message was signed with, not by when the peer itself learned
+	// about it. A message signed before our horizon that is still in
+	// flight at the peer (queued for validation, waiting on a dependency,
+	// or relayed to it late over several hops) when it answers our sync
+	// queries would otherwise be neither part of that answer nor relayed
+	// to us afterwards. Since a range sync only compares channel IDs,
+	// such a lost channel update is never requested again. Starting the
+	// horizon in the past closes this gap, at the cost of the peer
+	// re-sending the updates of this window, which we drop as stale.
+	updateHorizonSlack = 10 * time.Minute

How was 10 minutes chosen? With the default 90s trickledelay per hop, an update relayed over a few hops can reach the peer several minutes after signing, so the slack needs to stay above that. Would a lower value (e.g. ~5m) still leave enough margin, to cut the replay traffic from the comment above? Not asking for a config flag, just checking the trade-off.

saubyk saubyk commented on code on Nov 25, 2026 18:44 UTC
Code Review
docs/release-notes/unreleased/11634.md:1
@@ -0,0 +1,9 @@
+# Bug Fixes

Is there an issue/PR tracking the test-side fix (bootstrapper redial) so the nightly bw-compat test goes green before a release with this? Also, do we want this backported to 0.20.x, since routing failures from a missing policy hit users on that line too?

saubyk saubyk commented on code on Nov 25, 2026 18:44 UTC
Code Review
docs/release-notes/unreleased/11634.md:1
@@ -0,0 +1,9 @@
+# Bug Fixes
+
+* lnd now [requests a ten-minute overlap for live gossip
+  updates](https://github.com/lightningnetwork/lnd/pull/11634) to reduce the
+  chance of missing recent channel updates during graph sync. Previously, an
+  update signed before live gossip began could arrive at a peer too late for
+  its sync reply and then be excluded by its live gossip filter. Missing a
+  channel update can leave lnd without the policy it needs to route in that
+  direction.

Worth adding that peers may now resend up to 10 minutes of gossip when sync starts or rotates, so operators who see a burst of duplicate updates in debug logs know why?

saubyk saubyk commented on Nov 25, 2026 18:48 UTC
Reviewer

Thanks for tracking this down. The log timeline makes the gap clear, and fixing it on the requesting side means users benefit as soon as they upgrade, whatever their peers run. No blockers from my side. My questions are about the cost/coverage trade-off of the 10-minute window, and release follow-through (the nightly test fix and a possible 0.20.x backport). Happy for any of them to be follow-ups.

ziggie1984 ziggie1984 commented on code on Nov 25, 2026 22:40 UTC
Code Review
discovery/syncer.go:1
@@ -2035,7 +2059,7 @@ func (g *GossipSyncer) handleSyncTransition(ctx context.Context,
 	// If an active sync has been requested, then we should resume receiving
 	// new graph updates from the remote peer.
 	case ActiveSync, PinnedSync:
-		firstTimestamp = time.Now()
+		firstTimestamp = liveUpdateHorizonStart(time.Now())

Good catch on the rate limit. The backlog replay (ApplyGossipFilter → sendToPeerSync) and the live relay (FilterGossipMsgs → sendToPeer) go through the same per-peer limiter in sendMsgRateLimited (default 50 KiB/s), so while a peer replays the window to us, live updates from that peer wait behind it. A ChannelUpdate is ~150 bytes, so that budget is roughly 340 updates/s, and a replay of a few thousand updates delays live gossip by seconds. Live updates are delayed, not dropped. Peers running with ignore-historical-gossip-filters don't replay at all.

I lowered the window to 5 minutes (27a47bab5), which halves the replay. I don't have mainnet numbers yet. Happy to measure the update rate per window on a mainnet node as a follow-up.

ziggie1984 ziggie1984 commented on code on Nov 25, 2026 22:40 UTC
Code Review
discovery/syncer.go:1
@@ -191,6 +191,22 @@ const (
 
 	// syncerBufferSize is the size of the syncer's buffers.
 	syncerBufferSize = 50
+
+	// updateHorizonSlack is how far into the past we start the update
+	// horizon we send to a peer when we want to receive live graph
+	// updates from it.
+	//
+	// The remote peer filters the gossip it relays to us by the timestamp
+	// the message was signed with, not by when the peer itself learned
+	// about it. A message signed before our horizon that is still in
+	// flight at the peer (queued for validation, waiting on a dependency,
+	// or relayed to it late over several hops) when it answers our sync
+	// queries would otherwise be neither part of that answer nor relayed
+	// to us afterwards. Since a range sync only compares channel IDs,
+	// such a lost channel update is never requested again. Starting the
+	// horizon in the past closes this gap, at the cost of the peer
+	// re-sending the updates of this window, which we drop as stale.
+	updateHorizonSlack = 10 * time.Minute

Agreed, 10 minutes was more than needed. The window only has to cover a message still in flight at the peer when our sync starts: validation there plus a few relay hops at the 90s trickle delay. On a rotation, the other active syncers keep delivering live updates, so the case that really matters is startup or reconnect. 5 minutes covers ~3 worst-case hops. Lowered in 27a47bab5, with the reasoning in the constant's comment.

ziggie1984 ziggie1984 commented on code on Nov 25, 2026 22:40 UTC
Code Review
docs/release-notes/unreleased/11634.md:1
@@ -0,0 +1,9 @@
+# Bug Fixes

The trigger in both nightly failures was a needless reconnect: initialPeerBootstrap reuses the ignore list from startup for all its retries, so a peer connected right after (via connectpeer in the test) gets dialed again, and the new outbound connection replaces the working one. The Nov 23 nightly failed the same way, see the timeline in the description. I'm keeping that out of this PR. With the horizon fix, such a reconnect no longer loses updates, so the redial is only a minor startup glitch, and this PR stays focused on the root cause. We're also not hiding it on the test side.

The nightly can't confirm the fix yet, though. Alice is the node that loses the policy, and she stays on the base release (v0.20.0-beta) for the whole test. Only bob and dave are upgraded. The plan is to backport this to v0.21.x-branch after merge, then bump the bw-compat base to the 0.21.x patch release that includes it, so alice runs the fix. There won't be another 0.20.x release, so no backport there. Until the bump, the nightly can still flake.

ziggie1984 ziggie1984 commented on code on Nov 25, 2026 22:40 UTC
Code Review
docs/release-notes/unreleased/11634.md:1
@@ -0,0 +1,9 @@
+# Bug Fixes
+
+* lnd now [requests a ten-minute overlap for live gossip
+  updates](https://github.com/lightningnetwork/lnd/pull/11634) to reduce the
+  chance of missing recent channel updates during graph sync. Previously, an
+  update signed before live gossip began could arrive at a peer too late for
+  its sync reply and then be excluded by its live gossip filter. Missing a
+  channel update can leave lnd without the policy it needs to route in that
+  direction.

Added in 63c8a2ca1 (now five minutes).

saubyk saubyk approved these changes on Nov 26, 2026 00:29 UTC
Approved Reviewer

Thanks for addressing all four. The 5-minute window and the release-note wording look good. The 0.21.x backport plus the bw-compat base bump covers the nightly follow-through. Let's keep an eye on replay traffic on mainnet once this ships.

github-actions[bot] github-actions[bot] commented on Nov 26, 2026 00:54 UTC
Bot

Created backport PR for v0.21.x-branch:

  • #11637 with remaining conflicts!
  • Please cherry-pick the changes locally and resolve any conflicts.

    git fetch origin backport-11634-to-v0.21.x-branch
    git worktree add --checkout .worktree/backport-11634-to-v0.21.x-branch backport-11634-to-v0.21.x-branch
    cd .worktree/backport-11634-to-v0.21.x-branch
    git reset --hard HEAD^
    git cherry-pick -x fa5931fcdcb2020fc2bbacca14525566a0941b43 fba5dd90cd2189648c0534854202f21fcb5e1094 ccc7d65937ae0776c3c320694cfe3676c307d407 27a47bab54e4db0fb4a544bbf3cba4e890ad0acd 63c8a2ca184af3b64b4682e698b03ca30653243f
    git push --force-with-lease
    

    Reviewers
    Assignees
    ziggie1984 ziggie1984
    Labels
    risk: low confidence: 87.4% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 34.9% (LOW) · Higher = larger blast radius
    34.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 87.4% · Lower = rushed or shallow review
    87.4%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 4.4% · Safe to merge
    4.4%