invoices+channeldb: Fix AMP invoices behaviour.
We now cancel all HTLCs of an AMP invoice as soon as it expires. Otherwise because we mark the invoice as cancelled we would not allow accepted HTLCs to be resolved via the invoiceEventLoop.
This commit is contained in:
6 files changed
+205
-24
No files matched your search
@@ -31,7 +31,7 @@ func acceptHtlcsAmp(invoice *Invoice, setID SetID,
|
||||
}
|
||||
|
||||
// cancelHtlcsAmp processes a cancellation of an HTLC that belongs to an AMP
|
||||
// HTLC set. We'll need to update the meta data in the main invoice, and also
|
||||
// HTLC set. We'll need to update the meta data in the main invoice, and also
|
||||
// apply the new update to the update MAP, since all the HTLCs for a given HTLC
|
||||
// set need to be written in-line with each other.
|
||||
func cancelHtlcsAmp(invoice *Invoice, circuitKey models.CircuitKey,
|
||||
@@ -552,6 +552,9 @@ func cancelInvoice(invoice *Invoice, hash *lntypes.Hash,
|
||||
invoice.State = ContractCanceled
|
||||
|
||||
for key, htlc := range invoice.Htlcs {
|
||||
// We might not have a setID here in case we are cancelling
|
||||
// an AMP invoice however the setID is only important when
|
||||
// settling an AMP HTLC.
|
||||
canceled, _, err := getUpdatedHtlcState(
|
||||
htlc, ContractCanceled, setID,
|
||||
)
|
||||
@@ -567,6 +570,19 @@ func cancelInvoice(invoice *Invoice, hash *lntypes.Hash,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// If its an AMP HTLC we need to make sure we persist
|
||||
// this new state otherwise AMP HTLCs are not updated
|
||||
// on disk because HTLCs for AMP invoices are stored
|
||||
// separately.
|
||||
if htlc.AMP != nil {
|
||||
err := cancelHtlcsAmp(
|
||||
invoice, key, htlc, updater,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user