From 47cf144170b596aba10bf6cedc54588798608aee Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 23 Apr 2020 23:24:30 -0700 Subject: [PATCH] invoices: ensure ntfns are sent in the same order SettleHodlInvoice and CancelInvoice both notifyClients after notifyHodlSubscribers. This commit changes UpdateInvoice to follow the same pattern so that we are consistent. --- invoices/invoiceregistry.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/invoices/invoiceregistry.go b/invoices/invoiceregistry.go index 63328466..abb9f779 100644 --- a/invoices/invoiceregistry.go +++ b/invoices/invoiceregistry.go @@ -829,10 +829,6 @@ func (i *InvoiceRegistry) notifyExitHopHtlcLocked( return nil, err } - if updateSubscribers { - i.notifyClients(ctx.hash, invoice, invoice.State) - } - switch res := resolution.(type) { case *HtlcFailResolution: // Inspect latest htlc state on the invoice. If it is found, @@ -851,8 +847,6 @@ func (i *InvoiceRegistry) notifyExitHopHtlcLocked( "outcome: %v, at accept height: %v", res.Outcome, res.AcceptHeight)) - return res, nil - // If the htlc was settled, we will settle any previously accepted // htlcs and notify our peer to settle them. case *HtlcSettleResolution: @@ -883,8 +877,6 @@ func (i *InvoiceRegistry) notifyExitHopHtlcLocked( i.notifyHodlSubscribers(htlcSettleResolution) } - return resolution, nil - // If we accepted the htlc, subscribe to the hodl invoice and return // an accept resolution with the htlc's accept time on it. case *htlcAcceptResolution: @@ -915,11 +907,19 @@ func (i *InvoiceRegistry) notifyExitHopHtlcLocked( } i.hodlSubscribe(hodlChan, ctx.circuitKey) - return res, nil default: panic("unknown action") } + + // Now that the links have been notified of any state changes to their + // HTLCs, we'll go ahead and notify any clients wiaiting on the invoice + // state changes. + if updateSubscribers { + i.notifyClients(ctx.hash, invoice, invoice.State) + } + + return resolution, nil } // SettleHodlInvoice sets the preimage of a hodl invoice.