From 13668ce45fdb8b74df01877fc675db15a89ff4b6 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Wed, 25 Feb 2026 12:28:50 +0200 Subject: [PATCH] graphdb: pass context to PruneGraphNodes --- graph/builder.go | 4 ++-- graph/db/graph.go | 4 ++-- graph/db/graph_test.go | 2 +- graph/db/interfaces.go | 2 +- graph/db/kv_store.go | 2 +- graph/db/sql_store.go | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/graph/builder.go b/graph/builder.go index 154a00eab..8e2aba1ab 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 bc3d8ee3d..8ad85aa0a 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 ff06f5046..cd9f7d711 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 edd93a578..95651fac5 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 2627e1db7..38920caeb 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 6503dc22f..acc1da93d 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 {