routing+routerrpc+lnrpc: add option to use mc in queryroutes
A boolean flag is added to the QueryRoutes rpc that allows feeding mission control probabilities into path finding.
This commit is contained in:
5 files changed
+563
-500
No files matched your search
@@ -167,7 +167,13 @@ func (r *RouterBackend) QueryRoutes(ctx context.Context,
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1
|
if !in.UseMissionControl {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
return r.MissionControl.GetEdgeProbability(
|
||||||
|
node, edge, amt,
|
||||||
|
)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import (
|
|||||||
const (
|
const (
|
||||||
destKey = "0286098b97bc843372b4426d4b276cea9aa2f48f0428d6f5b66ae101befc14f8b4"
|
destKey = "0286098b97bc843372b4426d4b276cea9aa2f48f0428d6f5b66ae101befc14f8b4"
|
||||||
ignoreNodeKey = "02f274f48f3c0d590449a6776e3ce8825076ac376e470e992246eebc565ef8bb2a"
|
ignoreNodeKey = "02f274f48f3c0d590449a6776e3ce8825076ac376e470e992246eebc565ef8bb2a"
|
||||||
|
|
||||||
|
testMissionControlProb = 0.5
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -26,6 +28,15 @@ var (
|
|||||||
// TestQueryRoutes asserts that query routes rpc parameters are properly parsed
|
// TestQueryRoutes asserts that query routes rpc parameters are properly parsed
|
||||||
// and passed onto path finding.
|
// and passed onto path finding.
|
||||||
func TestQueryRoutes(t *testing.T) {
|
func TestQueryRoutes(t *testing.T) {
|
||||||
|
t.Run("no mission control", func(t *testing.T) {
|
||||||
|
testQueryRoutes(t, false)
|
||||||
|
})
|
||||||
|
t.Run("with mission control", func(t *testing.T) {
|
||||||
|
testQueryRoutes(t, true)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func testQueryRoutes(t *testing.T, useMissionControl bool) {
|
||||||
ignoreNodeBytes, err := hex.DecodeString(ignoreNodeKey)
|
ignoreNodeBytes, err := hex.DecodeString(ignoreNodeKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -58,6 +69,7 @@ func TestQueryRoutes(t *testing.T) {
|
|||||||
ChannelId: 555,
|
ChannelId: 555,
|
||||||
DirectionReverse: true,
|
DirectionReverse: true,
|
||||||
}},
|
}},
|
||||||
|
UseMissionControl: useMissionControl,
|
||||||
}
|
}
|
||||||
|
|
||||||
findRoute := func(source, target route.Vertex,
|
findRoute := func(source, target route.Vertex,
|
||||||
@@ -92,9 +104,13 @@ func TestQueryRoutes(t *testing.T) {
|
|||||||
t.Fatal("expecting 0% probability for ignored node")
|
t.Fatal("expecting 0% probability for ignored node")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expectedProb := 1.0
|
||||||
|
if useMissionControl {
|
||||||
|
expectedProb = testMissionControlProb
|
||||||
|
}
|
||||||
if restrictions.ProbabilitySource(route.Vertex{},
|
if restrictions.ProbabilitySource(route.Vertex{},
|
||||||
routing.EdgeLocator{}, 0,
|
routing.EdgeLocator{}, 0,
|
||||||
) != 1 {
|
) != expectedProb {
|
||||||
t.Fatal("expecting 100% probability")
|
t.Fatal("expecting 100% probability")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,6 +127,7 @@ func TestQueryRoutes(t *testing.T) {
|
|||||||
|
|
||||||
return 1, nil
|
return 1, nil
|
||||||
},
|
},
|
||||||
|
MissionControl: &mockMissionControl{},
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := backend.QueryRoutes(context.Background(), request)
|
resp, err := backend.QueryRoutes(context.Background(), request)
|
||||||
@@ -121,3 +138,17 @@ func TestQueryRoutes(t *testing.T) {
|
|||||||
t.Fatal("expected a single route response")
|
t.Fatal("expected a single route response")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type mockMissionControl struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockMissionControl) GetEdgeProbability(fromNode route.Vertex,
|
||||||
|
edge routing.EdgeLocator, amt lnwire.MilliSatoshi) float64 {
|
||||||
|
return testMissionControlProb
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockMissionControl) ResetHistory() {}
|
||||||
|
|
||||||
|
func (m *mockMissionControl) GetHistorySnapshot() *routing.MissionControlSnapshot {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
+510
-498
File diff suppressed because it is too large.
Load diff
@@ -1651,6 +1651,12 @@ message QueryRoutesRequest {
|
|||||||
self is assumed.
|
self is assumed.
|
||||||
*/
|
*/
|
||||||
string source_pub_key = 8;
|
string source_pub_key = 8;
|
||||||
|
|
||||||
|
/**
|
||||||
|
If set to true, edge probabilities from mission control will be used to get
|
||||||
|
the optimal route.
|
||||||
|
*/
|
||||||
|
bool use_mission_control = 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
message EdgeLocator {
|
message EdgeLocator {
|
||||||
|
|||||||
@@ -722,6 +722,14 @@
|
|||||||
"in": "query",
|
"in": "query",
|
||||||
"required": false,
|
"required": false,
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "use_mission_control",
|
||||||
|
"description": "*\nIf set to true, edge probabilities from mission control will be used to get\nthe optimal route.",
|
||||||
|
"in": "query",
|
||||||
|
"required": false,
|
||||||
|
"type": "boolean",
|
||||||
|
"format": "boolean"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
|
|||||||
Reference in new issue
Block a user