graph/db: thread context through MarkEdgeLive
What changed, and why it matters
This commit is a routine internal refactoring change. It adds a standard request context parameter to a function called MarkEdgeLive so that database operations can be cancelled or timed out cleanly. There is no security fix or vulnerability here.
No security action required. Treat as normal maintenance/refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change threads context.Context through the MarkEdgeLive method across the ChannelGraph, Store interface, KVStore, SQLStore, and Builder. The SQL implementation replaces a hardcoded context.TODO() with the passed-in context, while the KV implementation currently ignores it. This is a code-quality/context-propagation refactor with no behavioral security impact visible in the diff.
Changed components
graph/db/graph.gograph/db/interfaces.gograph/db/kv_store.gograph/db/sql_store.gograph/builder.gograph/db/graph_test.goInspect captured patch +12 / −10
diff --git a/graph/builder.go b/graph/builder.go
index c72b607..f16441c 100644
--- a/graph/builder.go
+++ b/graph/builder.go
@@ -1417,5 +1417,7 @@ func (b *Builder) IsStaleEdgePolicy(chanID lnwire.ShortChannelID,
//
// NOTE: This method is part of the ChannelGraphSource interface.
func (b *Builder) MarkEdgeLive(chanID lnwire.ShortChannelID) error {
- return b.cfg.Graph.MarkEdgeLive(chanID.ToUint64())
+ return b.cfg.Graph.MarkEdgeLive(
+ context.TODO(), chanID.ToUint64(),
+ )
}
diff --git a/graph/db/graph.go b/graph/db/graph.go
index 3cc08da..b4a811a 100644
--- a/graph/db/graph.go
+++ b/graph/db/graph.go
@@ -343,8 +343,8 @@ func (c *ChannelGraph) AddChannelEdge(ctx context.Context,
// MarkEdgeLive clears an edge from our zombie index, deeming it as live.
// If the cache is enabled, the edge will be added back to the graph cache if
// we still have a record of this channel in the DB.
-func (c *ChannelGraph) MarkEdgeLive(chanID uint64) error {
- err := c.db.MarkEdgeLive(chanID)
+func (c *ChannelGraph) MarkEdgeLive(ctx context.Context, chanID uint64) error {
+ err := c.db.MarkEdgeLive(ctx, chanID)
if err != nil {
return err
}
@@ -547,7 +547,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(
- info.ShortChannelID.ToUint64(),
+ context.TODO(), 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 159f8b6..7e7712b 100644
--- a/graph/db/graph_test.go
+++ b/graph/db/graph_test.go
@@ -4580,12 +4580,13 @@ func TestGraphZombieIndex(t *testing.T) {
// Similarly, if we mark the same edge as live, we should no longer see
// it within the index.
- require.NoError(t, graph.MarkEdgeLive(edge.ChannelID))
+ require.NoError(t, graph.MarkEdgeLive(ctx, edge.ChannelID))
// Attempting to mark the edge as live again now that it is no longer
// in the zombie index should fail.
require.ErrorIs(
- t, graph.MarkEdgeLive(edge.ChannelID), ErrZombieEdgeNotFound,
+ t, graph.MarkEdgeLive(ctx, edge.ChannelID),
+ ErrZombieEdgeNotFound,
)
isZombie, _, _, err = graph.IsZombieEdge(edge.ChannelID)
diff --git a/graph/db/interfaces.go b/graph/db/interfaces.go
index 9f3cebe..6a6d6b8 100644
--- a/graph/db/interfaces.go
+++ b/graph/db/interfaces.go
@@ -329,7 +329,7 @@ type Store interface { //nolint:interfacebloat
// MarkEdgeLive clears an edge from our zombie index, deeming it as
// live.
- MarkEdgeLive(chanID uint64) error
+ MarkEdgeLive(ctx context.Context, chanID uint64) error
// IsZombieEdge returns whether the edge is considered zombie. If it is
// a zombie, then the two node public keys corresponding to this edge
diff --git a/graph/db/kv_store.go b/graph/db/kv_store.go
index 15140c9..beda595 100644
--- a/graph/db/kv_store.go
+++ b/graph/db/kv_store.go
@@ -4289,7 +4289,7 @@ func markEdgeZombie(zombieIndex kvdb.RwBucket, chanID uint64, pubKey1,
}
// MarkEdgeLive clears an edge from our zombie index, deeming it as live.
-func (c *KVStore) MarkEdgeLive(chanID uint64) error {
+func (c *KVStore) MarkEdgeLive(_ context.Context, chanID uint64) error {
c.cacheMu.Lock()
defer c.cacheMu.Unlock()
diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go
index 9cab515..db900f9 100644
--- a/graph/db/sql_store.go
+++ b/graph/db/sql_store.go
@@ -1815,12 +1815,11 @@ func (s *SQLStore) MarkEdgeZombie(ctx context.Context, chanID uint64,
// MarkEdgeLive clears an edge from our zombie index, deeming it as live.
//
// NOTE: part of the Store interface.
-func (s *SQLStore) MarkEdgeLive(chanID uint64) error {
+func (s *SQLStore) MarkEdgeLive(ctx context.Context, chanID uint64) error {
s.cacheMu.Lock()
defer s.cacheMu.Unlock()
var (
- ctx = context.TODO()
chanIDB = channelIDToBytes(chanID)
)
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.