multi/refactor: add RouteRequest to hold FindRoute parameters

This commit introduces a single struct to hold all of the parameters
that are passed to FindRoute. This cleans up an already overloaded
function signature and prepares us for handling requests with blinded
routes where we need to perform some additional processing on our
para (such as extracting the target node from the blinded path).
This commit is contained in:
Carla Kirk-Cohen authored and Olaoluwa Osuntokun committed 2023-10-06 16:38:33 -07:00
1 parent 11a007dc16
commit 48e36d93d4
6 files changed
+127 -54

No files matched your search

+10 -10
View File
@@ -7,10 +7,8 @@ import (
"testing"
"github.com/btcsuite/btcd/btcutil"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/record"
"github.com/lightningnetwork/lnd/routing"
"github.com/lightningnetwork/lnd/routing/route"
"github.com/stretchr/testify/require"
@@ -122,24 +120,23 @@ func testQueryRoutes(t *testing.T, useMissionControl bool, useMsat bool,
}
}
findRoute := func(source, target route.Vertex,
amt lnwire.MilliSatoshi, _ float64,
restrictions *routing.RestrictParams, _ record.CustomSet,
routeHints map[route.Vertex][]*channeldb.CachedEdgePolicy,
finalExpiry uint16) (*route.Route, float64, error) {
findRoute := func(req *routing.RouteRequest) (*route.Route, float64,
error) {
if int64(amt) != amtSat*1000 {
if int64(req.Amount) != amtSat*1000 {
t.Fatal("unexpected amount")
}
if source != sourceKey {
if req.Source != sourceKey {
t.Fatal("unexpected source key")
}
target := req.Target
if !bytes.Equal(target[:], destNodeBytes) {
t.Fatal("unexpected target key")
}
restrictions := req.Restrictions
if restrictions.FeeLimit != 250*1000 {
t.Fatal("unexpected fee limit")
}
@@ -172,6 +169,7 @@ func testQueryRoutes(t *testing.T, useMissionControl bool, useMsat bool,
t.Fatal("unexpected dest features")
}
routeHints := req.RouteHints
if _, ok := routeHints[hintNode]; !ok {
t.Fatal("expected route hint")
}
@@ -187,7 +185,9 @@ func testQueryRoutes(t *testing.T, useMissionControl bool, useMsat bool,
}
hops := []*route.Hop{{}}
route, err := route.NewRouteFromHops(amt, 144, source, hops)
route, err := route.NewRouteFromHops(
req.Amount, 144, req.Source, hops,
)
return route, expectedProb, err
}