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.
This commit is contained in:
Juan Pablo Civile 2019-08-25 01:24:06 -03:00
parent df70095ad0
commit 818c302d46

@ -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 // processEdge is a helper closure that will be used to make sure edges
// satisfy our specific requirements. // satisfy our specific requirements.
processEdge := func(fromVertex route.Vertex, bandwidth lnwire.MilliSatoshi, processEdge := func(fromVertex route.Vertex, bandwidth lnwire.MilliSatoshi,
edge *channeldb.ChannelEdgePolicy, toNode route.Vertex) { edge *channeldb.ChannelEdgePolicy, toNodeDist *nodeWithDist) {
edgesExpanded++ edgesExpanded++
@ -420,17 +420,16 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
// Calculate amount that the candidate node would have to sent // Calculate amount that the candidate node would have to sent
// out. // out.
toNodeDist := distance[toNode]
amountToSend := toNodeDist.amountToReceive amountToSend := toNodeDist.amountToReceive
// Request the success probability for this edge. // Request the success probability for this edge.
edgeProbability := r.ProbabilitySource( edgeProbability := r.ProbabilitySource(
fromVertex, toNode, amountToSend, fromVertex, toNodeDist.node, amountToSend,
) )
log.Trace(newLogClosure(func() string { log.Trace(newLogClosure(func() string {
return fmt.Sprintf("path finding probability: fromnode=%v,"+ return fmt.Sprintf("path finding probability: fromnode=%v,"+
" tonode=%v, probability=%v", fromVertex, toNode, " tonode=%v, probability=%v", fromVertex, toNodeDist.node,
edgeProbability) edgeProbability)
})) }))
@ -626,7 +625,7 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
// Check if this candidate node is better than what we // Check if this candidate node is better than what we
// already have. // already have.
processEdge(chanSource, edgeBandwidth, inEdge, pivot) processEdge(chanSource, edgeBandwidth, inEdge, partialPath)
return nil return nil
} }
@ -646,7 +645,7 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
bandWidth := partialPath.amountToReceive bandWidth := partialPath.amountToReceive
for _, reverseEdge := range additionalEdgesWithSrc[pivot] { for _, reverseEdge := range additionalEdgesWithSrc[pivot] {
processEdge(reverseEdge.sourceNode, bandWidth, processEdge(reverseEdge.sourceNode, bandWidth,
reverseEdge.edge, pivot) reverseEdge.edge, partialPath)
} }
} }