@@ -23,6 +23,7 @@ import (
2323 "github.com/lightningnetwork/lnd/lntypes"
2424 "github.com/lightningnetwork/lnd/lnwallet/chainfee"
2525 "github.com/lightningnetwork/lnd/lnwire"
26+ "github.com/lightningnetwork/lnd/routing/route"
2627)
2728
2829var (
@@ -80,6 +81,33 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
8081 currentHeight int32 , request * LoopInRequest ) (* loopInInitResult ,
8182 error ) {
8283
84+ var err error
85+
86+ // Private and routehints are mutually exclusive as setting private
87+ // means we retrieve our own routehints from the connected node.
88+ if len (request .RouteHints ) != 0 && request .Private {
89+ return nil , fmt .Errorf ("private and route_hints both set" )
90+ }
91+
92+ // If Private is set, we generate route hints
93+ if request .Private {
94+ // If last_hop is set, we'll only add channels with peers
95+ // set to the last_hop parameter
96+ includeNodes := make (map [route.Vertex ]struct {})
97+ if request .LastHop != nil {
98+ includeNodes [* request .LastHop ] = struct {}{}
99+ }
100+
101+ // Because the Private flag is set, we'll generate our own
102+ // set of hop hints
103+ request .RouteHints , err = SelectHopHints (
104+ globalCtx , cfg .lnd , request .Amount , DefaultMaxHopHints , includeNodes ,
105+ )
106+ if err != nil {
107+ return nil , err
108+ }
109+ }
110+
83111 // Request current server loop in terms and use these to calculate the
84112 // swap fee that we should subtract from the swap amount in the payment
85113 // request that we send to the server. We pass nil as optional route
@@ -89,7 +117,7 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
89117 // route hints.
90118 quote , err := cfg .server .GetLoopInQuote (
91119 globalCtx , request .Amount , cfg .lnd .NodePubkey , request .LastHop ,
92- nil ,
120+ request . RouteHints ,
93121 )
94122 if err != nil {
95123 return nil , wrapGrpcError ("loop in terms" , err )
@@ -129,10 +157,11 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
129157 // Create the swap invoice in lnd.
130158 _ , swapInvoice , err := cfg .lnd .Client .AddInvoice (
131159 globalCtx , & invoicesrpc.AddInvoiceData {
132- Preimage : & swapPreimage ,
133- Value : lnwire .NewMSatFromSatoshis (swapInvoiceAmt ),
134- Memo : "swap" ,
135- Expiry : 3600 * 24 * 365 ,
160+ Preimage : & swapPreimage ,
161+ Value : lnwire .NewMSatFromSatoshis (swapInvoiceAmt ),
162+ Memo : "swap" ,
163+ Expiry : 3600 * 24 * 365 ,
164+ RouteHints : request .RouteHints ,
136165 },
137166 )
138167 if err != nil {
@@ -148,10 +177,11 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
148177 log .Infof ("Creating probe invoice %v" , probeHash )
149178 probeInvoice , err := cfg .lnd .Invoices .AddHoldInvoice (
150179 globalCtx , & invoicesrpc.AddInvoiceData {
151- Hash : & probeHash ,
152- Value : lnwire .NewMSatFromSatoshis (swapInvoiceAmt ),
153- Memo : "loop in probe" ,
154- Expiry : 3600 ,
180+ Hash : & probeHash ,
181+ Value : lnwire .NewMSatFromSatoshis (swapInvoiceAmt ),
182+ Memo : "loop in probe" ,
183+ Expiry : 3600 ,
184+ RouteHints : request .RouteHints ,
155185 },
156186 )
157187 if err != nil {
0 commit comments