invoices: exit early when the subscriber chan is nil
When calling `NotifyExitHopHtlc` it is allowed to pass a chan to subscribe to the HTLC's resolution when it's settled. However, this method will also return immediately if there's already a resolution, which means it behaves like a notifier and a getter. If the caller decides to only use the getter to do a non-blocking lookup, it can pass a nil subscriber chan to bypass the notification.
This commit is contained in:
2 files changed
+10
-1
No files matched your search
@@ -29,6 +29,11 @@ func (r *mockRegistry) NotifyExitHopHtlc(payHash lntypes.Hash,
|
|||||||
wireCustomRecords lnwire.CustomRecords,
|
wireCustomRecords lnwire.CustomRecords,
|
||||||
payload invoices.Payload) (invoices.HtlcResolution, error) {
|
payload invoices.Payload) (invoices.HtlcResolution, error) {
|
||||||
|
|
||||||
|
// Exit early if the notification channel is nil.
|
||||||
|
if hodlChan == nil {
|
||||||
|
return r.notifyResolution, r.notifyErr
|
||||||
|
}
|
||||||
|
|
||||||
r.notifyChan <- notifyExitHopData{
|
r.notifyChan <- notifyExitHopData{
|
||||||
hodlChan: hodlChan,
|
hodlChan: hodlChan,
|
||||||
payHash: payHash,
|
payHash: payHash,
|
||||||
|
|||||||
@@ -1275,7 +1275,11 @@ func (i *InvoiceRegistry) notifyExitHopHtlcLocked(
|
|||||||
invoiceToExpire = makeInvoiceExpiry(ctx.hash, invoice)
|
invoiceToExpire = makeInvoiceExpiry(ctx.hash, invoice)
|
||||||
}
|
}
|
||||||
|
|
||||||
i.hodlSubscribe(hodlChan, ctx.circuitKey)
|
// Subscribe to the resolution if the caller specified a
|
||||||
|
// notification channel.
|
||||||
|
if hodlChan != nil {
|
||||||
|
i.hodlSubscribe(hodlChan, ctx.circuitKey)
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
panic("unknown action")
|
panic("unknown action")
|
||||||
|
|||||||
Reference in new issue
Block a user