Merge pull request #3449 from joostjager/route-success-prob

routerrpc: report route success probability
This commit is contained in:
Joost Jager 2019-09-05 12:34:18 +02:00 committed by GitHub
commit fb565bcd5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 578 additions and 519 deletions

View File

@ -231,13 +231,41 @@ func (r *RouterBackend) QueryRoutes(ctx context.Context,
return nil, err
}
// Calculate route success probability. Do not rely on a probability
// that could have been returned from path finding, because mission
// control may have been disabled in the provided ProbabilitySource.
successProb := r.getSuccessProbability(route)
routeResp := &lnrpc.QueryRoutesResponse{
Routes: []*lnrpc.Route{rpcRoute},
Routes: []*lnrpc.Route{rpcRoute},
SuccessProb: successProb,
}
return routeResp, nil
}
// getSuccessProbability returns the success probability for the given route
// based on the current state of mission control.
func (r *RouterBackend) getSuccessProbability(rt *route.Route) float64 {
fromNode := rt.SourcePubKey
amtToFwd := rt.TotalAmount
successProb := 1.0
for _, hop := range rt.Hops {
toNode := hop.PubKeyBytes
probability := r.MissionControl.GetProbability(
fromNode, toNode, amtToFwd,
)
successProb *= probability
amtToFwd = hop.AmtToForward
fromNode = toNode
}
return successProb
}
// rpcEdgeToPair looks up the provided channel and returns the channel endpoints
// as a directed pair.
func (r *RouterBackend) rpcEdgeToPair(e *lnrpc.EdgeLocator) (

File diff suppressed because it is too large Load Diff

View File

@ -1704,7 +1704,17 @@ message EdgeLocator {
}
message QueryRoutesResponse {
/**
The route that results from the path finding operation. This is still a
repeated field to retain backwards compatibility.
*/
repeated Route routes = 1 [json_name = "routes"];
/**
The success probability of the returned route based on the current mission
control state. [EXPERIMENTAL]
*/
double success_prob = 2 [json_name = "success_prob"];
}
message Hop {

View File

@ -3163,7 +3163,13 @@
"type": "array",
"items": {
"$ref": "#/definitions/lnrpcRoute"
}
},
"description": "*\nThe route that results from the path finding operation. This is still a\nrepeated field to retain backwards compatibility."
},
"success_prob": {
"type": "number",
"format": "double",
"title": "*\nThe success probability of the returned route based on the current mission\ncontrol state. [EXPERIMENTAL]"
}
}
},