What changed, and why it matters
This commit is a straightforward internal code cleanup: it threads a request context through the IsClosedScid function and all its callers. The change itself does not fix a crash, bug, or security vulnerability; it merely makes cancellation/timeouts possible for future SQL-backed calls and keeps the API consistent with other functions that already take a context.
No security action required. Treat as normal code hygiene; review and merge through standard process.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch updates the IsClosedScid method signature across interfaces and implementations (GraphCloser, Store, ChannelGraph, KVStore, SQLStore, ScidCloserMan, mockScidCloser) and all call sites to accept a context.Context parameter. In SQLStore it replaces a hard-coded context.TODO() with the supplied context. No logic changes, no added validation, no bounds checks, and no behavioral fixes are present. It is a pure plumbing/refactoring change.
Changed components
graph/db SQL and KV store implementationsdiscovery/gossiper channel-announcement handlingdiscovery/ban ScidCloserMan wrapperrelated unit tests and mocksInspect captured patch +22 / −16
diff --git a/discovery/ban.go b/discovery/ban.go
index 7100c2f..0425948 100644
--- a/discovery/ban.go
+++ b/discovery/ban.go
@@ -59,7 +59,7 @@ type GraphCloser interface {
PutClosedScid(context.Context, lnwire.ShortChannelID) error
// IsClosedScid checks if a short channel id is closed.
- IsClosedScid(lnwire.ShortChannelID) (bool, error)
+ IsClosedScid(context.Context, lnwire.ShortChannelID) (bool, error)
}
// NodeInfoInquirier handles queries relating to specific nodes and channels
@@ -97,10 +97,10 @@ func (s *ScidCloserMan) PutClosedScid(ctx context.Context,
// IsClosedScid checks whether scid is closed so that the gossiper can ignore
// it.
-func (s *ScidCloserMan) IsClosedScid(scid lnwire.ShortChannelID) (bool,
- error) {
+func (s *ScidCloserMan) IsClosedScid(ctx context.Context,
+ scid lnwire.ShortChannelID) (bool, error) {
- return s.graph.IsClosedScid(scid)
+ return s.graph.IsClosedScid(ctx, scid)
}
// IsChannelPeer checks whether we have a channel with the peer.
diff --git a/discovery/gossiper.go b/discovery/gossiper.go
index 11aa4ce..42fe9ac 100644
--- a/discovery/gossiper.go
+++ b/discovery/gossiper.go
@@ -2724,7 +2724,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(ctx context.Context,
// Check if the channel is already closed in which case we can ignore
// it.
- closed, err := d.cfg.ScidCloser.IsClosedScid(scid)
+ closed, err := d.cfg.ScidCloser.IsClosedScid(ctx, scid)
if err != nil {
log.Errorf("failed to check if scid %v is closed: %v", scid,
err)
diff --git a/discovery/gossiper_test.go b/discovery/gossiper_test.go
index 7440919..0ee33ec 100644
--- a/discovery/gossiper_test.go
+++ b/discovery/gossiper_test.go
@@ -4793,7 +4793,7 @@ func TestChanAnnBanningNonChanPeer(t *testing.T) {
// Check that the announcement's scid is marked as closed.
isClosed, err := tCtx.gossiper.cfg.ScidCloser.IsClosedScid(
- ca.ShortChannelID,
+ ctx, ca.ShortChannelID,
)
require.Nil(t, err)
require.True(t, isClosed)
diff --git a/discovery/mock_test.go b/discovery/mock_test.go
index 87464c7..050c570 100644
--- a/discovery/mock_test.go
+++ b/discovery/mock_test.go
@@ -187,8 +187,8 @@ func (m *mockScidCloser) PutClosedScid(_ context.Context,
return nil
}
-func (m *mockScidCloser) IsClosedScid(scid lnwire.ShortChannelID) (bool,
- error) {
+func (m *mockScidCloser) IsClosedScid(_ context.Context,
+ scid lnwire.ShortChannelID) (bool, error) {
m.Lock()
defer m.Unlock()
diff --git a/graph/db/graph.go b/graph/db/graph.go
index de10bac..eaf3526 100644
--- a/graph/db/graph.go
+++ b/graph/db/graph.go
@@ -779,8 +779,10 @@ func (c *ChannelGraph) PutClosedScid(ctx context.Context,
}
// IsClosedScid checks whether a channel identified by the scid is closed.
-func (c *ChannelGraph) IsClosedScid(scid lnwire.ShortChannelID) (bool, error) {
- return c.db.IsClosedScid(scid)
+func (c *ChannelGraph) IsClosedScid(ctx context.Context,
+ scid lnwire.ShortChannelID) (bool, error) {
+
+ return c.db.IsClosedScid(ctx, scid)
}
// SetSourceNode sets the source node within the graph database.
diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go
index 5dd84c4..ebe958b 100644
--- a/graph/db/graph_test.go
+++ b/graph/db/graph_test.go
@@ -5086,7 +5086,7 @@ func TestClosedScid(t *testing.T) {
scid := lnwire.ShortChannelID{}
// The scid should not exist in the closedScidBucket.
- exists, err := graph.IsClosedScid(scid)
+ exists, err := graph.IsClosedScid(t.Context(), scid)
require.Nil(t, err)
require.False(t, exists)
@@ -5095,7 +5095,7 @@ func TestClosedScid(t *testing.T) {
err = graph.PutClosedScid(t.Context(), scid)
require.Nil(t, err)
- exists, err = graph.IsClosedScid(scid)
+ exists, err = graph.IsClosedScid(t.Context(), scid)
require.Nil(t, err)
require.True(t, exists)
}
diff --git a/graph/db/interfaces.go b/graph/db/interfaces.go
index 15b9b5f..06c74c9 100644
--- a/graph/db/interfaces.go
+++ b/graph/db/interfaces.go
@@ -353,7 +353,8 @@ type Store interface { //nolint:interfacebloat
// IsClosedScid checks whether a channel identified by the passed in
// scid is closed. This helps avoid having to perform expensive
// validation checks.
- IsClosedScid(scid lnwire.ShortChannelID) (bool, error)
+ IsClosedScid(ctx context.Context,
+ scid lnwire.ShortChannelID) (bool, error)
// UpdateEdgePolicy updates the edge routing policy for a single
// directed edge within the database for the referenced channel. The
diff --git a/graph/db/kv_store.go b/graph/db/kv_store.go
index 96ea2f2..a353257 100644
--- a/graph/db/kv_store.go
+++ b/graph/db/kv_store.go
@@ -4456,7 +4456,9 @@ func (c *KVStore) PutClosedScid(_ context.Context,
// IsClosedScid checks whether a channel identified by the passed in scid is
// closed. This helps avoid having to perform expensive validation checks.
// TODO: Add an LRU cache to cut down on disc reads.
-func (c *KVStore) IsClosedScid(scid lnwire.ShortChannelID) (bool, error) {
+func (c *KVStore) IsClosedScid(_ context.Context,
+ scid lnwire.ShortChannelID) (bool, error) {
+
var isClosed bool
err := kvdb.View(c.db, func(tx kvdb.RTx) error {
closedScids := tx.ReadBucket(closedScidBucket)
diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go
index a146a83..b310897 100644
--- a/graph/db/sql_store.go
+++ b/graph/db/sql_store.go
@@ -3287,9 +3287,10 @@ func (s *SQLStore) PutClosedScid(ctx context.Context,
// closed. This helps avoid having to perform expensive validation checks.
//
// NOTE: part of the Store interface.
-func (s *SQLStore) IsClosedScid(scid lnwire.ShortChannelID) (bool, error) {
+func (s *SQLStore) IsClosedScid(ctx context.Context,
+ scid lnwire.ShortChannelID) (bool, error) {
+
var (
- ctx = context.TODO()
isClosed bool
chanIDB = channelIDToBytes(scid.ToUint64())
)
Why this scored 14/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.