channeldb: do not change the update descriptor when cancelling htlcs

This commit is contained in:
Andras Banki-Horvath
2023-11-24 16:50:04 +01:00
parent 7298b2d190
commit ef5a31733e

View File

@@ -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 htlcsAmpUpdate := make(map[invpkg.SetID]map[models.CircuitKey]*invpkg.InvoiceHTLC) //nolint:lll
// Process cancel actions from update descriptor. // Process cancel actions from update descriptor.
cancelHtlcs := update.CancelHtlcs for key := range update.CancelHtlcs {
for key, htlc := range invoice.Htlcs { htlc, exists := invoice.Htlcs[key]
htlc := htlc
// Check whether this htlc needs to be canceled. If it does, // Verify that we don't get an action for htlcs that are not
// update the htlc state to Canceled. // present on the invoice.
_, cancel := cancelHtlcs[key] if !exists {
if !cancel { return nil, fmt.Errorf("cancel of non-existent htlc")
continue
} }
err := cancelSingleHtlc(timestamp, htlc, invoice.State) err := cancelSingleHtlc(timestamp, htlc, invoice.State)
@@ -1960,10 +1958,6 @@ func (d *DB) cancelHTLCs(invoices kvdb.RwBucket, invoiceNum []byte,
return nil, err 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 // Tally this into the set of HTLCs that need to be updated on
// disk, but once again, only if this is an AMP invoice. // disk, but once again, only if this is an AMP invoice.
if invoice.IsAMP() { 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( err := d.cancelHTLCsStoreUpdate(
invoices, invoiceNum, invoice, htlcsAmpUpdate, invoices, invoiceNum, invoice, htlcsAmpUpdate,
) )