graph/db: thread context through DisabledChannelIDs
What changed, and why it matters
This change simply passes a request-scoped cancellation signal (a 'context') through a database lookup function called DisabledChannelIDs. It does not fix a crash, bug, or security flaw by itself; it is a routine code-quality improvement that makes the function respect caller cancellation and enables future SQL query timeouts. The only concrete effect visible in the diff is that the SQL backend now reuses the caller's context instead of creating a blank one internally.
No immediate security action required. Treat as normal code hygiene. If auditing, verify that callers eventually pass a non-background context with sensible deadlines so the SQL path can actually time out long-running disabled-channel scans.
Security signals we found
Context propagation refactor only
No change to access control, authorization, or cryptographic logic
No input validation changes
No race condition or memory safety fix evident
SQL backend now honors caller context for query cancellation
Evidence from the diff
The commit threads context.Context through ChannelGraph.DisabledChannelIDs, VersionedGraph.DisabledChannelIDs, the Store interface, KVStore.DisabledChannelIDs, and SQLStore.DisabledChannelIDs. The KV implementation ignores the context (uses ‘_’), while the SQL implementation replaces an internal context.TODO() with the supplied context, allowing ExecTx to honor caller cancellation/deadlines. No behavioral change is forced on callers except supplying a context; builder.go uses context.TODO(). This is a refactor with minor operational benefit (timeout/cancellation propagation) rather than a vulnerability fix.
Changed components
graph/builder.gograph/db/graph.gograph/db/interfaces.gograph/db/kv_store.gograph/db/sql_store.gograph/db/graph_test.goInspect captured patch +16 / −13
diff --git a/graph/builder.go b/graph/builder.go
index 5100066..eec97b3 100644
--- a/graph/builder.go
+++ b/graph/builder.go
@@ -574,7 +574,7 @@ func (b *Builder) pruneZombieChans() error {
// the channel being closed and can prune it from our graph.
if b.cfg.AssumeChannelValid {
disabledChanIDs, err := b.cfg.Graph.DisabledChannelIDs(
- lnwire.GossipVersion1,
+ context.TODO(), lnwire.GossipVersion1,
)
if err != nil {
return fmt.Errorf("unable to get disabled channels "+
diff --git a/graph/db/graph.go b/graph/db/graph.go
index ba63941..acafbcc 100644
--- a/graph/db/graph.go
+++ b/graph/db/graph.go
@@ -662,10 +662,11 @@ func (c *ChannelGraph) ForEachChannel(ctx context.Context,
}
// DisabledChannelIDs returns the channel ids of disabled channels.
-func (c *ChannelGraph) DisabledChannelIDs(v lnwire.GossipVersion) (
+func (c *ChannelGraph) DisabledChannelIDs(ctx context.Context,
+ v lnwire.GossipVersion) (
[]uint64, error) {
- return c.db.DisabledChannelIDs(v)
+ return c.db.DisabledChannelIDs(ctx, v)
}
// HasV1ChannelEdge returns true if the database knows of a channel edge.
@@ -952,8 +953,10 @@ func (c *VersionedGraph) ForEachChannelCacheable(
}
// DisabledChannelIDs returns the channel ids of disabled channels.
-func (c *VersionedGraph) DisabledChannelIDs() ([]uint64, error) {
- return c.db.DisabledChannelIDs(c.v)
+func (c *VersionedGraph) DisabledChannelIDs(
+ ctx context.Context) ([]uint64, error) {
+
+ return c.db.DisabledChannelIDs(ctx, c.v)
}
// FetchChanInfos returns the set of channel edges for the passed channel IDs.
diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go
index 051f59a..737376b 100644
--- a/graph/db/graph_test.go
+++ b/graph/db/graph_test.go
@@ -4359,7 +4359,7 @@ func testDisabledChannelIDs(t *testing.T, v lnwire.GossipVersion) {
require.NoError(t, graph.AddChannelEdge(ctx, edgeInfo))
// Ensure no disabled channels exist in the bucket on start.
- disabledChanIds, err := graph.DisabledChannelIDs()
+ disabledChanIds, err := graph.DisabledChannelIDs(ctx)
require.NoError(t, err, "unable to get disabled channel ids")
require.Empty(t, disabledChanIds)
@@ -4372,7 +4372,7 @@ func testDisabledChannelIDs(t *testing.T, v lnwire.GossipVersion) {
edge1.DisableFlags |= lnwire.ChanUpdateDisableIncoming
}
require.NoError(t, graph.UpdateEdgePolicy(ctx, edge1))
- disabledChanIds, err = graph.DisabledChannelIDs()
+ disabledChanIds, err = graph.DisabledChannelIDs(ctx)
require.NoError(t, err, "unable to get disabled channel ids")
require.Empty(t, disabledChanIds)
@@ -4385,7 +4385,7 @@ func testDisabledChannelIDs(t *testing.T, v lnwire.GossipVersion) {
edge2.DisableFlags |= lnwire.ChanUpdateDisableIncoming
}
require.NoError(t, graph.UpdateEdgePolicy(ctx, edge2))
- disabledChanIds, err = graph.DisabledChannelIDs()
+ disabledChanIds, err = graph.DisabledChannelIDs(ctx)
require.NoError(t, err, "unable to get disabled channel ids")
require.Equal(t, []uint64{edgeInfo.ChannelID}, disabledChanIds)
@@ -4394,7 +4394,7 @@ func testDisabledChannelIDs(t *testing.T, v lnwire.GossipVersion) {
require.NoError(t, graph.DeleteChannelEdges(
false, true, edgeInfo.ChannelID,
))
- disabledChanIds, err = graph.DisabledChannelIDs()
+ disabledChanIds, err = graph.DisabledChannelIDs(ctx)
require.NoError(t, err, "unable to get disabled channel ids")
require.Empty(t, disabledChanIds)
}
diff --git a/graph/db/interfaces.go b/graph/db/interfaces.go
index 9daabb0..897b56a 100644
--- a/graph/db/interfaces.go
+++ b/graph/db/interfaces.go
@@ -191,7 +191,8 @@ type Store interface { //nolint:interfacebloat
// DisabledChannelIDs returns the channel ids of disabled channels.
// A channel is disabled when two of the associated ChanelEdgePolicies
// have their disabled bit on.
- DisabledChannelIDs(v lnwire.GossipVersion) ([]uint64, error)
+ DisabledChannelIDs(ctx context.Context,
+ v lnwire.GossipVersion) ([]uint64, error)
// AddChannelEdge adds a new (undirected, blank) edge to the graph
// database. An undirected edge from the two target nodes are created.
diff --git a/graph/db/kv_store.go b/graph/db/kv_store.go
index 67cebc2..ceb2b67 100644
--- a/graph/db/kv_store.go
+++ b/graph/db/kv_store.go
@@ -773,7 +773,7 @@ func (c *KVStore) ForEachNodeCached(ctx context.Context, withAddrs bool,
// A channel is disabled when two of the associated ChanelEdgePolicies
// have their disabled bit on.
func (c *KVStore) DisabledChannelIDs(
- v lnwire.GossipVersion) ([]uint64, error) {
+ _ context.Context, v lnwire.GossipVersion) ([]uint64, error) {
if v != lnwire.GossipVersion1 {
return nil, ErrVersionNotSupportedForKVDB
diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go
index cc058c8..77863d7 100644
--- a/graph/db/sql_store.go
+++ b/graph/db/sql_store.go
@@ -460,10 +460,9 @@ func (s *SQLStore) FetchNodeFeatures(ctx context.Context,
//
// NOTE: part of the Store interface.
func (s *SQLStore) DisabledChannelIDs(
- v lnwire.GossipVersion) ([]uint64, error) {
+ ctx context.Context, v lnwire.GossipVersion) ([]uint64, error) {
var (
- ctx = context.TODO()
chanIDs []uint64
)
err := s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
Why this scored 18/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.