What changed, and why it matters
This is a small internal code-quality change in LND's channel graph database. It replaces a hard-coded placeholder context with a single context variable that is passed through a few related functions. There is no security-relevant behavior change visible in the diff.
No security action required. Treat as routine refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors context handling in graph/db/graph.go and graph/db/notifications.go. A context.TODO() is now created once in ChannelGraph.Start() and threaded through populateCache, handleTopologySubscriptions, handleTopologyUpdate, and addToTopologyChange, replacing a second context.TODO() inside addToTopologyChange. A new ctx.Done() case is added in handleTopologySubscriptions’ select loop, but because the context is context.TODO() (never canceled), this case is effectively unreachable. No functional or security change is introduced.
Changed components
graph/db/graph.gograph/db/notifications.goInspect captured patch +14 / −9
diff --git a/graph/db/graph.go b/graph/db/graph.go
index a1eb2e3..d60ca24 100644
--- a/graph/db/graph.go
+++ b/graph/db/graph.go
@@ -73,15 +73,17 @@ func (c *ChannelGraph) Start() error {
log.Debugf("ChannelGraph starting")
defer log.Debug("ChannelGraph started")
+ ctx := context.TODO()
+
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 "+
"cache: %w", err)
}
}
c.wg.Add(1)
- go c.handleTopologySubscriptions()
+ go c.handleTopologySubscriptions(ctx)
return nil
}
@@ -106,7 +108,7 @@ func (c *ChannelGraph) Stop() error {
// synchronously.
//
// NOTE: this MUST be run in a goroutine.
-func (c *ChannelGraph) handleTopologySubscriptions() {
+func (c *ChannelGraph) handleTopologySubscriptions(ctx context.Context) {
defer c.wg.Done()
for {
@@ -118,7 +120,7 @@ func (c *ChannelGraph) handleTopologySubscriptions() {
// synchronously so that we can guarantee the order of
// notification delivery.
c.wg.Add(1)
- go c.handleTopologyUpdate(update)
+ go c.handleTopologyUpdate(ctx, update)
// TODO(roasbeef): remove all unconnected vertexes
// after N blocks pass with no corresponding
@@ -149,6 +151,9 @@ func (c *ChannelGraph) handleTopologySubscriptions() {
exit: make(chan struct{}),
})
+ case <-ctx.Done():
+ return
+
case <-c.quit:
return
}
diff --git a/graph/db/notifications.go b/graph/db/notifications.go
index 6676cbe..1c8a889 100644
--- a/graph/db/notifications.go
+++ b/graph/db/notifications.go
@@ -202,11 +202,11 @@ func (c *ChannelGraph) notifyTopologyChange(topologyDiff *TopologyChange) {
//
// NOTE: must be run inside goroutine and must only ever be called from within
// handleTopologySubscriptions.
-func (c *ChannelGraph) handleTopologyUpdate(update any) {
+func (c *ChannelGraph) handleTopologyUpdate(ctx context.Context, update any) {
defer c.wg.Done()
topChange := &TopologyChange{}
- err := c.addToTopologyChange(topChange, update)
+ err := c.addToTopologyChange(ctx, topChange, update)
if err != nil {
log.Errorf("unable to update topology change notification: %v",
err)
@@ -376,8 +376,8 @@ type ChannelEdgeUpdate struct {
// constitutes. This function will also fetch any required auxiliary
// information required to create the topology change update from the graph
// database.
-func (c *ChannelGraph) addToTopologyChange(update *TopologyChange,
- msg any) error {
+func (c *ChannelGraph) addToTopologyChange(ctx context.Context,
+ update *TopologyChange, msg any) error {
switch m := msg.(type) {
@@ -414,7 +414,7 @@ func (c *ChannelGraph) addToTopologyChange(update *TopologyChange,
// in order to get the information concerning which nodes are
// being connected.
edgeInfo, _, _, err := c.FetchChannelEdgesByID(
- context.TODO(), m.ChannelID,
+ ctx, m.ChannelID,
)
if err != nil {
return fmt.Errorf("unable fetch channel edge: %w", err)
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.