From e17fd58a1d4dba7c0afd60749fa13a238a45c450 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Fri, 11 Jul 2025 10:57:40 +0200 Subject: [PATCH] graph/db: pass reset to ForEachNodeCacheable --- graph/db/graph.go | 2 +- graph/db/graph_test.go | 4 ++++ graph/db/interfaces.go | 2 +- graph/db/kv_store.go | 5 ++--- graph/db/sql_store.go | 5 ++--- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/graph/db/graph.go b/graph/db/graph.go index 2ae944e9e..ba6ad6ae0 100644 --- a/graph/db/graph.go +++ b/graph/db/graph.go @@ -170,7 +170,7 @@ func (c *ChannelGraph) populateCache(ctx context.Context) error { c.graphCache.AddNodeFeatures(node, features) return nil - }) + }, func() {}) if err != nil { return err } diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go index 3a7f9b9de..d2f1577b2 100644 --- a/graph/db/graph_test.go +++ b/graph/db/graph_test.go @@ -1469,6 +1469,8 @@ func TestGraphTraversalCacheable(t *testing.T) { nodes = append(nodes, node) return nil + }, func() { + nodes = nil }) require.NoError(t, err) require.Len(t, nodeMap, 0) @@ -4227,6 +4229,8 @@ func BenchmarkForEachChannel(b *testing.B) { nodes = append(nodes, node) return nil + }, func() { + nodes = nil }) require.NoError(b, err) diff --git a/graph/db/interfaces.go b/graph/db/interfaces.go index 616aabc9f..e02081da1 100644 --- a/graph/db/interfaces.go +++ b/graph/db/interfaces.go @@ -110,7 +110,7 @@ type V1Store interface { //nolint:interfacebloat // encountered. If the callback returns an error, then the transaction // is aborted and the iteration stops early. ForEachNodeCacheable(ctx context.Context, cb func(route.Vertex, - *lnwire.FeatureVector) error) error + *lnwire.FeatureVector) error, reset func()) error // LookupAlias attempts to return the alias as advertised by the target // node. diff --git a/graph/db/kv_store.go b/graph/db/kv_store.go index eff37ff21..906012bcc 100644 --- a/graph/db/kv_store.go +++ b/graph/db/kv_store.go @@ -857,9 +857,8 @@ func forEachNode(db kvdb.Backend, // callback returns an error, then the transaction is aborted and the iteration // stops early. func (c *KVStore) ForEachNodeCacheable(_ context.Context, - cb func(route.Vertex, *lnwire.FeatureVector) error) error { - - reset := func() {} + cb func(route.Vertex, *lnwire.FeatureVector) error, + reset func()) 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 aef2f2464..15a902c4e 100644 --- a/graph/db/sql_store.go +++ b/graph/db/sql_store.go @@ -924,9 +924,8 @@ func (s *SQLStore) ForEachNodeDirectedChannel(nodePub route.Vertex, // // NOTE: This is a part of the V1Store interface. func (s *SQLStore) ForEachNodeCacheable(ctx context.Context, - cb func(route.Vertex, *lnwire.FeatureVector) error) error { - - reset := func() {} + cb func(route.Vertex, *lnwire.FeatureVector) error, + reset func()) error { err := s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error { return forEachNodeCacheable(ctx, db, func(nodeID int64,