graph/db: thread context through FilterChannelRange
What changed, and why it matters
This commit is a routine code cleanup: it passes a request-scoped cancellation signal (a 'context') through a database query method called FilterChannelRange. Previously the SQL backend created a blank context internally, while the caller in the network discovery code ignored any context. Now the context is threaded from the caller down to the database. There is no security bug being fixed here; it is a maintainability and consistency improvement.
No security action required. Treat as normal refactoring. Consider following up with a separate change to propagate context from the RPC/gossip handler into discovery/ChanSeries.FilterChannelRange so the cancellation signal is meaningful rather than context.TODO().
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change threads context.Context through ChannelGraph.FilterChannelRange, the Store interface, and both KVStore and SQLStore implementations. The SQLStore previously used context.TODO() internally; it now uses the supplied ctx. The KVStore accepts the context but ignores it (named ‘_’). The discovery/chan_series.go caller passes context.TODO() because its own method signature does not yet take a context. No functional or security behavior changes are introduced by this patch.
Changed components
graph/db/graph.gograph/db/interfaces.gograph/db/kv_store.gograph/db/sql_store.godiscovery/chan_series.gograph/db/graph_test.goInspect captured patch +16 / −13
diff --git a/discovery/chan_series.go b/discovery/chan_series.go
index 75654a6..a1f0778 100644
--- a/discovery/chan_series.go
+++ b/discovery/chan_series.go
@@ -241,7 +241,7 @@ func (c *ChanSeries) FilterChannelRange(_ chainhash.Hash, startHeight,
error) {
return c.graph.FilterChannelRange(
- startHeight, endHeight, withTimestamps,
+ context.TODO(), startHeight, endHeight, withTimestamps,
)
}
diff --git a/graph/db/graph.go b/graph/db/graph.go
index a5e79a6..bd4cfdc 100644
--- a/graph/db/graph.go
+++ b/graph/db/graph.go
@@ -711,10 +711,13 @@ func (c *ChannelGraph) ChanUpdatesInHorizon(ctx context.Context,
}
// FilterChannelRange returns channel IDs within the passed block height range.
-func (c *ChannelGraph) FilterChannelRange(startHeight, endHeight uint32,
- withTimestamps bool) ([]BlockChannelRange, error) {
+func (c *ChannelGraph) FilterChannelRange(ctx context.Context,
+ startHeight, endHeight uint32, withTimestamps bool) (
+ []BlockChannelRange, error) {
- return c.db.FilterChannelRange(startHeight, endHeight, withTimestamps)
+ return c.db.FilterChannelRange(
+ ctx, startHeight, endHeight, withTimestamps,
+ )
}
// 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 9c017aa..042ed78 100644
--- a/graph/db/graph_test.go
+++ b/graph/db/graph_test.go
@@ -3477,7 +3477,7 @@ func TestFilterChannelRange(t *testing.T) {
// If we try to filter a channel range before we have any channels
// inserted, we should get an empty slice of results.
- resp, err := graph.FilterChannelRange(10, 100, false)
+ resp, err := graph.FilterChannelRange(ctx, 10, 100, false)
require.NoError(t, err)
require.Empty(t, resp)
@@ -3652,7 +3652,7 @@ func TestFilterChannelRange(t *testing.T) {
// First, do the query without requesting timestamps.
resp, err := graph.FilterChannelRange(
- test.startHeight, test.endHeight, false,
+ ctx, test.startHeight, test.endHeight, false,
)
require.NoError(t, err)
@@ -3666,7 +3666,7 @@ func TestFilterChannelRange(t *testing.T) {
// Now, query the timestamps as well.
resp, err = graph.FilterChannelRange(
- test.startHeight, test.endHeight, true,
+ ctx, test.startHeight, test.endHeight, true,
)
require.NoError(t, err)
diff --git a/graph/db/interfaces.go b/graph/db/interfaces.go
index f443953..db2e511 100644
--- a/graph/db/interfaces.go
+++ b/graph/db/interfaces.go
@@ -277,8 +277,9 @@ type Store interface { //nolint:interfacebloat
// offline. If withTimestamps is true then the timestamp info of the
// latest received channel update messages of the channel will be
// included in the response.
- FilterChannelRange(startHeight, endHeight uint32, withTimestamps bool) (
- []BlockChannelRange, error)
+ FilterChannelRange(ctx context.Context, startHeight,
+ endHeight uint32,
+ withTimestamps bool) ([]BlockChannelRange, error)
// FetchChanInfos returns the set of channel edges that correspond to
// the passed channel ID's. If an edge is the query is unknown to the
diff --git a/graph/db/kv_store.go b/graph/db/kv_store.go
index 94993c2..2a8334d 100644
--- a/graph/db/kv_store.go
+++ b/graph/db/kv_store.go
@@ -2817,7 +2817,7 @@ type BlockChannelRange struct {
// up after a period of time offline. If withTimestamps is true then the
// timestamp info of the latest received channel update messages of the channel
// will be included in the response.
-func (c *KVStore) FilterChannelRange(startHeight,
+func (c *KVStore) FilterChannelRange(_ context.Context, startHeight,
endHeight uint32, withTimestamps bool) ([]BlockChannelRange, error) {
startChanID := &lnwire.ShortChannelID{
diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go
index 745dff5..1b2f286 100644
--- a/graph/db/sql_store.go
+++ b/graph/db/sql_store.go
@@ -1664,11 +1664,10 @@ func (s *SQLStore) ForEachChannel(ctx context.Context,
// will be included in the response.
//
// NOTE: This is part of the Store interface.
-func (s *SQLStore) FilterChannelRange(startHeight, endHeight uint32,
- withTimestamps bool) ([]BlockChannelRange, error) {
+func (s *SQLStore) FilterChannelRange(ctx context.Context, startHeight,
+ endHeight uint32, withTimestamps bool) ([]BlockChannelRange, error) {
var (
- ctx = context.TODO()
startSCID = &lnwire.ShortChannelID{
BlockHeight: startHeight,
}
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.