From 5f348800409832aab1bb66a6782fcae734927eec Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 3 Mar 2021 09:59:05 -0800 Subject: [PATCH] channeldb/invoices: continue cancel loop early --- channeldb/invoices.go | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/channeldb/invoices.go b/channeldb/invoices.go index 5cb0cdfc..1675f15c 100644 --- a/channeldb/invoices.go +++ b/channeldb/invoices.go @@ -1816,23 +1816,24 @@ func (d *DB) updateInvoice(hash lntypes.Hash, invoices, // Check whether this htlc needs to be canceled. If it does, // update the htlc state to Canceled. _, cancel := cancelHtlcs[key] - if cancel { - // Consistency check to verify that there is no overlap - // between the add and cancel sets. - if _, added := update.AddHtlcs[key]; added { - return nil, fmt.Errorf("added htlc %v canceled", - key) - } - - err := cancelSingleHtlc(now, htlc, newState) - if err != nil { - return nil, err - } - - // Delete processed cancel action, so that we can check - // later that there are no actions left. - delete(cancelHtlcs, key) + if !cancel { + continue } + + // Consistency check to verify that there is no overlap between + // the add and cancel sets. + if _, added := update.AddHtlcs[key]; added { + return nil, fmt.Errorf("added htlc %v canceled", key) + } + + err := cancelSingleHtlc(now, htlc, newState) + if err != nil { + return nil, err + } + + // Delete processed cancel action, so that we can check later + // that there are no actions left. + delete(cancelHtlcs, key) } // Verify that we didn't get an action for htlcs that are not present on