routing: fix path finding, bug use the proper policy during path finding

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.
This commit is contained in:
Olaoluwa Osuntokun 2017-08-21 23:47:02 -07:00
parent 6467fdd829
commit 5301da790c
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

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