What changed, and why it matters
This commit is a routine code cleanup: it threads a request-scoped cancellation context through a graph database helper called FilterKnownChanIDs. Previously the SQL backend created a blank context.TODO() inside the function, while the caller also used context.TODO(). Now the caller's context is passed down, which is better engineering practice but does not by itself fix a security vulnerability. There is no change to access control, cryptography, network behavior, or data validation.
No security action required. Treat as normal maintenance/refactor commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies the FilterKnownChanIDs method signature to accept a context.Context and propagates that context from discovery/chan_series.go through graph/db/graph.go into both KVStore and SQLStore implementations. The SQLStore previously used context.TODO() internally; it now uses the supplied ctx. KVStore ignores the context with _. Tests are updated to pass a context. This is a pure refactor for cancellation/timeout propagation and observability; no logic, query, or authorization semantics changed.
Changed components
discovery/chan_series.gograph/db/graph.gograph/db/interfaces.gograph/db/kv_store.gograph/db/sql_store.gograph/db/graph_test.goInspect captured patch +21 / −16
diff --git a/discovery/chan_series.go b/discovery/chan_series.go
index eaebc0b..7ed9bbd 100644
--- a/discovery/chan_series.go
+++ b/discovery/chan_series.go
@@ -215,7 +215,9 @@ func (c *ChanSeries) FilterKnownChanIDs(_ chainhash.Hash,
isZombieChan func(time.Time, time.Time) bool) (
[]lnwire.ShortChannelID, error) {
- newChanIDs, err := c.graph.FilterKnownChanIDs(superSet, isZombieChan)
+ newChanIDs, err := c.graph.FilterKnownChanIDs(
+ context.TODO(), superSet, isZombieChan,
+ )
if err != nil {
return nil, err
}
diff --git a/graph/db/graph.go b/graph/db/graph.go
index c5213ac..bc3d8ee 100644
--- a/graph/db/graph.go
+++ b/graph/db/graph.go
@@ -514,10 +514,11 @@ func (c *ChannelGraph) PruneGraphNodes() error {
// words, we perform a set difference of our set of chan ID's and the ones
// passed in. This method can be used by callers to determine the set of
// channels another peer knows of that we don't.
-func (c *ChannelGraph) FilterKnownChanIDs(chansInfo []ChannelUpdateInfo,
+func (c *ChannelGraph) FilterKnownChanIDs(ctx context.Context,
+ chansInfo []ChannelUpdateInfo,
isZombieChan func(time.Time, time.Time) bool) ([]uint64, error) {
- unknown, knownZombies, err := c.db.FilterKnownChanIDs(chansInfo)
+ unknown, knownZombies, err := c.db.FilterKnownChanIDs(ctx, chansInfo)
if err != nil {
return nil, err
}
@@ -547,7 +548,7 @@ func (c *ChannelGraph) FilterKnownChanIDs(chansInfo []ChannelUpdateInfo,
// alive, and we let it be added to the set of IDs to query our
// peer for.
err := c.db.MarkEdgeLive(
- context.TODO(), info.ShortChannelID.ToUint64(),
+ ctx, info.ShortChannelID.ToUint64(),
)
// Since there is a chance that the edge could have been marked
// as "live" between the FilterKnownChanIDs call and the
diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go
index 0f2e635..ff06f50 100644
--- a/graph/db/graph_test.go
+++ b/graph/db/graph_test.go
@@ -2976,7 +2976,7 @@ func TestFilterKnownChanIDsZombieRevival(t *testing.T) {
// Call FilterKnownChanIDs with an isStillZombie call-back that would
// result in the current zombies still be considered as zombies.
- _, err = graph.FilterKnownChanIDs([]ChannelUpdateInfo{
+ _, err = graph.FilterKnownChanIDs(ctx, []ChannelUpdateInfo{
{ShortChannelID: scid1},
{ShortChannelID: scid2},
{ShortChannelID: scid3},
@@ -2992,7 +2992,7 @@ func TestFilterKnownChanIDsZombieRevival(t *testing.T) {
// Now call it again but this time with a isStillZombie call-back that
// would result in channel with SCID 2 no longer being considered a
// zombie.
- _, err = graph.FilterKnownChanIDs([]ChannelUpdateInfo{
+ _, err = graph.FilterKnownChanIDs(ctx, []ChannelUpdateInfo{
{ShortChannelID: scid1},
{
ShortChannelID: scid2,
@@ -3038,7 +3038,9 @@ func TestFilterKnownChanIDs(t *testing.T) {
{ShortChannelID: scid2},
{ShortChannelID: scid3},
}
- filteredIDs, err := graph.FilterKnownChanIDs(preChanIDs, isZombieUpdate)
+ filteredIDs, err := graph.FilterKnownChanIDs(
+ ctx, preChanIDs, isZombieUpdate,
+ )
require.NoError(t, err, "unable to filter chan IDs")
require.EqualValues(t, []uint64{
scid1.ToUint64(),
@@ -3163,7 +3165,7 @@ func TestFilterKnownChanIDs(t *testing.T) {
for _, queryCase := range queryCases {
resp, err := graph.FilterKnownChanIDs(
- queryCase.queryIDs, isZombieUpdate,
+ ctx, queryCase.queryIDs, isZombieUpdate,
)
require.NoError(t, err)
@@ -3342,7 +3344,7 @@ func TestStressTestChannelGraphAPI(t *testing.T) {
}
_, err := graph.FilterKnownChanIDs(
- chanIDs,
+ ctx, chanIDs,
func(t time.Time, t2 time.Time) bool {
return rand.Intn(2) == 0
},
diff --git a/graph/db/interfaces.go b/graph/db/interfaces.go
index cdc6df1..edd93a5 100644
--- a/graph/db/interfaces.go
+++ b/graph/db/interfaces.go
@@ -267,8 +267,9 @@ type Store interface { //nolint:interfacebloat
// callers to determine the set of channels another peer knows of that
// we don't. The ChannelUpdateInfos for the known zombies is also
// returned.
- FilterKnownChanIDs(chansInfo []ChannelUpdateInfo) ([]uint64,
- []ChannelUpdateInfo, error)
+ FilterKnownChanIDs(ctx context.Context,
+ chansInfo []ChannelUpdateInfo) ([]uint64, []ChannelUpdateInfo,
+ error)
// FilterChannelRange returns the channel ID's of all known channels
// which were mined in a block height within the passed range. The
diff --git a/graph/db/kv_store.go b/graph/db/kv_store.go
index 2db9f39..2627e1d 100644
--- a/graph/db/kv_store.go
+++ b/graph/db/kv_store.go
@@ -2679,8 +2679,8 @@ func (c *KVStore) NodeUpdatesInHorizon(_ context.Context, startTime,
// passed in. This method can be used by callers to determine the set of
// channels another peer knows of that we don't. The ChannelUpdateInfos for the
// known zombies is also returned.
-func (c *KVStore) FilterKnownChanIDs(chansInfo []ChannelUpdateInfo) ([]uint64,
- []ChannelUpdateInfo, error) {
+func (c *KVStore) FilterKnownChanIDs(_ context.Context,
+ chansInfo []ChannelUpdateInfo) ([]uint64, []ChannelUpdateInfo, error) {
var (
newChanIDs []uint64
diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go
index 2b72c46..6503dc2 100644
--- a/graph/db/sql_store.go
+++ b/graph/db/sql_store.go
@@ -2679,11 +2679,10 @@ func (s *SQLStore) forEachChanWithPoliciesInSCIDList(ctx context.Context,
// known zombies is also returned.
//
// NOTE: part of the Store interface.
-func (s *SQLStore) FilterKnownChanIDs(chansInfo []ChannelUpdateInfo) ([]uint64,
- []ChannelUpdateInfo, error) {
+func (s *SQLStore) FilterKnownChanIDs(ctx context.Context,
+ chansInfo []ChannelUpdateInfo) ([]uint64, []ChannelUpdateInfo, error) {
var (
- ctx = context.TODO()
newChanIDs []uint64
knownZombies []ChannelUpdateInfo
infoLookup = make(
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.