routing: modify findRoute to accept starting node as a paramter
This commit slightly modified findRoute to accept the node which should be used as the starting point in our path finding algorithm. With this change, as we move to a k-shortest paths algorithm this modification will be needed as all of our path finding attempts won’t always originate from a the same starting point.
This commit is contained in:
3 files changed
+37
-20
No files matched your search
+6
-10
@@ -238,8 +238,8 @@ func edgeWeight(e *channeldb.ChannelEdgePolicy) float64 {
|
||||
//
|
||||
// TODO(roasbeef): make member, add caching
|
||||
// * add k-path
|
||||
func findRoute(graph *channeldb.ChannelGraph, target *btcec.PublicKey,
|
||||
amt btcutil.Amount) (*Route, error) {
|
||||
func findRoute(graph *channeldb.ChannelGraph, sourceNode *channeldb.LightningNode,
|
||||
target *btcec.PublicKey, amt btcutil.Amount) (*Route, error) {
|
||||
|
||||
|
||||
// First we'll initilaze an empty heap which'll help us to quickly
|
||||
@@ -263,20 +263,16 @@ func findRoute(graph *channeldb.ChannelGraph, target *btcec.PublicKey,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Next we obtain the source node from the graph, and initialize it
|
||||
// with a distance of 0. This indicates our starting point in the graph
|
||||
// traversal.
|
||||
sourceNode, err := graph.SourceNode()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// To start, we add the source of our path finding attempt to the
|
||||
// distance map with with a distance of 0. This indicates our starting
|
||||
// point in the graph traversal.
|
||||
sourceVertex := newVertex(sourceNode.PubKey)
|
||||
distance[sourceVertex] = nodeWithDist{
|
||||
dist: 0,
|
||||
node: sourceNode,
|
||||
}
|
||||
|
||||
// To start, our source node will hte the sole item within our distance
|
||||
// To start, our source node will the sole item within our distance
|
||||
// heap.
|
||||
heap.Push(&nodeHeap, distance[sourceVertex])
|
||||
|
||||
|
||||
Reference in new issue
Block a user