diff --git a/routing/pathfind.go b/routing/pathfind.go index 9e4a471b..48b18946 100644 --- a/routing/pathfind.go +++ b/routing/pathfind.go @@ -210,8 +210,8 @@ func (r *Route) ToHopPayloads() []sphinx.HopData { // // NOTE: The passed slice of ChannelHops MUST be sorted in forward order: from // the source to the target node of the path finding attempt. -func newRoute(amtToSend lnwire.MilliSatoshi, pathEdges []*ChannelHop, - currentHeight uint32) (*Route, error) { +func newRoute(amtToSend lnwire.MilliSatoshi, sourceVertex vertex, + pathEdges []*ChannelHop, currentHeight uint32) (*Route, error) { // First, we'll create a new empty route with enough hops to match the // amount of path edges. We set the TotalTimeLock to the current block @@ -228,6 +228,10 @@ func newRoute(amtToSend lnwire.MilliSatoshi, pathEdges []*ChannelHop, // TODO(roasbeef): need to do sanity check to ensure we don't make a // "dust" payment: over x% of money sending to fees + // We'll populate the next hop map for the _source_ node with the + // information for the first hop so the mapping is sound. + route.nextHopMap[sourceVertex] = pathEdges[0] + // The running amount is the total amount of satoshis required at this // point in the route. We start this value at the amount we want to // send to the destination. This value will then get successively diff --git a/routing/pathfind_test.go b/routing/pathfind_test.go index 5272ef3a..707ce54f 100644 --- a/routing/pathfind_test.go +++ b/routing/pathfind_test.go @@ -303,6 +303,7 @@ func TestBasicGraphPathFinding(t *testing.T) { if err != nil { t.Fatalf("unable to fetch source node: %v", err) } + sourceVertex := newVertex(sourceNode.PubKey) ignoredEdges := make(map[uint64]struct{}) ignoredVertexes := make(map[vertex]struct{}) @@ -320,7 +321,7 @@ func TestBasicGraphPathFinding(t *testing.T) { if err != nil { t.Fatalf("unable to find path: %v", err) } - route, err := newRoute(paymentAmt, path, startingHeight) + route, err := newRoute(paymentAmt, sourceVertex, path, startingHeight) if err != nil { t.Fatalf("unable to create path: %v", err) } @@ -416,7 +417,7 @@ func TestBasicGraphPathFinding(t *testing.T) { if err != nil { t.Fatalf("unable to find route: %v", err) } - route, err = newRoute(paymentAmt, path, startingHeight) + route, err = newRoute(paymentAmt, sourceVertex, path, startingHeight) if err != nil { t.Fatalf("unable to create path: %v", err) } diff --git a/routing/router.go b/routing/router.go index 55a199cc..291fd221 100644 --- a/routing/router.go +++ b/routing/router.go @@ -950,11 +950,13 @@ func (r *ChannelRouter) FindRoutes(target *btcec.PublicKey, // aren't able to support the total satoshis flow once fees have been // factored in. validRoutes := make([]*Route, 0, len(shortestPaths)) + sourceVertex := newVertex(r.selfNode.PubKey) for _, path := range shortestPaths { // Attempt to make the path into a route. We snip off the first // hop in the path as it contains a "self-hop" that is inserted // by our KSP algorithm. - route, err := newRoute(amt, path[1:], uint32(currentHeight)) + route, err := newRoute(amt, sourceVertex, path[1:], + uint32(currentHeight)) if err != nil { continue }