Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upCompute routes backward #797
Conversation
Dec 28, 2018
added some commits
This comment has been minimized.
This comment has been minimized.
I chose to have an explicit parameter on the graph construction and manipulation functions, alternatively we can have a separate function with reverse in the name i.e "addEdgeReverse", please let me know what do you think of it. |
This comment has been minimized.
This comment has been minimized.
Isn't it possible to use the same graph (i.e. not need for the additional |
This comment has been minimized.
This comment has been minimized.
Sure it's possible, especially if we want to support only the graph in reverse order. |
Jan 2, 2019
added some commits
This comment has been minimized.
This comment has been minimized.
Latest commit hid the "reverse" parameter and now the graph and shortestPath method work only in reverse mode (i left some comment in the docs to clarify the graph operations as it might be a little confusing) |
sstone
reviewed
Jan 4, 2019
@@ -791,7 +791,7 @@ object Router { | |||
def findRoute(g: DirectedGraph, localNodeId: PublicKey, targetNodeId: PublicKey, amountMsat: Long, extraEdges: Set[GraphEdge] = Set.empty, ignoredEdges: Set[ChannelDesc] = Set.empty): Try[Seq[Hop]] = Try { | |||
if (localNodeId == targetNodeId) throw CannotRouteToSelf | |||
|
|||
Graph.shortestPath(g, localNodeId, targetNodeId, amountMsat, ignoredEdges, extraEdges) match { | |||
Graph.shortestPath(g, targetNodeId, localNodeId, amountMsat, ignoredEdges.map(reverseDesc), extraEdges.map(edge => edge.copy(desc = reverseDesc(edge.desc)))) match { |
This comment has been minimized.
This comment has been minimized.
sstone
Jan 4, 2019
Member
I think we should keep the method and parameters as they were, we are still computing a shortest path from the source to the destination, it's just that internally we compute it backwards
Jan 6, 2019
and others
added some commits
pm47
reviewed
Jan 8, 2019
What is the overall performance impact in terms of compute time? |
// note: the default value here will never be used, as there is always an entry for the current in the 'cost' map | ||
val newMinimumKnownCost = cost.get(current.key) + edgeWeightByAmount(edge, amountMsat) | ||
// test for ignored edges | ||
if (!(edge.update.htlcMaximumMsat.exists(_ < newMinimumKnownCost) || |
This comment has been minimized.
This comment has been minimized.
pm47
Jan 8, 2019
Member
is that the most optimal order for the testing conditions? Given that the first to return true
will return immediately
This comment has been minimized.
This comment has been minimized.
* @param isNeighborTarget true if the receiving vertex of this edge is the target node (source in a reversed graph), which has cost 0 | ||
* @return the new amount updated with the necessary fees for this edge | ||
*/ | ||
private def edgeWeight(edge: GraphEdge, amountWithFees: Long, isNeighborTarget: Boolean): Long = isNeighborTarget match { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
araspitzu
Jan 9, 2019
Author
Member
Depends on which one you consider more readable, i've used 'match' for testing conditions and this is consistent to it.
This comment has been minimized.
This comment has been minimized.
Performance impact is not significant, i just benchmarked it and the graph initialization is still around 2.4s with 13k channels (measurements not taken on the mobile phone). On the other hand we're now computing the correct routes thanks to the backward search and incremental edge cost.
|
araspitzu
added some commits
Jan 9, 2019
This comment has been minimized.
This comment has been minimized.
Todo: update the wiki as soon as this is merged |
araspitzu
added some commits
Jan 10, 2019
sstone
approved these changes
Jan 11, 2019
sstone
merged commit fd3ff91
into
master
Jan 11, 2019
sstone
deleted the
routing_backward
branch
Jan 11, 2019
This comment has been minimized.
This comment has been minimized.
wiki updated |
araspitzu commentedJan 2, 2019
Compute the routes backward from the target and with the correct channels cost, nodes that are 'neighbor' to the local node (direct channel) will have a routing cost of 0.