mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
Merge pull request #3449 from joostjager/route-success-prob
routerrpc: report route success probability
This commit is contained in:
commit
fb565bcd5d
@ -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) (
|
||||
|
1049
lnrpc/rpc.pb.go
1049
lnrpc/rpc.pb.go
File diff suppressed because it is too large
Load Diff
@ -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 {
|
||||
|
@ -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]"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user