From 818c302d46381251fbb916884dc833adec816485 Mon Sep 17 00:00:00 2001 From: Juan Pablo Civile Date: Sun, 25 Aug 2019 01:24:06 -0300 Subject: [PATCH] routing: use nodeWithDist instead of vertex to avoid map access The same nodeWithDist was fetched from the map for every channel it has. This struct is not mutated so it can be fetched before and reused. --- routing/pathfind.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/routing/pathfind.go b/routing/pathfind.go index 4fa4d15f..743adad1 100644 --- a/routing/pathfind.go +++ b/routing/pathfind.go @@ -393,7 +393,7 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig, // processEdge is a helper closure that will be used to make sure edges // satisfy our specific requirements. processEdge := func(fromVertex route.Vertex, bandwidth lnwire.MilliSatoshi, - edge *channeldb.ChannelEdgePolicy, toNode route.Vertex) { + edge *channeldb.ChannelEdgePolicy, toNodeDist *nodeWithDist) { edgesExpanded++ @@ -420,17 +420,16 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig, // Calculate amount that the candidate node would have to sent // out. - toNodeDist := distance[toNode] amountToSend := toNodeDist.amountToReceive // Request the success probability for this edge. edgeProbability := r.ProbabilitySource( - fromVertex, toNode, amountToSend, + fromVertex, toNodeDist.node, amountToSend, ) log.Trace(newLogClosure(func() string { return fmt.Sprintf("path finding probability: fromnode=%v,"+ - " tonode=%v, probability=%v", fromVertex, toNode, + " tonode=%v, probability=%v", fromVertex, toNodeDist.node, edgeProbability) })) @@ -626,7 +625,7 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig, // Check if this candidate node is better than what we // already have. - processEdge(chanSource, edgeBandwidth, inEdge, pivot) + processEdge(chanSource, edgeBandwidth, inEdge, partialPath) return nil } @@ -646,7 +645,7 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig, bandWidth := partialPath.amountToReceive for _, reverseEdge := range additionalEdgesWithSrc[pivot] { processEdge(reverseEdge.sourceNode, bandWidth, - reverseEdge.edge, pivot) + reverseEdge.edge, partialPath) } }