From 81b7798c039b6a656d8cc7dd886d6dbd31dc80b0 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Mon, 18 Nov 2019 10:00:16 +0100 Subject: [PATCH] routing: pop heap at the end of the loop This prepares for routing to self. --- routing/pathfind.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/routing/pathfind.go b/routing/pathfind.go index 65f84043..c52e1cb7 100644 --- a/routing/pathfind.go +++ b/routing/pathfind.go @@ -530,25 +530,14 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig, // TODO(roasbeef): also add path caching // * similar to route caching, but doesn't factor in the amount - // To start, our target node will the sole item within our distance - // heap. - heap.Push(&nodeHeap, distance[target]) - + // The partial path that we start out with is a path that consists of + // just the target node. + partialPath := distance[target] for { nodesVisited++ - // Fetch the node within the smallest distance from our source - // from the heap. - partialPath := heap.Pop(&nodeHeap).(*nodeWithDist) pivot := partialPath.node - // If we've reached our source (or we don't have any incoming - // edges), then we're done here and can exit the graph - // traversal early. - if pivot == source { - break - } - // Create unified policies for all incoming connections. u := newUnifiedPolicies(source, pivot, r.OutgoingChannelID) @@ -589,6 +578,17 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig, if nodeHeap.Len() == 0 { break } + + // Fetch the node within the smallest distance from our source + // from the heap. + partialPath = heap.Pop(&nodeHeap).(*nodeWithDist) + + // If we've reached our source (or we don't have any incoming + // edges), then we're done here and can exit the graph + // traversal early. + if partialPath.node == source { + break + } } // Use the distance map to unravel the forward path from source to