routing: add source parameter to query routes

This commit allows execution of QueryRoutes from any source node.
Previously this was restricted to only the self node.
This commit is contained in:
Joost Jager committed 2019-03-06 15:31:03 +01:00
1 parent 7719bc432f
commit c62c9d64da
7 files changed
+646 -586

No files matched your search

+2 -2
View File
@@ -1712,7 +1712,7 @@ func TestPathFindSpecExample(t *testing.T) {
carol := ctx.aliases["C"]
const amt lnwire.MilliSatoshi = 4999999
routes, err := ctx.router.FindRoutes(
carol, amt, noRestrictions, 100,
bobNode.PubKeyBytes, carol, amt, noRestrictions, 100,
)
if err != nil {
t.Fatalf("unable to find route: %v", err)
@@ -1779,7 +1779,7 @@ func TestPathFindSpecExample(t *testing.T) {
// We'll now request a route from A -> B -> C.
ctx.router.routeCache = make(map[routeTuple][]*Route)
routes, err = ctx.router.FindRoutes(
carol, amt, noRestrictions, 100,
source.PubKeyBytes, carol, amt, noRestrictions, 100,
)
if err != nil {
t.Fatalf("unable to find routes: %v", err)
+5 -5
View File
@@ -1325,9 +1325,9 @@ func pathsToFeeSortedRoutes(source Vertex, paths [][]*channeldb.ChannelEdgePolic
// the required fee and time lock values running backwards along the route. The
// route that will be ranked the highest is the one with the lowest cumulative
// fee along the route.
func (r *ChannelRouter) FindRoutes(target Vertex, amt lnwire.MilliSatoshi,
restrictions *RestrictParams, numPaths uint32, finalExpiry ...uint16) (
[]*Route, error) {
func (r *ChannelRouter) FindRoutes(source, target Vertex,
amt lnwire.MilliSatoshi, restrictions *RestrictParams, numPaths uint32,
finalExpiry ...uint16) ([]*Route, error) {
var finalCLTVDelta uint16
if len(finalExpiry) == 0 {
@@ -1394,8 +1394,8 @@ func (r *ChannelRouter) FindRoutes(target Vertex, amt lnwire.MilliSatoshi,
// we'll execute our KSP algorithm to find the k-shortest paths from
// our source to the destination.
shortestPaths, err := findPaths(
tx, r.cfg.Graph, r.selfNode.PubKeyBytes, target, amt,
restrictions, numPaths, bandwidthHints,
tx, r.cfg.Graph, source, target, amt, restrictions,
numPaths, bandwidthHints,
)
if err != nil {
tx.Rollback()
+4
View File
@@ -184,6 +184,7 @@ func TestFindRoutesFeeSorting(t *testing.T) {
paymentAmt := lnwire.NewMSatFromSatoshis(100)
target := ctx.aliases["luoji"]
routes, err := ctx.router.FindRoutes(
ctx.router.selfNode.PubKeyBytes,
target, paymentAmt, noRestrictions, defaultNumRoutes,
DefaultFinalCLTVDelta,
)
@@ -245,6 +246,7 @@ func TestFindRoutesWithFeeLimit(t *testing.T) {
}
routes, err := ctx.router.FindRoutes(
ctx.router.selfNode.PubKeyBytes,
target, paymentAmt, restrictions, defaultNumRoutes,
DefaultFinalCLTVDelta,
)
@@ -1341,6 +1343,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
var targetPubKeyBytes Vertex
copy(targetPubKeyBytes[:], targetNode.SerializeCompressed())
routes, err := ctx.router.FindRoutes(
ctx.router.selfNode.PubKeyBytes,
targetPubKeyBytes, paymentAmt, noRestrictions, defaultNumRoutes,
DefaultFinalCLTVDelta,
)
@@ -1386,6 +1389,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
// Should still be able to find the routes, and the info should be
// updated.
routes, err = ctx.router.FindRoutes(
ctx.router.selfNode.PubKeyBytes,
targetPubKeyBytes, paymentAmt, noRestrictions, defaultNumRoutes,
DefaultFinalCLTVDelta,
)