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
No known key found for this signature in database
GPG Key ID: 80E5375C094198D8

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
// 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,
)