Skip to content

Commit

Permalink
fix: use private channels in invoice routing (#386)
Browse files Browse the repository at this point in the history
* fix: use private channels in invoice routing

* fix: add private hints only if node is private

* chore: code cleanup

---------

Co-authored-by: Roland Bewick <[email protected]>
  • Loading branch information
im-adithya and rolznz authored Aug 2, 2024
1 parent c79e11e commit 9ae0712
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lnclient/lnd/lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,27 @@ func (svc *LNDService) MakeInvoice(ctx context.Context, amount int64, descriptio
expiry = lnclient.DEFAULT_INVOICE_EXPIRY
}

resp, err := svc.client.AddInvoice(ctx, &lnrpc.Invoice{ValueMsat: amount, Memo: description, DescriptionHash: descriptionHashBytes, Expiry: expiry})
channels, err := svc.ListChannels(ctx)
if err != nil {
return nil, err
}

hasPublicChannels := false
for _, channel := range channels {
if channel.Active && channel.Public {
hasPublicChannels = true
}
}

addInvoiceRequest := &lnrpc.Invoice{
ValueMsat: amount,
Memo: description,
DescriptionHash: descriptionHashBytes,
Expiry: expiry,
Private: !hasPublicChannels, // use private channel hints in the invoice
}

resp, err := svc.client.AddInvoice(ctx, addInvoiceRequest)

if err != nil {
return nil, err
Expand Down

0 comments on commit 9ae0712

Please sign in to comment.