Skip to content

Commit c9ae63a

Browse files
authored
Merge pull request #9338 from yyforyongyu/fix-invoice-htlcs-order
lnrpc: sort `Invoice.HTLCs` based on `HtlcIndex`
2 parents 5659c01 + 7374392 commit c9ae63a

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

docs/release-notes/release-notes-0.19.0.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@
9090
* [The `walletrpc.FundPsbt` method now has a new option to specify the maximum
9191
fee to output amounts ratio.](https://github.com/lightningnetwork/lnd/pull/8600)
9292

93+
* When returning the response from list invoices RPC, the `lnrpc.Invoice.Htlcs`
94+
are now [sorted](https://github.com/lightningnetwork/lnd/pull/9337) based on
95+
the `InvoiceHTLC.HtlcIndex`.
96+
9397
## lncli Additions
9498

9599
* [A pre-generated macaroon root key can now be specified in `lncli create` and

lnrpc/invoicesrpc/utils.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package invoicesrpc
22

33
import (
4+
"cmp"
45
"encoding/hex"
56
"fmt"
7+
"slices"
68

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

165+
// Perform an inplace sort of the HTLCs to ensure they are ordered.
166+
slices.SortFunc(rpcHtlcs, func(i, j *lnrpc.InvoiceHTLC) int {
167+
return cmp.Compare(i.HtlcIndex, j.HtlcIndex)
168+
})
169+
163170
rpcInvoice := &lnrpc.Invoice{
164171
Memo: string(invoice.Memo),
165172
RHash: rHash,

0 commit comments

Comments
 (0)