From cd27ee7cfc9a12eca6a863452c3962d62e8ef782 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 5 Dec 2019 07:59:31 -0800 Subject: [PATCH] rpcserver+invoicesrpc: set payment addr on new invoices This commit modifies Lighting.AddInvoice and InvoicesRPC.AddHoldInvoice to include the node's supported feature bits on the invoice. For now this only includes the optional TLV Onion Payload bit. --- lnrpc/invoicesrpc/addinvoice.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lnrpc/invoicesrpc/addinvoice.go b/lnrpc/invoicesrpc/addinvoice.go index e99e9417..6fe149b1 100644 --- a/lnrpc/invoicesrpc/addinvoice.go +++ b/lnrpc/invoicesrpc/addinvoice.go @@ -370,6 +370,15 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig, ) options = append(options, zpay32.Features(invoiceFeatures)) + // Generate and set a random payment address for this invoice. If the + // sender understands payment addresses, this can be used to avoid + // intermediaries probing the receiver. + var paymentAddr [32]byte + if _, err := rand.Read(paymentAddr[:]); err != nil { + return nil, nil, err + } + options = append(options, zpay32.PaymentAddr(paymentAddr)) + // Create and encode the payment request as a bech32 (zpay32) string. creationDate := time.Now() payReq, err := zpay32.NewInvoice( @@ -397,6 +406,7 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig, Expiry: payReq.Expiry(), Value: amtMSat, PaymentPreimage: paymentPreimage, + PaymentAddr: paymentAddr, Features: invoiceFeatures, }, }