From b3f3766fe6bdd7ff81257b24b1f041a62e814a37 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Fri, 11 Jul 2025 11:02:15 +0200 Subject: [PATCH] multi: pass reset to GraphSession --- graph/db/graph.go | 6 ++++-- graph/db/interfaces.go | 2 +- graph/db/kv_store.go | 4 ++-- graph/db/sql_store.go | 6 +++--- routing/graph.go | 3 ++- routing/mock_graph_test.go | 4 ++-- routing/pathfind_test.go | 2 ++ routing/payment_session.go | 6 +++++- routing/payment_session_test.go | 4 ++-- 9 files changed, 23 insertions(+), 14 deletions(-) diff --git a/graph/db/graph.go b/graph/db/graph.go index ba6ad6ae0..c0a4f52b6 100644 --- a/graph/db/graph.go +++ b/graph/db/graph.go @@ -233,12 +233,14 @@ func (c *ChannelGraph) FetchNodeFeatures(node route.Vertex) ( // instance which can be used to perform queries against the channel graph. If // the graph cache is not enabled, then the call-back will be provided with // access to the graph via a consistent read-only transaction. -func (c *ChannelGraph) GraphSession(cb func(graph NodeTraverser) error) error { +func (c *ChannelGraph) GraphSession(cb func(graph NodeTraverser) error, + reset func()) error { + if c.graphCache != nil { return cb(c) } - return c.V1Store.GraphSession(cb) + return c.V1Store.GraphSession(cb, reset) } // ForEachNodeCached iterates through all the stored vertices/nodes in the diff --git a/graph/db/interfaces.go b/graph/db/interfaces.go index e02081da1..f4cbb475d 100644 --- a/graph/db/interfaces.go +++ b/graph/db/interfaces.go @@ -149,7 +149,7 @@ type V1Store interface { //nolint:interfacebloat // GraphSession will provide the call-back with access to a // NodeTraverser instance which can be used to perform queries against // the channel graph. - GraphSession(cb func(graph NodeTraverser) error) error + GraphSession(cb func(graph NodeTraverser) error, reset func()) error // ForEachChannel iterates through all the channel edges stored within // the graph and invokes the passed callback for each edge. The callback diff --git a/graph/db/kv_store.go b/graph/db/kv_store.go index 906012bcc..020d7d3d3 100644 --- a/graph/db/kv_store.go +++ b/graph/db/kv_store.go @@ -3977,8 +3977,8 @@ func (c *KVStore) IsClosedScid(scid lnwire.ShortChannelID) (bool, error) { // GraphSession will provide the call-back with access to a NodeTraverser // instance which can be used to perform queries against the channel graph. -func (c *KVStore) GraphSession(cb func(graph NodeTraverser) error) error { - reset := func() {} +func (c *KVStore) GraphSession(cb func(graph NodeTraverser) error, + reset func()) error { return c.db.View(func(tx walletdb.ReadTx) error { return cb(&nodeTraverserSession{ diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go index 15a902c4e..58f29a75e 100644 --- a/graph/db/sql_store.go +++ b/graph/db/sql_store.go @@ -2757,10 +2757,10 @@ func (s *SQLStore) IsClosedScid(scid lnwire.ShortChannelID) (bool, error) { // instance which can be used to perform queries against the channel graph. // // NOTE: part of the V1Store interface. -func (s *SQLStore) GraphSession(cb func(graph NodeTraverser) error) error { - var ctx = context.TODO() +func (s *SQLStore) GraphSession(cb func(graph NodeTraverser) error, + reset func()) error { - reset := func() {} + var ctx = context.TODO() return s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error { return cb(newSQLNodeTraverser(db, s.cfg.ChainHash)) diff --git a/routing/graph.go b/routing/graph.go index 115f2daf1..d5c6b2d7d 100644 --- a/routing/graph.go +++ b/routing/graph.go @@ -29,7 +29,8 @@ type GraphSessionFactory interface { // GraphSession will provide the call-back with access to a // graphdb.NodeTraverser instance which can be used to perform queries // against the channel graph. - GraphSession(cb func(graph graphdb.NodeTraverser) error) error + GraphSession(cb func(graph graphdb.NodeTraverser) error, + reset func()) error } // FetchAmountPairCapacity determines the maximal public capacity between two diff --git a/routing/mock_graph_test.go b/routing/mock_graph_test.go index cb5d07f3a..b5c8b55bc 100644 --- a/routing/mock_graph_test.go +++ b/routing/mock_graph_test.go @@ -232,8 +232,8 @@ func (m *mockGraph) FetchNodeFeatures(nodePub route.Vertex) ( // the channel graph. // // NOTE: Part of the GraphSessionFactory interface. -func (m *mockGraph) GraphSession( - cb func(graph graphdb.NodeTraverser) error) error { +func (m *mockGraph) GraphSession(cb func(graph graphdb.NodeTraverser) error, + _ func()) error { return cb(m) } diff --git a/routing/pathfind_test.go b/routing/pathfind_test.go index fd5f06656..2f746ac9e 100644 --- a/routing/pathfind_test.go +++ b/routing/pathfind_test.go @@ -3303,6 +3303,8 @@ func dbFindPath(graph *graphdb.ChannelGraph, ) return err + }, func() { + route = nil }) if err != nil { return nil, err diff --git a/routing/payment_session.go b/routing/payment_session.go index 607c10443..cf20251ed 100644 --- a/routing/payment_session.go +++ b/routing/payment_session.go @@ -343,7 +343,11 @@ func (p *paymentSession) RequestRoute(maxAmt, feeLimit lnwire.MilliSatoshi, } for { - err := p.graphSessFactory.GraphSession(findPath) + err := p.graphSessFactory.GraphSession( + findPath, func() { + path = nil + }, + ) // If there is an error, and it is not a path finding error, we // return it immediately. if err != nil && !lnutils.ErrorAs[*pathFindingError](err) { diff --git a/routing/payment_session_test.go b/routing/payment_session_test.go index 51eeda425..ffe9d996c 100644 --- a/routing/payment_session_test.go +++ b/routing/payment_session_test.go @@ -259,8 +259,8 @@ func (g *sessionGraph) sourceNode() route.Vertex { return route.Vertex{} } -func (g *sessionGraph) GraphSession( - cb func(graph graphdb.NodeTraverser) error) error { +func (g *sessionGraph) GraphSession(cb func(graph graphdb.NodeTraverser) error, + _ func()) error { return cb(g) }