What changed, and why it matters
This change simply threads a request context through a database lookup function so callers can cancel or time out the operation. It does not fix a vulnerability or change behavior in a security-relevant way.
No security action required; review as normal code-quality change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit updates the ChannelID method signature across the graph database interface and both implementations (KVStore and SQLStore) to accept a context.Context. The SQLStore previously used context.TODO() internally; now it uses the caller-provided context. The KVStore ignores the context. rpcserver.go passes context.TODO() at the call site. This is a routine API hygiene/refactoring change with no security fix evident in the diff.
Changed components
graph/db/graph.gograph/db/interfaces.gograph/db/kv_store.gograph/db/sql_store.gorpcserver.goInspect captured patch +9 / −8
diff --git a/graph/db/graph.go b/graph/db/graph.go
index 1659ed9..0051e8d 100644
--- a/graph/db/graph.go
+++ b/graph/db/graph.go
@@ -986,8 +986,10 @@ func (c *VersionedGraph) HighestChanID(ctx context.Context) (uint64, error) {
}
// ChannelID attempts to lookup the 8-byte compact channel ID.
-func (c *VersionedGraph) ChannelID(chanPoint *wire.OutPoint) (uint64, error) {
- return c.db.ChannelID(c.v, chanPoint)
+func (c *VersionedGraph) ChannelID(ctx context.Context,
+ chanPoint *wire.OutPoint) (uint64, error) {
+
+ return c.db.ChannelID(ctx, c.v, chanPoint)
}
// IsPublicNode determines whether the node is seen as public in the graph.
diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go
index c223c10..d162611 100644
--- a/graph/db/graph_test.go
+++ b/graph/db/graph_test.go
@@ -1191,7 +1191,7 @@ func testEdgeInfoUpdates(t *testing.T, v lnwire.GossipVersion) {
// We should also be able to retrieve the channelID only knowing the
// channel point of the channel.
- dbChanID, err := graph.ChannelID(&outpoint)
+ dbChanID, err := graph.ChannelID(ctx, &outpoint)
require.NoError(t, err, "unable to retrieve channel ID")
require.Equal(t, chanID, dbChanID)
diff --git a/graph/db/interfaces.go b/graph/db/interfaces.go
index a1dda31..4d52fbf 100644
--- a/graph/db/interfaces.go
+++ b/graph/db/interfaces.go
@@ -242,7 +242,7 @@ type Store interface { //nolint:interfacebloat
// ChannelID attempt to lookup the 8-byte compact channel ID which maps
// to the passed channel point (outpoint). If the passed channel doesn't
// exist within the database, then ErrEdgeNotFound is returned.
- ChannelID(v lnwire.GossipVersion,
+ ChannelID(ctx context.Context, v lnwire.GossipVersion,
chanPoint *wire.OutPoint) (uint64, error)
// HighestChanID returns the "highest" known channel ID in the channel
diff --git a/graph/db/kv_store.go b/graph/db/kv_store.go
index 4cfcedb..72d63f5 100644
--- a/graph/db/kv_store.go
+++ b/graph/db/kv_store.go
@@ -2006,7 +2006,7 @@ func (c *KVStore) DeleteChannelEdges(_ context.Context,
// ChannelID attempt to lookup the 8-byte compact channel ID which maps to the
// passed channel point (outpoint). If the passed channel doesn't exist within
// the database, then ErrEdgeNotFound is returned.
-func (c *KVStore) ChannelID(v lnwire.GossipVersion,
+func (c *KVStore) ChannelID(_ context.Context, v lnwire.GossipVersion,
chanPoint *wire.OutPoint) (uint64, error) {
if v != lnwire.GossipVersion1 {
diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go
index 388b25b..06f099d 100644
--- a/graph/db/sql_store.go
+++ b/graph/db/sql_store.go
@@ -2510,11 +2510,10 @@ func (s *SQLStore) HasChannelEdge(ctx context.Context,
// the database, then ErrEdgeNotFound is returned.
//
// NOTE: part of the Store interface.
-func (s *SQLStore) ChannelID(v lnwire.GossipVersion,
+func (s *SQLStore) ChannelID(ctx context.Context, v lnwire.GossipVersion,
chanPoint *wire.OutPoint) (uint64, error) {
var (
- ctx = context.TODO()
channelID uint64
)
err := s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
diff --git a/rpcserver.go b/rpcserver.go
index bf01fc8..531443f 100644
--- a/rpcserver.go
+++ b/rpcserver.go
@@ -3204,7 +3204,7 @@ func abandonChanFromGraph(chanGraph *graphdb.VersionedGraph,
// First, we'll obtain the channel ID. If we can't locate this, then
// it's the case that the channel may have already been removed from
// the graph, so we'll return a nil error.
- chanID, err := chanGraph.ChannelID(chanPoint)
+ chanID, err := chanGraph.ChannelID(context.TODO(), chanPoint)
switch {
case errors.Is(err, graphdb.ErrEdgeNotFound):
return nil
Why this scored 19/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.