diff --git a/loopin.go b/loopin.go index e2bbe6c..7a76593 100644 --- a/loopin.go +++ b/loopin.go @@ -779,12 +779,30 @@ func (s *loopInSwap) waitForSwapComplete(ctx context.Context, htlcSpend = true // Swap invoice ntfn error. - case err := <-swapInvoiceErr: + case err, ok := <-swapInvoiceErr: + // If the channel has been closed, the server has + // finished sending updates, so we set the channel to + // nil because we don't want to constantly select this + // case. + if !ok { + swapInvoiceErr = nil + continue + } + return err // An update to the swap invoice occurred. Check the new state // and update the swap state accordingly. - case update := <-swapInvoiceChan: + case update, ok := <-swapInvoiceChan: + // If the channel has been closed, the server has + // finished sending updates, so we set the channel to + // nil because we don't want to constantly select this + // case. + if !ok { + swapInvoiceChan = nil + continue + } + s.log.Infof("Received swap invoice update: %v", update.State) diff --git a/loopin_testcontext_test.go b/loopin_testcontext_test.go index 7f0c0a8..e029c15 100644 --- a/loopin_testcontext_test.go +++ b/loopin_testcontext_test.go @@ -84,4 +84,13 @@ func (c *loopInTestContext) updateInvoiceState(amount btcutil.Amount, AmtPaid: amount, State: state, } + + // If we're in a final state, close our update channels as lndclient + // would. + if state == channeldb.ContractCanceled || + state == channeldb.ContractSettled { + + close(c.swapInvoiceSubscription.Update) + close(c.swapInvoiceSubscription.Err) + } }