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
2022-12-19 17:10:22 -05:00
committed by Olaoluwa Osuntokun
parent 11a007dc16
commit 48e36d93d4
6 changed files with 127 additions and 54 deletions

View File

@@ -55,14 +55,9 @@ type RouterBackend struct {
FetchChannelEndpoints func(chanID uint64) (route.Vertex,
route.Vertex, error)
// FindRoutes is a closure that abstracts away how we locate/query for
// FindRoute is a closure that abstracts away how we locate/query for
// routes.
FindRoute func(source, target route.Vertex,
amt lnwire.MilliSatoshi, timePref float64,
restrictions *routing.RestrictParams,
destCustomRecords record.CustomSet,
routeHints map[route.Vertex][]*channeldb.CachedEdgePolicy,
finalExpiry uint16) (*route.Route, float64, error)
FindRoute func(*routing.RouteRequest) (*route.Route, float64, error)
MissionControl MissionControl
@@ -330,14 +325,19 @@ func (r *RouterBackend) QueryRoutes(ctx context.Context,
// Query the channel router for a possible path to the destination that
// can carry `in.Amt` satoshis _including_ the total fee required on
// the route.
route, successProb, err := r.FindRoute(
sourcePubKey, targetPubKey, amt, in.TimePref, restrictions,
routeReq, err := routing.NewRouteRequest(
sourcePubKey, &targetPubKey, amt, in.TimePref, restrictions,
customRecords, routeHintEdges, finalCLTVDelta,
)
if err != nil {
return nil, err
}
route, successProb, err := r.FindRoute(routeReq)
if err != nil {
return nil, err
}
// For each valid route, we'll convert the result into the format
// required by the RPC system.
rpcRoute, err := r.MarshallRoute(route)

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
}

View File

@@ -398,8 +398,8 @@ func (s *Server) EstimateRouteFee(ctx context.Context,
// restriction for the default CLTV limit, otherwise we can find a route
// that exceeds it and is useless to us.
mc := s.cfg.RouterBackend.MissionControl
route, _, err := s.cfg.Router.FindRoute(
s.cfg.RouterBackend.SelfNode, destNode, amtMsat, 0,
routeReq, err := routing.NewRouteRequest(
s.cfg.RouterBackend.SelfNode, &destNode, amtMsat, 0,
&routing.RestrictParams{
FeeLimit: feeLimit,
CltvLimit: s.cfg.RouterBackend.MaxTotalTimelock,
@@ -410,6 +410,11 @@ func (s *Server) EstimateRouteFee(ctx context.Context,
return nil, err
}
route, _, err := s.cfg.Router.FindRoute(routeReq)
if err != nil {
return nil, err
}
return &RouteFeeResponse{
RoutingFeeMsat: int64(route.TotalFees()),
TimeLockDelay: int64(route.TotalTimeLock),