routing+lnrpc: add missing query routes parameters
This commit is contained in:
9 files changed
+825
-626
No files matched your search
@@ -45,6 +45,7 @@ type RouterBackend struct {
|
||||
FindRoute func(source, target route.Vertex,
|
||||
amt lnwire.MilliSatoshi, restrictions *routing.RestrictParams,
|
||||
destCustomRecords record.CustomSet,
|
||||
routeHints map[route.Vertex][]*channeldb.ChannelEdgePolicy,
|
||||
finalExpiry ...uint16) (*route.Route, error)
|
||||
|
||||
MissionControl MissionControl
|
||||
@@ -199,6 +200,12 @@ func (r *RouterBackend) QueryRoutes(ctx context.Context,
|
||||
}
|
||||
cltvLimit -= uint32(finalCLTVDelta)
|
||||
|
||||
// Parse destination feature bits.
|
||||
features, err := UnmarshalFeatures(in.DestFeatures)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
restrictions := &routing.RestrictParams{
|
||||
FeeLimit: feeLimit,
|
||||
ProbabilitySource: func(fromNode, toNode route.Vertex,
|
||||
@@ -226,6 +233,23 @@ func (r *RouterBackend) QueryRoutes(ctx context.Context,
|
||||
},
|
||||
DestCustomRecords: record.CustomSet(in.DestCustomRecords),
|
||||
CltvLimit: cltvLimit,
|
||||
DestFeatures: features,
|
||||
}
|
||||
|
||||
// Pass along an outgoing channel restriction if specified.
|
||||
if in.OutgoingChanId != 0 {
|
||||
restrictions.OutgoingChannelID = &in.OutgoingChanId
|
||||
}
|
||||
|
||||
// Pass along a last hop restriction if specified.
|
||||
if len(in.LastHopPubkey) > 0 {
|
||||
lastHop, err := route.NewVertexFromBytes(
|
||||
in.LastHopPubkey,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
restrictions.LastHop = &lastHop
|
||||
}
|
||||
|
||||
// If we have any TLV records destined for the final hop, then we'll
|
||||
@@ -236,12 +260,24 @@ func (r *RouterBackend) QueryRoutes(ctx context.Context,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Convert route hints to an edge map.
|
||||
routeHints, err := unmarshallRouteHints(in.RouteHints)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
routeHintEdges, err := routing.RouteHintsToEdges(
|
||||
routeHints, targetPubKey,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 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, err := r.FindRoute(
|
||||
sourcePubKey, targetPubKey, amt, restrictions,
|
||||
customRecords, finalCLTVDelta,
|
||||
customRecords, routeHintEdges, finalCLTVDelta,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/record"
|
||||
"github.com/lightningnetwork/lnd/routing"
|
||||
@@ -18,6 +19,7 @@ import (
|
||||
const (
|
||||
destKey = "0286098b97bc843372b4426d4b276cea9aa2f48f0428d6f5b66ae101befc14f8b4"
|
||||
ignoreNodeKey = "02f274f48f3c0d590449a6776e3ce8825076ac376e470e992246eebc565ef8bb2a"
|
||||
hintNodeKey = "0274e7fb33eafd74fe1acb6db7680bb4aa78e9c839a6e954e38abfad680f645ef7"
|
||||
|
||||
testMissionControlProb = 0.5
|
||||
)
|
||||
@@ -58,6 +60,27 @@ func testQueryRoutes(t *testing.T, useMissionControl bool, useMsat bool) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var (
|
||||
lastHop = route.Vertex{64}
|
||||
outgoingChan = uint64(383322)
|
||||
)
|
||||
|
||||
hintNode, err := route.NewVertexFromStr(hintNodeKey)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
rpcRouteHints := []*lnrpc.RouteHint{
|
||||
{
|
||||
HopHints: []*lnrpc.HopHint{
|
||||
{
|
||||
ChanId: 38484,
|
||||
NodeId: hintNodeKey,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
request := &lnrpc.QueryRoutesRequest{
|
||||
PubKey: destKey,
|
||||
FinalCltvDelta: 100,
|
||||
@@ -71,6 +94,10 @@ func testQueryRoutes(t *testing.T, useMissionControl bool, useMsat bool) {
|
||||
To: node2[:],
|
||||
}},
|
||||
UseMissionControl: useMissionControl,
|
||||
LastHopPubkey: lastHop[:],
|
||||
OutgoingChanId: outgoingChan,
|
||||
DestFeatures: []lnrpc.FeatureBit{lnrpc.FeatureBit_MPP_OPT},
|
||||
RouteHints: rpcRouteHints,
|
||||
}
|
||||
|
||||
amtSat := int64(100000)
|
||||
@@ -93,6 +120,7 @@ func testQueryRoutes(t *testing.T, useMissionControl bool, useMsat bool) {
|
||||
findRoute := func(source, target route.Vertex,
|
||||
amt lnwire.MilliSatoshi, restrictions *routing.RestrictParams,
|
||||
_ record.CustomSet,
|
||||
routeHints map[route.Vertex][]*channeldb.ChannelEdgePolicy,
|
||||
finalExpiry ...uint16) (*route.Route, error) {
|
||||
|
||||
if int64(amt) != amtSat*1000 {
|
||||
@@ -127,6 +155,22 @@ func testQueryRoutes(t *testing.T, useMissionControl bool, useMsat bool) {
|
||||
t.Fatal("expecting 0% probability for ignored pair")
|
||||
}
|
||||
|
||||
if *restrictions.LastHop != lastHop {
|
||||
t.Fatal("unexpected last hop")
|
||||
}
|
||||
|
||||
if *restrictions.OutgoingChannelID != outgoingChan {
|
||||
t.Fatal("unexpected outgoing channel id")
|
||||
}
|
||||
|
||||
if !restrictions.DestFeatures.HasFeature(lnwire.MPPOptional) {
|
||||
t.Fatal("unexpected dest features")
|
||||
}
|
||||
|
||||
if _, ok := routeHints[hintNode]; !ok {
|
||||
t.Fatal("expected route hint")
|
||||
}
|
||||
|
||||
expectedProb := 1.0
|
||||
if useMissionControl {
|
||||
expectedProb = testMissionControlProb
|
||||
|
||||
@@ -260,7 +260,7 @@ func (s *Server) EstimateRouteFee(ctx context.Context,
|
||||
&routing.RestrictParams{
|
||||
FeeLimit: feeLimit,
|
||||
CltvLimit: s.cfg.RouterBackend.MaxTotalTimelock,
|
||||
}, nil,
|
||||
}, nil, nil,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in new issue
Block a user