mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-23 22:46:40 +01:00
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:
parent
df70095ad0
commit
818c302d46
1 changed files with 5 additions and 6 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue