What changed, and why it matters
This commit is a routine code cleanup: it adds a context.Context parameter to the PruneGraphNodes function so callers can pass cancellation/timeout information. The SQL implementation previously used a placeholder TODO context, and now receives a real context from callers. There is no security-relevant behavior change visible in the diff.
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 PruneGraphNodes call chain: Builder.Start and Builder.pruneZombieChans pass context.TODO(); ChannelGraph.PruneGraphNodes forwards it; the Store interface and both KVStore and SQLStore implementations accept the context. KVStore ignores it with _, while SQLStore replaces its internal context.TODO() with the supplied ctx. This is a refactoring/telemetry change with no observable security fix.
Changed components
graph/builder.gograph/db/graph.gograph/db/interfaces.gograph/db/kv_store.gograph/db/sql_store.goInspect captured patch +9 / −9
diff --git a/graph/builder.go b/graph/builder.go
index 154a00e..8e2aba1 100644
--- a/graph/builder.go
+++ b/graph/builder.go
@@ -268,7 +268,7 @@ func (b *Builder) Start() error {
// Finally, before we proceed, we'll prune any unconnected nodes
// from the graph in order to ensure we maintain a tight graph
// of "useful" nodes.
- err = b.cfg.Graph.PruneGraphNodes()
+ err = b.cfg.Graph.PruneGraphNodes(context.TODO())
if err != nil &&
!errors.Is(err, graphdb.ErrGraphNodesNotFound) {
@@ -638,7 +638,7 @@ func (b *Builder) pruneZombieChans() error {
// With the channels pruned, we'll also attempt to prune any nodes that
// were a part of them.
- err = b.cfg.Graph.PruneGraphNodes()
+ err = b.cfg.Graph.PruneGraphNodes(context.TODO())
if err != nil && !errors.Is(err, graphdb.ErrGraphNodesNotFound) {
return fmt.Errorf("unable to prune graph nodes: %w", err)
}
diff --git a/graph/db/graph.go b/graph/db/graph.go
index bc3d8ee..8ad85aa 100644
--- a/graph/db/graph.go
+++ b/graph/db/graph.go
@@ -494,8 +494,8 @@ func (c *ChannelGraph) PruneGraph(spentOutputs []*wire.OutPoint,
// any nodes from the channel graph that are currently unconnected. This ensure
// that we only maintain a graph of reachable nodes. In the event that a pruned
// node gains more channels, it will be re-added back to the graph.
-func (c *ChannelGraph) PruneGraphNodes() error {
- nodes, err := c.db.PruneGraphNodes()
+func (c *ChannelGraph) PruneGraphNodes(ctx context.Context) error {
+ nodes, err := c.db.PruneGraphNodes(ctx)
if err != nil {
return err
}
diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go
index ff06f50..cd9f7d7 100644
--- a/graph/db/graph_test.go
+++ b/graph/db/graph_test.go
@@ -4044,7 +4044,7 @@ func TestPruneGraphNodes(t *testing.T) {
require.NoError(t, graph.UpdateEdgePolicy(ctx, edge1))
// We'll now initiate a around of graph pruning.
- require.NoError(t, graph.PruneGraphNodes())
+ require.NoError(t, graph.PruneGraphNodes(ctx))
// At this point, there should be 3 nodes left in the graph still: the
// source node (which can't be pruned), and node 1+2. Nodes 1 and two
diff --git a/graph/db/interfaces.go b/graph/db/interfaces.go
index edd93a5..95651fa 100644
--- a/graph/db/interfaces.go
+++ b/graph/db/interfaces.go
@@ -390,7 +390,7 @@ type Store interface { //nolint:interfacebloat
// unconnected. This ensures that we only maintain a graph of reachable
// nodes. In the event that a pruned node gains more channels, it will
// be re-added back to the graph.
- PruneGraphNodes() ([]route.Vertex, error)
+ PruneGraphNodes(ctx context.Context) ([]route.Vertex, error)
// PruneGraph prunes newly closed channels from the channel graph in
// response to a new block being solved on the network. Any transactions
diff --git a/graph/db/kv_store.go b/graph/db/kv_store.go
index 2627e1d..38920ca 100644
--- a/graph/db/kv_store.go
+++ b/graph/db/kv_store.go
@@ -1620,7 +1620,7 @@ func (c *KVStore) PruneGraph(spentOutputs []*wire.OutPoint,
// any nodes from the channel graph that are currently unconnected. This ensure
// that we only maintain a graph of reachable nodes. In the event that a pruned
// node gains more channels, it will be re-added back to the graph.
-func (c *KVStore) PruneGraphNodes() ([]route.Vertex, error) {
+func (c *KVStore) PruneGraphNodes(_ context.Context) ([]route.Vertex, error) {
var prunedNodes []route.Vertex
err := kvdb.Update(c.db, func(tx kvdb.RwTx) error {
nodes := tx.ReadWriteBucket(nodeBucket)
diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go
index 6503dc2..acc1da9 100644
--- a/graph/db/sql_store.go
+++ b/graph/db/sql_store.go
@@ -2802,8 +2802,8 @@ func (s *SQLStore) forEachChanInSCIDList(ctx context.Context, db SQLQueries,
// source nodes.
//
// NOTE: part of the Store interface.
-func (s *SQLStore) PruneGraphNodes() ([]route.Vertex, error) {
- var ctx = context.TODO()
+func (s *SQLStore) PruneGraphNodes(ctx context.Context) (
+ []route.Vertex, error) {
var prunedNodes []route.Vertex
err := s.db.ExecTx(ctx, sqldb.WriteTxOpt(), func(db SQLQueries) error {
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.