routing: use probability source in path finding
This PR replaces the previously used edge and node ignore lists in path finding by a probability based system. It modifies path finding so that it not only compares routes on fee and time lock, but also takes route success probability into account. Allowing routes to be compared based on success probability is achieved by introducing a 'virtual' cost of a payment attempt and using that to translate probability into another cost factor.
This commit is contained in:
7 files changed
+327
-118
No files matched your search
@@ -123,9 +123,21 @@ func (r *RouterBackend) QueryRoutes(ctx context.Context,
|
||||
}
|
||||
|
||||
restrictions := &routing.RestrictParams{
|
||||
FeeLimit: feeLimit,
|
||||
IgnoredNodes: ignoredNodes,
|
||||
IgnoredEdges: ignoredEdges,
|
||||
FeeLimit: feeLimit,
|
||||
ProbabilitySource: func(node route.Vertex,
|
||||
edge routing.EdgeLocator) float64 {
|
||||
|
||||
if _, ok := ignoredNodes[node]; ok {
|
||||
return 0
|
||||
}
|
||||
|
||||
if _, ok := ignoredEdges[edge]; ok {
|
||||
return 0
|
||||
}
|
||||
|
||||
return 1
|
||||
},
|
||||
PaymentAttemptPenalty: routing.DefaultPaymentAttemptPenalty,
|
||||
}
|
||||
|
||||
// Query the channel router for a possible path to the destination that
|
||||
|
||||
@@ -39,6 +39,11 @@ func TestQueryRoutes(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ignoredEdge := routing.EdgeLocator{
|
||||
ChannelID: 555,
|
||||
Direction: 1,
|
||||
}
|
||||
|
||||
request := &lnrpc.QueryRoutesRequest{
|
||||
PubKey: destKey,
|
||||
Amt: 100000,
|
||||
@@ -75,22 +80,22 @@ func TestQueryRoutes(t *testing.T) {
|
||||
t.Fatal("unexpected fee limit")
|
||||
}
|
||||
|
||||
if len(restrictions.IgnoredEdges) != 1 {
|
||||
t.Fatal("unexpected ignored edges map size")
|
||||
if restrictions.ProbabilitySource(route.Vertex{},
|
||||
ignoredEdge,
|
||||
) != 0 {
|
||||
t.Fatal("expecting 0% probability for ignored edge")
|
||||
}
|
||||
|
||||
if _, ok := restrictions.IgnoredEdges[routing.EdgeLocator{
|
||||
ChannelID: 555, Direction: 1,
|
||||
}]; !ok {
|
||||
t.Fatal("unexpected ignored edge")
|
||||
if restrictions.ProbabilitySource(ignoreNodeVertex,
|
||||
routing.EdgeLocator{},
|
||||
) != 0 {
|
||||
t.Fatal("expecting 0% probability for ignored node")
|
||||
}
|
||||
|
||||
if len(restrictions.IgnoredNodes) != 1 {
|
||||
t.Fatal("unexpected ignored nodes map size")
|
||||
}
|
||||
|
||||
if _, ok := restrictions.IgnoredNodes[ignoreNodeVertex]; !ok {
|
||||
t.Fatal("unexpected ignored node")
|
||||
if restrictions.ProbabilitySource(route.Vertex{},
|
||||
routing.EdgeLocator{},
|
||||
) != 1 {
|
||||
t.Fatal("expecting 100% probability")
|
||||
}
|
||||
|
||||
hops := []*route.Hop{{}}
|
||||
|
||||
Reference in new issue
Block a user