graph/db: thread context through DeleteChannelEdges
What changed, and why it matters
This change simply passes a request-scoped cancellation signal (a 'context') through the DeleteChannelEdges function and its callers. It does not change what the function does, only how it receives timeout/cancellation information. There is no security vulnerability or fix here.
No security action required; treat as normal code maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit threads a context.Context parameter through DeleteChannelEdges across ChannelGraph, VersionedGraph, Store interface, KVStore, SQLStore, and callers in graph/builder.go, rpcserver.go, and server.go. The SQL implementation now uses the supplied ctx instead of context.TODO() inside ExecTx. The KV implementation accepts the context but does not currently use it. This is a pure API/refactoring change 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.gorpcserver.goserver.goInspect captured patch +34 / −28
diff --git a/graph/builder.go b/graph/builder.go
index f16441c..497b263 100644
--- a/graph/builder.go
+++ b/graph/builder.go
@@ -630,7 +630,7 @@ func (b *Builder) pruneZombieChans() error {
log.Tracef("Pruning zombie channel with ChannelID(%v)", chanID)
}
err := b.v1Graph.DeleteChannelEdges(
- b.cfg.StrictZombiePruning, true, toPrune...,
+ context.TODO(), b.cfg.StrictZombiePruning, true, toPrune...,
)
if err != nil {
return fmt.Errorf("unable to delete zombie channels: %w", err)
diff --git a/graph/db/graph.go b/graph/db/graph.go
index 8abca82..e199ce0 100644
--- a/graph/db/graph.go
+++ b/graph/db/graph.go
@@ -389,11 +389,11 @@ func (c *ChannelGraph) MarkEdgeLive(ctx context.Context, chanID uint64) error {
// that we require the node that failed to send the fresh update to be the one
// that resurrects the channel from its zombie state. The markZombie bool
// denotes whether to mark the channel as a zombie.
-func (c *ChannelGraph) DeleteChannelEdges(strictZombiePruning, markZombie bool,
- chanIDs ...uint64) error {
+func (c *ChannelGraph) DeleteChannelEdges(ctx context.Context,
+ strictZombiePruning, markZombie bool, chanIDs ...uint64) error {
infos, err := c.db.DeleteChannelEdges(
- lnwire.GossipVersion1, strictZombiePruning, markZombie,
+ ctx, lnwire.GossipVersion1, strictZombiePruning, markZombie,
chanIDs...,
)
if err != nil {
@@ -889,11 +889,11 @@ func (c *VersionedGraph) SourceNode(ctx context.Context) (*models.Node,
// that we require the node that failed to send the fresh update to be the one
// that resurrects the channel from its zombie state. The markZombie bool
// denotes whether to mark the channel as a zombie.
-func (c *VersionedGraph) DeleteChannelEdges(strictZombiePruning,
- markZombie bool, chanIDs ...uint64) error {
+func (c *VersionedGraph) DeleteChannelEdges(ctx context.Context,
+ strictZombiePruning, markZombie bool, chanIDs ...uint64) error {
infos, err := c.db.DeleteChannelEdges(
- c.v, strictZombiePruning, markZombie, chanIDs...,
+ ctx, c.v, strictZombiePruning, markZombie, chanIDs...,
)
if err != nil {
return err
diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go
index 2503f58..8572808 100644
--- a/graph/db/graph_test.go
+++ b/graph/db/graph_test.go
@@ -699,7 +699,9 @@ func testEdgeInsertionDeletion(t *testing.T, v lnwire.GossipVersion) {
// Next, attempt to delete the edge from the database, again this
// should proceed without any issues.
- require.NoError(t, graph.DeleteChannelEdges(false, true, chanID))
+ require.NoError(t, graph.DeleteChannelEdges(
+ ctx, false, true, chanID,
+ ))
assertNoEdge(t, graph.ChannelGraph, chanID)
// Ensure that any query attempts to lookup the delete channel edge are
@@ -720,7 +722,7 @@ func testEdgeInsertionDeletion(t *testing.T, v lnwire.GossipVersion) {
// Finally, attempt to delete a (now) non-existent edge within the
// database, this should result in an error.
- err = graph.DeleteChannelEdges(false, true, chanID)
+ err = graph.DeleteChannelEdges(ctx, false, true, chanID)
require.ErrorIs(t, err, ErrEdgeNotFound)
}
@@ -3064,7 +3066,9 @@ func TestFilterKnownChanIDs(t *testing.T) {
node1, node2,
)
require.NoError(t, graph.AddChannelEdge(ctx, channel))
- err := graph.DeleteChannelEdges(false, true, channel.ChannelID)
+ err := graph.DeleteChannelEdges(
+ ctx, false, true, channel.ChannelID,
+ )
require.NoError(t, err)
zombieIDs = append(
@@ -3403,7 +3407,8 @@ func TestStressTestChannelGraphAPI(t *testing.T) {
}
err := graph.DeleteChannelEdges(
- strictPruning, markZombie, chanIDs...,
+ ctx, strictPruning, markZombie,
+ chanIDs...,
)
if err != nil &&
!errors.Is(err, ErrEdgeNotFound) {
@@ -3761,7 +3766,9 @@ func testFetchChanInfos(t *testing.T, v lnwire.GossipVersion) {
v, 666, 0, 0, 0, node1, node2,
)
require.NoError(t, graph.AddChannelEdge(ctx, zombieChan))
- err := graph.DeleteChannelEdges(false, true, zombieChan.ChannelID)
+ err := graph.DeleteChannelEdges(
+ ctx, false, true, zombieChan.ChannelID,
+ )
require.NoError(t, err, "unable to delete and mark edge zombie")
edgeQuery = append(edgeQuery, zombieChanID.ToUint64())
@@ -4226,7 +4233,7 @@ func testNodeIsPublic(t *testing.T, v lnwire.GossipVersion) {
// has any advertised edges.
for _, graph := range graphs {
err := graph.DeleteChannelEdges(
- false, true, aliceBobEdge.ChannelID,
+ ctx, false, true, aliceBobEdge.ChannelID,
)
require.NoError(t, err, "unable to remove edge")
}
@@ -4243,7 +4250,7 @@ func testNodeIsPublic(t *testing.T, v lnwire.GossipVersion) {
// it without it being advertised.
for _, graph := range graphs {
err := graph.DeleteChannelEdges(
- false, true, bobCarolEdge.ChannelID,
+ ctx, false, true, bobCarolEdge.ChannelID,
)
require.NoError(t, err, "unable to remove edge")
@@ -4404,7 +4411,7 @@ func testDisabledChannelIDs(t *testing.T, v lnwire.GossipVersion) {
// Delete the channel edge and ensure it is removed from the disabled
// list.
require.NoError(t, graph.DeleteChannelEdges(
- false, true, edgeInfo.ChannelID,
+ ctx, false, true, edgeInfo.ChannelID,
))
disabledChanIds, err = graph.DisabledChannelIDs(ctx)
require.NoError(t, err, "unable to get disabled channel ids")
@@ -4571,7 +4578,7 @@ func TestGraphZombieIndex(t *testing.T) {
// If we delete the edge and mark it as a zombie, then we should expect
// to see it within the index.
- err = graph.DeleteChannelEdges(false, true, edge.ChannelID)
+ err = graph.DeleteChannelEdges(ctx, false, true, edge.ChannelID)
require.NoError(t, err, "unable to mark edge as zombie")
isZombie, pubKey1, pubKey2, err := graph.IsZombieEdge(
ctx, edge.ChannelID,
diff --git a/graph/db/interfaces.go b/graph/db/interfaces.go
index a42836f..a698183 100644
--- a/graph/db/interfaces.go
+++ b/graph/db/interfaces.go
@@ -230,8 +230,8 @@ type Store interface { //nolint:interfacebloat
// failed to send the fresh update to be the one that resurrects the
// channel from its zombie state. The markZombie bool denotes whether
// to mark the channel as a zombie.
- DeleteChannelEdges(v lnwire.GossipVersion, strictZombiePruning,
- markZombie bool, chanIDs ...uint64) (
+ DeleteChannelEdges(ctx context.Context, v lnwire.GossipVersion,
+ strictZombiePruning, markZombie bool, chanIDs ...uint64) (
[]*models.ChannelEdgeInfo, error)
// AddEdgeProof sets the proof of an existing edge in the graph
diff --git a/graph/db/kv_store.go b/graph/db/kv_store.go
index 98308ae..09b180b 100644
--- a/graph/db/kv_store.go
+++ b/graph/db/kv_store.go
@@ -1934,8 +1934,9 @@ func (c *KVStore) PruneTip() (*chainhash.Hash, uint32, error) {
// that we require the node that failed to send the fresh update to be the one
// that resurrects the channel from its zombie state. The markZombie bool
// denotes whether or not to mark the channel as a zombie.
-func (c *KVStore) DeleteChannelEdges(v lnwire.GossipVersion,
- strictZombiePruning, markZombie bool, chanIDs ...uint64) (
+func (c *KVStore) DeleteChannelEdges(_ context.Context,
+ v lnwire.GossipVersion, strictZombiePruning, markZombie bool,
+ chanIDs ...uint64) (
[]*models.ChannelEdgeInfo, error) {
if v != lnwire.GossipVersion1 {
diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go
index dc8492e..a534ecc 100644
--- a/graph/db/sql_store.go
+++ b/graph/db/sql_store.go
@@ -1946,8 +1946,9 @@ func (s *SQLStore) NumZombies(ctx context.Context) (uint64, error) {
// denotes whether to mark the channel as a zombie.
//
// NOTE: part of the Store interface.
-func (s *SQLStore) DeleteChannelEdges(v lnwire.GossipVersion,
- strictZombiePruning, markZombie bool, chanIDs ...uint64) (
+func (s *SQLStore) DeleteChannelEdges(ctx context.Context,
+ v lnwire.GossipVersion, strictZombiePruning, markZombie bool,
+ chanIDs ...uint64) (
[]*models.ChannelEdgeInfo, error) {
s.cacheMu.Lock()
@@ -1960,10 +1961,7 @@ func (s *SQLStore) DeleteChannelEdges(v lnwire.GossipVersion,
chanLookup[chanID] = struct{}{}
}
- var (
- ctx = context.TODO()
- edges []*models.ChannelEdgeInfo
- )
+ var edges []*models.ChannelEdgeInfo
err := s.db.ExecTx(ctx, sqldb.WriteTxOpt(), func(db SQLQueries) error {
// First, collect all channel rows.
var channelRows []sqlc.GetChannelsBySCIDWithPoliciesRow
diff --git a/rpcserver.go b/rpcserver.go
index f0eecd4..bfe537a 100644
--- a/rpcserver.go
+++ b/rpcserver.go
@@ -3212,7 +3212,7 @@ func abandonChanFromGraph(chanGraph *graphdb.VersionedGraph,
// If the channel ID is still in the graph, then that means the channel
// is still open, so we'll now move to purge it from the graph.
- return chanGraph.DeleteChannelEdges(false, true, chanID)
+ return chanGraph.DeleteChannelEdges(context.TODO(), false, true, chanID)
}
// abandonChan removes a channel from the database, graph and contract court.
diff --git a/server.go b/server.go
index 91b6624..248a69c 100644
--- a/server.go
+++ b/server.go
@@ -1426,7 +1426,7 @@ func newServer(ctx context.Context, cfg *Config, listenAddrs []net.Addr,
}
err = s.v1Graph.DeleteChannelEdges(
- false, false, scid.ToUint64(),
+ context.TODO(), false, false, scid.ToUint64(),
)
return ourPolicy, err
}
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.