routing: also include the source node in the nextHopMap index

In this commit we modify the newRoute function to also add the source
node to the nextHopMap index. With this addition the indexes will now
allow the router to react based on failures that occur during the
_first_ hop, meaning the channel directly attached to the source node.
This commit is contained in:
Olaoluwa Osuntokun 2017-10-10 19:45:09 -07:00
parent 70e114fa6f
commit f6ac31281b
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
3 changed files with 12 additions and 5 deletions

@ -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

@ -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)
}

@ -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
}