graphdb: thread topology update context

This commit is contained in:
Elle Mouton committed 2026-02-25 16:11:47 +02:00
1 parent 0bb0d66952
commit 262e9208b9
2 files changed
+14 -9

No files matched your search

+9 -4
View File
@@ -73,15 +73,17 @@ func (c *ChannelGraph) Start() error {
log.Debugf("ChannelGraph starting") log.Debugf("ChannelGraph starting")
defer log.Debug("ChannelGraph started") defer log.Debug("ChannelGraph started")
ctx := context.TODO()
if c.graphCache != nil { if c.graphCache != nil {
if err := c.populateCache(context.TODO()); err != nil { if err := c.populateCache(ctx); err != nil {
return fmt.Errorf("could not populate the graph "+ return fmt.Errorf("could not populate the graph "+
"cache: %w", err) "cache: %w", err)
} }
} }
c.wg.Add(1) c.wg.Add(1)
go c.handleTopologySubscriptions() go c.handleTopologySubscriptions(ctx)
return nil return nil
} }
@@ -106,7 +108,7 @@ func (c *ChannelGraph) Stop() error {
// synchronously. // synchronously.
// //
// NOTE: this MUST be run in a goroutine. // NOTE: this MUST be run in a goroutine.
func (c *ChannelGraph) handleTopologySubscriptions() { func (c *ChannelGraph) handleTopologySubscriptions(ctx context.Context) {
defer c.wg.Done() defer c.wg.Done()
for { for {
@@ -118,7 +120,7 @@ func (c *ChannelGraph) handleTopologySubscriptions() {
// synchronously so that we can guarantee the order of // synchronously so that we can guarantee the order of
// notification delivery. // notification delivery.
c.wg.Add(1) c.wg.Add(1)
go c.handleTopologyUpdate(update) go c.handleTopologyUpdate(ctx, update)
// TODO(roasbeef): remove all unconnected vertexes // TODO(roasbeef): remove all unconnected vertexes
// after N blocks pass with no corresponding // after N blocks pass with no corresponding
@@ -149,6 +151,9 @@ func (c *ChannelGraph) handleTopologySubscriptions() {
exit: make(chan struct{}), exit: make(chan struct{}),
}) })
case <-ctx.Done():
return
case <-c.quit: case <-c.quit:
return return
} }
+5 -5
View File
@@ -202,11 +202,11 @@ func (c *ChannelGraph) notifyTopologyChange(topologyDiff *TopologyChange) {
// //
// NOTE: must be run inside goroutine and must only ever be called from within // NOTE: must be run inside goroutine and must only ever be called from within
// handleTopologySubscriptions. // handleTopologySubscriptions.
func (c *ChannelGraph) handleTopologyUpdate(update any) { func (c *ChannelGraph) handleTopologyUpdate(ctx context.Context, update any) {
defer c.wg.Done() defer c.wg.Done()
topChange := &TopologyChange{} topChange := &TopologyChange{}
err := c.addToTopologyChange(topChange, update) err := c.addToTopologyChange(ctx, topChange, update)
if err != nil { if err != nil {
log.Errorf("unable to update topology change notification: %v", log.Errorf("unable to update topology change notification: %v",
err) err)
@@ -376,8 +376,8 @@ type ChannelEdgeUpdate struct {
// constitutes. This function will also fetch any required auxiliary // constitutes. This function will also fetch any required auxiliary
// information required to create the topology change update from the graph // information required to create the topology change update from the graph
// database. // database.
func (c *ChannelGraph) addToTopologyChange(update *TopologyChange, func (c *ChannelGraph) addToTopologyChange(ctx context.Context,
msg any) error { update *TopologyChange, msg any) error {
switch m := msg.(type) { switch m := msg.(type) {
@@ -414,7 +414,7 @@ func (c *ChannelGraph) addToTopologyChange(update *TopologyChange,
// in order to get the information concerning which nodes are // in order to get the information concerning which nodes are
// being connected. // being connected.
edgeInfo, _, _, err := c.FetchChannelEdgesByID( edgeInfo, _, _, err := c.FetchChannelEdgesByID(
context.TODO(), m.ChannelID, ctx, m.ChannelID,
) )
if err != nil { if err != nil {
return fmt.Errorf("unable fetch channel edge: %w", err) return fmt.Errorf("unable fetch channel edge: %w", err)