multi: remove the need for the graphsession package
In this commit, we add a `GraphSession` method to the `ChannelGraph`. This method provides a caller with access to a `NodeTraverser`. This is used by pathfinding to create a graph "session" overwhich to perform a set of queries for a pathfinding attempt. With this refactor, we hide details such as DB transaction creation and transaction commits from the caller. So with this, pathfinding does not need to remember to "close the graph session". With this commit, the `graphsession` package may be completely removed.
This commit is contained in:
11 files changed
+117
-297
No files matched your search
+15
-21
@@ -3221,30 +3221,25 @@ func dbFindPath(graph *graphdb.ChannelGraph,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
graphSessFactory := newMockGraphSessionFactoryFromChanDB(graph)
|
||||
var route []*unifiedEdge
|
||||
err = graph.GraphSession(func(graph graphdb.NodeTraverser) error {
|
||||
route, _, err = findPath(
|
||||
&graphParams{
|
||||
additionalEdges: additionalEdges,
|
||||
bandwidthHints: bandwidthHints,
|
||||
graph: graph,
|
||||
},
|
||||
r, cfg, sourceNode.PubKeyBytes, source, target, amt,
|
||||
timePref, finalHtlcExpiry,
|
||||
)
|
||||
|
||||
graphSess, closeGraphSess, err := graphSessFactory.NewGraphSession()
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err := closeGraphSess(); err != nil {
|
||||
log.Errorf("Error closing graph session: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
route, _, err := findPath(
|
||||
&graphParams{
|
||||
additionalEdges: additionalEdges,
|
||||
bandwidthHints: bandwidthHints,
|
||||
graph: graphSess,
|
||||
},
|
||||
r, cfg, sourceNode.PubKeyBytes, source, target, amt, timePref,
|
||||
finalHtlcExpiry,
|
||||
)
|
||||
|
||||
return route, err
|
||||
return route, nil
|
||||
}
|
||||
|
||||
// dbFindBlindedPaths calls findBlindedPaths after getting a db transaction from
|
||||
@@ -3258,8 +3253,7 @@ func dbFindBlindedPaths(graph *graphdb.ChannelGraph,
|
||||
}
|
||||
|
||||
return findBlindedPaths(
|
||||
newMockGraphSessionChanDB(graph), sourceNode.PubKeyBytes,
|
||||
restrictions,
|
||||
graph, sourceNode.PubKeyBytes, restrictions,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user