routing: use capacity in pathfinding

Extends the pathfinder with a capacity argument for later usage.

In tests, the inserted testCapacity has no effect, but will be used
later to estimate reduced probabilities from it.
This commit is contained in:
bitromortac committed 2022-12-12 13:22:28 +01:00
1 parent 2b6308a61f
commit 516e3a8cca
11 files changed
+70 -37

No files matched your search

+5 -4
View File
@@ -103,7 +103,7 @@ type MissionControl interface {
// GetProbability is expected to return the success probability of a
// payment from fromNode to toNode.
GetProbability(fromNode, toNode route.Vertex,
amt lnwire.MilliSatoshi) float64
amt lnwire.MilliSatoshi, capacity btcutil.Amount) float64
// ResetHistory resets the history of MissionControl returning it to a
// state as if no payment attempts have been made.
@@ -258,7 +258,8 @@ func (r *RouterBackend) QueryRoutes(ctx context.Context,
restrictions := &routing.RestrictParams{
FeeLimit: feeLimit,
ProbabilitySource: func(fromNode, toNode route.Vertex,
amt lnwire.MilliSatoshi) float64 {
amt lnwire.MilliSatoshi,
capacity btcutil.Amount) float64 {
if _, ok := ignoredNodes[fromNode]; ok {
return 0
@@ -277,7 +278,7 @@ func (r *RouterBackend) QueryRoutes(ctx context.Context,
}
return r.MissionControl.GetProbability(
fromNode, toNode, amt,
fromNode, toNode, amt, capacity,
)
},
DestCustomRecords: record.CustomSet(in.DestCustomRecords),
@@ -362,7 +363,7 @@ func (r *RouterBackend) getSuccessProbability(rt *route.Route) float64 {
toNode := hop.PubKeyBytes
probability := r.MissionControl.GetProbability(
fromNode, toNode, amtToFwd,
fromNode, toNode, amtToFwd, 0,
)
successProb *= probability
+5 -5
View File
@@ -145,18 +145,18 @@ func testQueryRoutes(t *testing.T, useMissionControl bool, useMsat bool,
}
if restrictions.ProbabilitySource(route.Vertex{2},
route.Vertex{1}, 0,
route.Vertex{1}, 0, 0,
) != 0 {
t.Fatal("expecting 0% probability for ignored edge")
}
if restrictions.ProbabilitySource(ignoreNodeVertex,
route.Vertex{6}, 0,
route.Vertex{6}, 0, 0,
) != 0 {
t.Fatal("expecting 0% probability for ignored node")
}
if restrictions.ProbabilitySource(node1, node2, 0) != 0 {
if restrictions.ProbabilitySource(node1, node2, 0, 0) != 0 {
t.Fatal("expecting 0% probability for ignored pair")
}
@@ -181,7 +181,7 @@ func testQueryRoutes(t *testing.T, useMissionControl bool, useMsat bool,
expectedProb = testMissionControlProb
}
if restrictions.ProbabilitySource(route.Vertex{4},
route.Vertex{5}, 0,
route.Vertex{5}, 0, 0,
) != expectedProb {
t.Fatal("expecting 100% probability")
}
@@ -239,7 +239,7 @@ type mockMissionControl struct {
}
func (m *mockMissionControl) GetProbability(fromNode, toNode route.Vertex,
amt lnwire.MilliSatoshi) float64 {
amt lnwire.MilliSatoshi, capacity btcutil.Amount) float64 {
return testMissionControlProb
}
+1 -1
View File
@@ -710,7 +710,7 @@ func (s *Server) QueryProbability(ctx context.Context,
amt := lnwire.MilliSatoshi(req.AmtMsat)
mc := s.cfg.RouterBackend.MissionControl
prob := mc.GetProbability(fromNode, toNode, amt)
prob := mc.GetProbability(fromNode, toNode, amt, 0)
history := mc.GetPairHistorySnapshot(fromNode, toNode)
return &QueryProbabilityResponse{