graph/db: thread context through MarkEdgeZombie
What changed, and why it matters
This change simply passes a request-scoped cancellation signal (a 'context') through the MarkEdgeZombie function and its database backends. It does not alter what the function does, who can call it, or how channel zombie state is decided. There is no security fix or vulnerability here—only a routine code-quality refactor to make the function consistent with the rest of the codebase.
No security action required. Treat as a normal refactor commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit threads a context.Context parameter through ChannelGraph.MarkEdgeZombie, the Store interface, and both concrete implementations (KVStore and SQLStore). The KVStore implementation ignores the context (named ‘_’), while the SQLStore replaces an internal context.TODO() with the supplied context. Call sites in graph/builder.go and tests are updated accordingly. No logic, authorization, or data-flow behavior changes.
Changed components
graph/builder.gograph/db/graph.gograph/db/interfaces.gograph/db/kv_store.gograph/db/sql_store.gograph/db/graph_test.goInspect captured patch +17 / −12
diff --git a/graph/builder.go b/graph/builder.go
index 25dfdf0..c72b607 100644
--- a/graph/builder.go
+++ b/graph/builder.go
@@ -913,7 +913,9 @@ func (b *Builder) MarkZombieEdge(chanID uint64) error {
// so we don't continue to request it. We use the "zero key" for both
// node pubkeys so this edge can't be resurrected.
var zeroKey [33]byte
- err := b.cfg.Graph.MarkEdgeZombie(chanID, zeroKey, zeroKey)
+ err := b.cfg.Graph.MarkEdgeZombie(
+ context.TODO(), chanID, zeroKey, zeroKey,
+ )
if err != nil {
return fmt.Errorf("unable to mark spent chan(id=%v) as a "+
"zombie: %w", chanID, err)
diff --git a/graph/db/graph.go b/graph/db/graph.go
index bd4cfdc..3cc08da 100644
--- a/graph/db/graph.go
+++ b/graph/db/graph.go
@@ -564,10 +564,10 @@ func (c *ChannelGraph) FilterKnownChanIDs(chansInfo []ChannelUpdateInfo,
// MarkEdgeZombie attempts to mark a channel identified by its channel ID as a
// zombie. This method is used on an ad-hoc basis, when channels need to be
// marked as zombies outside the normal pruning cycle.
-func (c *ChannelGraph) MarkEdgeZombie(chanID uint64,
+func (c *ChannelGraph) MarkEdgeZombie(ctx context.Context, chanID uint64,
pubKey1, pubKey2 [33]byte) error {
- err := c.db.MarkEdgeZombie(chanID, pubKey1, pubKey2)
+ err := c.db.MarkEdgeZombie(ctx, chanID, pubKey1, pubKey2)
if err != nil {
return err
}
diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go
index 042ed78..159f8b6 100644
--- a/graph/db/graph_test.go
+++ b/graph/db/graph_test.go
@@ -2929,6 +2929,7 @@ func TestChanUpdatesInHorizonBoundaryConditions(t *testing.T) {
// FilterKnownChanIDs is tested in TestFilterKnownChanIDs.
func TestFilterKnownChanIDsZombieRevival(t *testing.T) {
t.Parallel()
+ ctx := t.Context()
graph := MakeTestGraph(t)
@@ -2946,9 +2947,13 @@ func TestFilterKnownChanIDsZombieRevival(t *testing.T) {
}
// Mark channel 1 and 2 as zombies.
- err := graph.MarkEdgeZombie(scid1.ToUint64(), [33]byte{}, [33]byte{})
+ err := graph.MarkEdgeZombie(
+ ctx, scid1.ToUint64(), [33]byte{}, [33]byte{},
+ )
require.NoError(t, err)
- err = graph.MarkEdgeZombie(scid2.ToUint64(), [33]byte{}, [33]byte{})
+ err = graph.MarkEdgeZombie(
+ ctx, scid2.ToUint64(), [33]byte{}, [33]byte{},
+ )
require.NoError(t, err)
require.True(t, isZombie(scid1))
@@ -3299,7 +3304,7 @@ func TestStressTestChannelGraphAPI(t *testing.T) {
}
return graph.MarkEdgeZombie(
- channel.id.ToUint64(),
+ ctx, channel.id.ToUint64(),
node1.PubKeyBytes,
node2.PubKeyBytes,
)
@@ -4592,7 +4597,7 @@ func TestGraphZombieIndex(t *testing.T) {
// If we mark the edge as a zombie manually, then it should show up as
// being a zombie once again.
err = graph.MarkEdgeZombie(
- edge.ChannelID, node1.PubKeyBytes, node2.PubKeyBytes,
+ ctx, edge.ChannelID, node1.PubKeyBytes, node2.PubKeyBytes,
)
require.NoError(t, err, "unable to mark edge as zombie")
diff --git a/graph/db/interfaces.go b/graph/db/interfaces.go
index db2e511..9f3cebe 100644
--- a/graph/db/interfaces.go
+++ b/graph/db/interfaces.go
@@ -324,7 +324,7 @@ type Store interface { //nolint:interfacebloat
// MarkEdgeZombie attempts to mark a channel identified by its channel
// ID as a zombie. This method is used on an ad-hoc basis, when channels
// need to be marked as zombies outside the normal pruning cycle.
- MarkEdgeZombie(chanID uint64,
+ MarkEdgeZombie(ctx context.Context, chanID uint64,
pubKey1, pubKey2 [33]byte) error
// MarkEdgeLive clears an edge from our zombie index, deeming it as
diff --git a/graph/db/kv_store.go b/graph/db/kv_store.go
index 2a8334d..15140c9 100644
--- a/graph/db/kv_store.go
+++ b/graph/db/kv_store.go
@@ -4243,7 +4243,7 @@ func (c *KVStore) ChannelView() ([]EdgePoint, error) {
// MarkEdgeZombie attempts to mark a channel identified by its channel ID as a
// zombie. This method is used on an ad-hoc basis, when channels need to be
// marked as zombies outside the normal pruning cycle.
-func (c *KVStore) MarkEdgeZombie(chanID uint64,
+func (c *KVStore) MarkEdgeZombie(_ context.Context, chanID uint64,
pubKey1, pubKey2 [33]byte) error {
c.cacheMu.Lock()
diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go
index 1b2f286..9cab515 100644
--- a/graph/db/sql_store.go
+++ b/graph/db/sql_store.go
@@ -1783,11 +1783,9 @@ func (s *SQLStore) FilterChannelRange(ctx context.Context, startHeight,
// marked as zombies outside the normal pruning cycle.
//
// NOTE: part of the Store interface.
-func (s *SQLStore) MarkEdgeZombie(chanID uint64,
+func (s *SQLStore) MarkEdgeZombie(ctx context.Context, chanID uint64,
pubKey1, pubKey2 [33]byte) error {
- ctx := context.TODO()
-
s.cacheMu.Lock()
defer s.cacheMu.Unlock()
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.