From 20aba8060f0a4153e5dd035e7fc826a83c96f30c Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sun, 19 Mar 2017 14:11:25 -0700 Subject: [PATCH] routing: add sufficient link capacity to our relaxation condition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit modifies our modified version of Dijkstra's to include sufficient link capacity within the algorithm’s relaxation condition. With this change, we’ll now avoid exploring the graph in the direction of a link that has insufficient capacity, allowing us to terminate path finding more quickly. --- routing/pathfind.go | 4 +++- routing/pathfind_test.go | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/routing/pathfind.go b/routing/pathfind.go index e320d2f2b..8279fa74f 100644 --- a/routing/pathfind.go +++ b/routing/pathfind.go @@ -331,7 +331,9 @@ func findRoute(graph *channeldb.ChannelGraph, target *btcec.PublicKey, // TODO(roasbeef): add capacity to relaxation criteria? // * also add min payment? v := newVertex(edge.Node.PubKey) - if tempDist < distance[v].dist { + if tempDist < distance[v].dist && + edgeInfo.Capacity >= amt { + distance[v] = nodeWithDist{ dist: tempDist, node: edge.Node, diff --git a/routing/pathfind_test.go b/routing/pathfind_test.go index 8d949d91c..cccd6a58d 100644 --- a/routing/pathfind_test.go +++ b/routing/pathfind_test.go @@ -431,11 +431,15 @@ func TestPathInsufficientCapacity(t *testing.T) { const payAmt = btcutil.SatoshiPerBitcoin _, err = findRoute(graph, target, payAmt) - if err != ErrInsufficientCapacity { + if err != ErrNoPathFound { t.Fatalf("graph shouldn't be able to support payment: %v", err) } } func TestPathInsufficientCapacityWithFee(t *testing.T) { // TODO(roasbeef): encode live graph to json + + // TODO(roasbeef): need to add a case, or modify the fee ratio for one + // to ensure that has going forward, but when fees are applied doesn't + // work }