From 4725e4b3ed1079d344ce79a1cfde12ea199f4946 Mon Sep 17 00:00:00 2001 From: Andras Banki-Horvath Date: Thu, 22 May 2025 10:03:08 +0200 Subject: [PATCH] loopin: generate route hints correctly if last hop is set --- loopin.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/loopin.go b/loopin.go index 45f639a02..959f6ce0d 100644 --- a/loopin.go +++ b/loopin.go @@ -103,17 +103,20 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig, return nil, fmt.Errorf("private and route_hints both set") } - // If Private is set, we generate route hints. - if request.Private { - // If last_hop is set, we'll only add channels with peers set to - // the last_hop parameter. - includeNodes := make(map[route.Vertex]struct{}) - if request.LastHop != nil { - includeNodes[*request.LastHop] = struct{}{} - } - - // Because the Private flag is set, we'll generate our own set - // of hop hints. + // If last_hop is set, we'll only add channels with peers set to + // the last_hop parameter. + includeNodes := make(map[route.Vertex]struct{}) + if request.LastHop != nil { + includeNodes[*request.LastHop] = struct{}{} + } + + // SelectHopHints is used to generate route hints for the swap and probe + // invoices. If the user has set the last_hop parameter, we will only + // add channels with the peer set to the last_hop parameter. If the user + // has requested a private swap, we'll use the intersection of the last + // hop and the private channels of the node. If the user only requested + // private channels, we'll select from all private channels of the node. + if request.Private || request.LastHop != nil { request.RouteHints, err = SelectHopHints( globalCtx, cfg.lnd.Client, request.Amount, DefaultMaxHopHints, includeNodes,