Skip to content

Commit 0e7ed91

Browse files
committed
loop: integrate the probe api with loop-in quote
In this commit we add a call to the new probe endpoint directly into the loop-in quote call. Furthermore we add an option to include private channels in the loopin swap payment request. This is also useful for when users quote/probe directly using the client API and specify hop hints.
1 parent f786aaa commit 0e7ed91

File tree

8 files changed

+367
-310
lines changed

8 files changed

+367
-310
lines changed

client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ func (s *Client) LoopInQuote(ctx context.Context,
565565

566566
quote, err := s.Server.GetLoopInQuote(
567567
ctx, request.Amount, s.lndServices.NodePubkey, request.LastHop,
568+
request.RouteHints,
568569
)
569570
if err != nil {
570571
return nil, err

interface.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ type LoopInQuoteRequest struct {
249249
// the client has already requested a server probe for more accurate
250250
// routing fee estimation.
251251
LastHop *route.Vertex
252+
253+
// RouteHints are optional route hints to reach the destination through
254+
// private channels.
255+
RouteHints [][]zpay32.HopHint
252256
}
253257

254258
// LoopInQuote contains estimates for the fees making up the total swap cost

loopd/swapclient_server.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,29 @@ func (s *swapClientServer) GetLoopInQuote(ctx context.Context,
483483
return nil, err
484484
}
485485

486+
var lastHop *route.Vertex
487+
if req.LoopInLastHop != nil {
488+
lastHopVertex, err := route.NewVertexFromBytes(
489+
req.LoopInLastHop,
490+
)
491+
if err != nil {
492+
return nil, err
493+
}
494+
495+
lastHop = &lastHopVertex
496+
}
497+
498+
routeHints, err := unmarshallRouteHints(req.LoopInRouteHints)
499+
if err != nil {
500+
return nil, err
501+
}
502+
486503
quote, err := s.impl.LoopInQuote(ctx, &loop.LoopInQuoteRequest{
487504
Amount: btcutil.Amount(req.Amt),
488505
HtlcConfTarget: htlcConfTarget,
489506
ExternalHtlc: req.ExternalHtlc,
507+
LastHop: lastHop,
508+
RouteHints: routeHints,
490509
})
491510
if err != nil {
492511
return nil, err
@@ -569,7 +588,6 @@ func (s *swapClientServer) Probe(ctx context.Context,
569588
LastHop: lastHop,
570589
RouteHints: routeHints,
571590
})
572-
573591
if err != nil {
574592
return nil, err
575593
}

loopin.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,14 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
8282

8383
// Request current server loop in terms and use these to calculate the
8484
// swap fee that we should subtract from the swap amount in the payment
85-
// request that we send to the server.
85+
// request that we send to the server. We pass nil as optional route
86+
// hints as hop hint selection when generating invoices with private
87+
// channels is an LND side black box feaure. Advanced users will quote
88+
// directly anyway and there they have the option to add specific
89+
// route hints.
8690
quote, err := cfg.server.GetLoopInQuote(
8791
globalCtx, request.Amount, cfg.lnd.NodePubkey, request.LastHop,
92+
nil,
8893
)
8994
if err != nil {
9095
return nil, wrapGrpcError("loop in terms", err)

looprpc/client.pb.go

Lines changed: 320 additions & 304 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

looprpc/client.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,11 @@ message QuoteRequest {
575575
server.
576576
*/
577577
bytes loop_in_last_hop = 5;
578+
579+
/*
580+
Optional route hints to reach the destination through private channels.
581+
*/
582+
repeated RouteHint loop_in_route_hints = 6;
578583
}
579584

580585
message InQuoteResponse {

server_mock_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func (s *serverMock) GetLoopInTerms(ctx context.Context) (
213213
}
214214

215215
func (s *serverMock) GetLoopInQuote(context.Context, btcutil.Amount,
216-
route.Vertex, *route.Vertex) (*LoopInQuote, error) {
216+
route.Vertex, *route.Vertex, [][]zpay32.HopHint) (*LoopInQuote, error) {
217217

218218
return &LoopInQuote{
219219
SwapFee: testSwapFee,

swap_server_client.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import (
2323
"github.com/lightningnetwork/lnd/tor"
2424
"github.com/lightningnetwork/lnd/zpay32"
2525
"google.golang.org/grpc"
26+
"google.golang.org/grpc/codes"
2627
"google.golang.org/grpc/credentials"
28+
"google.golang.org/grpc/status"
2729
)
2830

2931
var (
@@ -53,7 +55,8 @@ type swapServerClient interface {
5355
*LoopInTerms, error)
5456

5557
GetLoopInQuote(ctx context.Context, amt btcutil.Amount,
56-
pubKey route.Vertex, lastHop *route.Vertex) (*LoopInQuote, error)
58+
pubKey route.Vertex, lastHop *route.Vertex,
59+
routeHints [][]zpay32.HopHint) (*LoopInQuote, error)
5760

5861
Probe(ctx context.Context, amt btcutil.Amount, target route.Vertex,
5962
lastHop *route.Vertex, routeHints [][]zpay32.HopHint) error
@@ -207,8 +210,13 @@ func (s *grpcSwapServerClient) GetLoopInTerms(ctx context.Context) (
207210
}
208211

209212
func (s *grpcSwapServerClient) GetLoopInQuote(ctx context.Context,
210-
amt btcutil.Amount, pubKey route.Vertex, lastHop *route.Vertex) (
211-
*LoopInQuote, error) {
213+
amt btcutil.Amount, pubKey route.Vertex, lastHop *route.Vertex,
214+
routeHints [][]zpay32.HopHint) (*LoopInQuote, error) {
215+
216+
err := s.Probe(ctx, amt, pubKey, lastHop, routeHints)
217+
if err != nil && status.Code(err) != codes.Unavailable {
218+
log.Warnf("Server probe error: %v", err)
219+
}
212220

213221
rpcCtx, rpcCancel := context.WithTimeout(ctx, globalCallTimeout)
214222
defer rpcCancel()

0 commit comments

Comments
 (0)