diff --git a/graph/db/graph.go b/graph/db/graph.go index 922adef53..86c14a6cf 100644 --- a/graph/db/graph.go +++ b/graph/db/graph.go @@ -75,7 +75,7 @@ func (c *ChannelGraph) Start() error { defer log.Debug("ChannelGraph started") if c.graphCache != nil { - if err := c.populateCache(); err != nil { + if err := c.populateCache(context.TODO()); err != nil { return fmt.Errorf("could not populate the graph "+ "cache: %w", err) } @@ -159,12 +159,12 @@ func (c *ChannelGraph) handleTopologySubscriptions() { // populateCache loads the entire channel graph into the in-memory graph cache. // // NOTE: This should only be called if the graphCache has been constructed. -func (c *ChannelGraph) populateCache() error { +func (c *ChannelGraph) populateCache(ctx context.Context) error { startTime := time.Now() log.Info("Populating in-memory channel graph, this might take a " + "while...") - err := c.V1Store.ForEachNodeCacheable(func(node route.Vertex, + err := c.V1Store.ForEachNodeCacheable(ctx, func(node route.Vertex, features *lnwire.FeatureVector) error { c.graphCache.AddNodeFeatures(node, features) diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go index b63651188..e3fd19456 100644 --- a/graph/db/graph_test.go +++ b/graph/db/graph_test.go @@ -1433,6 +1433,7 @@ func TestGraphTraversal(t *testing.T) { // working correctly. func TestGraphTraversalCacheable(t *testing.T) { t.Parallel() + ctx := context.Background() graph := MakeTestGraph(t) @@ -1458,7 +1459,7 @@ func TestGraphTraversalCacheable(t *testing.T) { // iterating over each node, once again if the map is empty that // indicates that all edges have properly been reached. var nodes []route.Vertex - err = graph.ForEachNodeCacheable(func(node route.Vertex, + err = graph.ForEachNodeCacheable(ctx, func(node route.Vertex, features *lnwire.FeatureVector) error { delete(nodeMap, node) @@ -4226,7 +4227,7 @@ func BenchmarkForEachChannel(b *testing.B) { ) var nodes []route.Vertex - err := graph.ForEachNodeCacheable(func(node route.Vertex, + err := graph.ForEachNodeCacheable(ctx, func(node route.Vertex, vector *lnwire.FeatureVector) error { nodes = append(nodes, node) diff --git a/graph/db/interfaces.go b/graph/db/interfaces.go index e46e578a9..8d2948478 100644 --- a/graph/db/interfaces.go +++ b/graph/db/interfaces.go @@ -107,7 +107,7 @@ type V1Store interface { //nolint:interfacebloat // in the graph, executing the passed callback with each node // encountered. If the callback returns an error, then the transaction // is aborted and the iteration stops early. - ForEachNodeCacheable(cb func(route.Vertex, + ForEachNodeCacheable(ctx context.Context, cb func(route.Vertex, *lnwire.FeatureVector) error) error // LookupAlias attempts to return the alias as advertised by the target diff --git a/graph/db/kv_store.go b/graph/db/kv_store.go index 02e6a4ab6..9d92aaaca 100644 --- a/graph/db/kv_store.go +++ b/graph/db/kv_store.go @@ -842,8 +842,8 @@ func forEachNode(db kvdb.Backend, // graph, executing the passed callback with each node encountered. If the // callback returns an error, then the transaction is aborted and the iteration // stops early. -func (c *KVStore) ForEachNodeCacheable(cb func(route.Vertex, - *lnwire.FeatureVector) error) error { +func (c *KVStore) ForEachNodeCacheable(_ context.Context, + cb func(route.Vertex, *lnwire.FeatureVector) error) error { traversal := func(tx kvdb.RTx) error { // First grab the nodes bucket which stores the mapping from diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go index c8f80c9f8..825013413 100644 --- a/graph/db/sql_store.go +++ b/graph/db/sql_store.go @@ -923,10 +923,8 @@ func (s *SQLStore) ForEachNodeDirectedChannel(nodePub route.Vertex, // stops early. // // NOTE: This is a part of the V1Store interface. -func (s *SQLStore) ForEachNodeCacheable(cb func(route.Vertex, - *lnwire.FeatureVector) error) error { - - ctx := context.TODO() +func (s *SQLStore) ForEachNodeCacheable(ctx context.Context, + cb func(route.Vertex, *lnwire.FeatureVector) error) error { err := s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error { return forEachNodeCacheable(ctx, db, func(nodeID int64,