From ef5a31733e4a5135156849cbbbb94e2c6273a553 Mon Sep 17 00:00:00 2001 From: Andras Banki-Horvath Date: Fri, 24 Nov 2023 16:50:04 +0100 Subject: [PATCH] channeldb: do not change the update descriptor when cancelling htlcs --- channeldb/invoices.go | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/channeldb/invoices.go b/channeldb/invoices.go index d2c60f614..24ca9c805 100644 --- a/channeldb/invoices.go +++ b/channeldb/invoices.go @@ -1944,15 +1944,13 @@ func (d *DB) cancelHTLCs(invoices kvdb.RwBucket, invoiceNum []byte, htlcsAmpUpdate := make(map[invpkg.SetID]map[models.CircuitKey]*invpkg.InvoiceHTLC) //nolint:lll // Process cancel actions from update descriptor. - cancelHtlcs := update.CancelHtlcs - for key, htlc := range invoice.Htlcs { - htlc := htlc + for key := range update.CancelHtlcs { + htlc, exists := invoice.Htlcs[key] - // Check whether this htlc needs to be canceled. If it does, - // update the htlc state to Canceled. - _, cancel := cancelHtlcs[key] - if !cancel { - continue + // Verify that we don't get an action for htlcs that are not + // present on the invoice. + if !exists { + return nil, fmt.Errorf("cancel of non-existent htlc") } err := cancelSingleHtlc(timestamp, htlc, invoice.State) @@ -1960,10 +1958,6 @@ func (d *DB) cancelHTLCs(invoices kvdb.RwBucket, invoiceNum []byte, return nil, err } - // Delete processed cancel action, so that we can check later - // that there are no actions left. - delete(cancelHtlcs, key) - // Tally this into the set of HTLCs that need to be updated on // disk, but once again, only if this is an AMP invoice. if invoice.IsAMP() { @@ -1976,12 +1970,6 @@ func (d *DB) cancelHTLCs(invoices kvdb.RwBucket, invoiceNum []byte, } } - // Verify that we didn't get an action for htlcs that are not present on - // the invoice. - if len(cancelHtlcs) > 0 { - return nil, errors.New("cancel action on non-existent htlc(s)") - } - err := d.cancelHTLCsStoreUpdate( invoices, invoiceNum, invoice, htlcsAmpUpdate, )