multi: add abstraction for Router and SessionSource graph access

In this commit, we completely remove the Router's dependence on a Graph
source that requires a `kvdb.RTx`. In so doing, we are more prepared for
a future where the Graph source is backed by different DB structure such
as pure SQL.

The two areas affected here are: the ChannelRouter's graph access that
it uses for pathfinding. And the SessionSource's graph access that it
uses for payments.

The ChannelRouter gets given a Graph and the SessionSource is given a
GraphSessionFactory which it can use to create a new session. Behind the
scenes, this will acquire a kvdb.RTx that will be used for calls to the
Graph's `ForEachNodeChannel` method.
This commit is contained in:
Elle Mouton committed 2024-07-15 15:13:57 +02:00
1 parent 90d6b863a8
commit 8c0df98439
11 files changed
+288 -128

No files matched your search

+6 -4
View File
@@ -3201,14 +3201,16 @@ func dbFindPath(graph *channeldb.ChannelGraph,
return nil, err
}
routingGraph, err := NewCachedGraph(graph)
graphSessFactory := newMockGraphSessionFactoryFromChanDB(graph)
graphSess, closeGraphSess, err := graphSessFactory.NewGraphSession()
if err != nil {
return nil, err
}
defer func() {
if err := routingGraph.Close(); err != nil {
log.Errorf("Error closing db tx: %v", err)
if err := closeGraphSess(); err != nil {
log.Errorf("Error closing graph session: %v", err)
}
}()
@@ -3216,7 +3218,7 @@ func dbFindPath(graph *channeldb.ChannelGraph,
&graphParams{
additionalEdges: additionalEdges,
bandwidthHints: bandwidthHints,
graph: routingGraph,
graph: graphSess,
},
r, cfg, sourceNode.PubKeyBytes, source, target, amt, timePref,
finalHtlcExpiry,