Skip to content

Commit

Permalink
Merge pull request #9338 from yyforyongyu/fix-invoice-htlcs-order
Browse files Browse the repository at this point in the history
lnrpc: sort `Invoice.HTLCs` based on `HtlcIndex`
  • Loading branch information
guggero authored Dec 9, 2024
2 parents 5659c01 + 7374392 commit c9ae63a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/release-notes/release-notes-0.19.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
* [The `walletrpc.FundPsbt` method now has a new option to specify the maximum
fee to output amounts ratio.](https://github.com/lightningnetwork/lnd/pull/8600)

* When returning the response from list invoices RPC, the `lnrpc.Invoice.Htlcs`
are now [sorted](https://github.com/lightningnetwork/lnd/pull/9337) based on
the `InvoiceHTLC.HtlcIndex`.

## lncli Additions

* [A pre-generated macaroon root key can now be specified in `lncli create` and
Expand Down
7 changes: 7 additions & 0 deletions lnrpc/invoicesrpc/utils.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package invoicesrpc

import (
"cmp"
"encoding/hex"
"fmt"
"slices"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/chaincfg"
Expand Down Expand Up @@ -160,6 +162,11 @@ func CreateRPCInvoice(invoice *invoices.Invoice,
rpcHtlcs = append(rpcHtlcs, &rpcHtlc)
}

// Perform an inplace sort of the HTLCs to ensure they are ordered.
slices.SortFunc(rpcHtlcs, func(i, j *lnrpc.InvoiceHTLC) int {
return cmp.Compare(i.HtlcIndex, j.HtlcIndex)
})

rpcInvoice := &lnrpc.Invoice{
Memo: string(invoice.Memo),
RHash: rHash,
Expand Down

0 comments on commit c9ae63a

Please sign in to comment.