From 5301da790c3c55b39e8b74fac734c24a393528cf Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 21 Aug 2017 23:47:02 -0700 Subject: [PATCH] routing: fix path finding, bug use the proper policy during path finding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes an lingering bug within the path finding logic of the router. Previously we used the edge policy directly attached to the outgoing channel of the node we were traversing to calculate the fees and time lock information. This is incorrect, as we instead should be using the policy of the *connecting* node as we’ll need to pay for transit as they dictate. To remedy this, we now grab the incoming+outgoing edges and use those accordingly when building the initial path. --- routing/pathfind.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/routing/pathfind.go b/routing/pathfind.go index 77a0434b..bec821ec 100644 --- a/routing/pathfind.go +++ b/routing/pathfind.go @@ -394,9 +394,11 @@ func findPath(graph *channeldb.ChannelGraph, sourceNode *channeldb.LightningNode pivot := newVertex(bestNode.PubKey) err := bestNode.ForEachChannel(nil, func(tx *bolt.Tx, edgeInfo *channeldb.ChannelEdgeInfo, - edge *channeldb.ChannelEdgePolicy) error { + outEdge, inEdge *channeldb.ChannelEdgePolicy) error { - v := newVertex(edge.Node.PubKey) + v := newVertex(outEdge.Node.PubKey) + + // TODO(roasbeef): skip if disabled // If this vertex or edge has been black listed, then // we'll skip exploring this edge during this @@ -404,14 +406,14 @@ func findPath(graph *channeldb.ChannelGraph, sourceNode *channeldb.LightningNode if _, ok := ignoredNodes[v]; ok { return nil } - if _, ok := ignoredEdges[edge.ChannelID]; ok { + if _, ok := ignoredEdges[outEdge.ChannelID]; ok { return nil } // Compute the tentative distance to this new // channel/edge which is the distance to our current // pivot node plus the weight of this edge. - tempDist := distance[pivot].dist + edgeWeight(edge) + tempDist := distance[pivot].dist + edgeWeight(inEdge) // If this new tentative distance is better than the // current best known distance to this node, then we @@ -427,16 +429,28 @@ func findPath(graph *channeldb.ChannelGraph, sourceNode *channeldb.LightningNode distance[v] = nodeWithDist{ dist: tempDist, - node: edge.Node, + node: outEdge.Node, } prev[v] = edgeWithPrev{ + // We'll use the *incoming* edge here + // as we need to use the routing policy + // specified by the node this channel + // connects to. edge: &ChannelHop{ - ChannelEdgePolicy: edge, + ChannelEdgePolicy: inEdge, Capacity: edgeInfo.Capacity, }, prevNode: bestNode.PubKey, } + // In order for the path unwinding to work + // properly, we'll ensure that this edge + // properly points to the outgoing node. + // + // TODO(roasbeef): revisit, possibly switch db + // format? + prev[v].edge.Node = outEdge.Node + // Add this new node to our heap as we'd like // to further explore down this edge. heap.Push(&nodeHeap, distance[v])