Skip to content

Commit 1db6c31

Browse files
authored
Merge pull request #9798 from ellemouton/graphFixNotificationSubs
graph/db: synchronous topology client subscriptions/cancellations
2 parents 8044891 + 0155d5d commit 1db6c31

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

docs/release-notes/release-notes-0.19.0.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ when running LND with an aux component injected (custom channels).
128128
such that the probability is evaluated quicker and to be more accurate in
129129
outdated scenarios.
130130

131+
* [Fix a bug](https://github.com/lightningnetwork/lnd/pull/9798) that could
132+
result in a new topology client missing a channel-close notifications.
133+
131134
# New Features
132135

133136
* Add support for [archiving channel backup](https://github.com/lightningnetwork/lnd/pull/9232)

graph/db/graph.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,12 @@ func (c *ChannelGraph) PruneGraph(spentOutputs []*wire.OutPoint,
492492
closeSummaries := createCloseSummaries(
493493
blockHeight, edges...,
494494
)
495-
c.notifyTopologyChange(&TopologyChange{
496-
ClosedChannels: closeSummaries,
497-
})
495+
496+
select {
497+
case c.topologyUpdate <- closeSummaries:
498+
case <-c.quit:
499+
return nil, ErrChanGraphShuttingDown
500+
}
498501
}
499502

500503
return edges, nil

graph/db/notifications.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ type topologyClient struct {
149149

150150
// notifyTopologyChange notifies all registered clients of a new change in
151151
// graph topology in a non-blocking.
152+
//
153+
// NOTE: this should only ever be called from a call-stack originating from the
154+
// handleTopologySubscriptions handler.
152155
func (c *ChannelGraph) notifyTopologyChange(topologyDiff *TopologyChange) {
153156
// notifyClient is a helper closure that will send topology updates to
154157
// the given client.
@@ -194,7 +197,8 @@ func (c *ChannelGraph) notifyTopologyChange(topologyDiff *TopologyChange) {
194197
// handleTopologyUpdate is responsible for sending any topology changes
195198
// notifications to registered clients.
196199
//
197-
// NOTE: must be run inside goroutine.
200+
// NOTE: must be run inside goroutine and must only ever be called from within
201+
// handleTopologySubscriptions.
198202
func (c *ChannelGraph) handleTopologyUpdate(update any) {
199203
defer c.wg.Done()
200204

@@ -445,6 +449,10 @@ func (c *ChannelGraph) addToTopologyChange(update *TopologyChange,
445449
edgeUpdate)
446450
return nil
447451

452+
case []*ClosedChanSummary:
453+
update.ClosedChannels = append(update.ClosedChannels, m...)
454+
return nil
455+
448456
default:
449457
return fmt.Errorf("unable to add to topology change, "+
450458
"unknown message type %T", msg)

0 commit comments

Comments
 (0)