mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-26 01:33:02 +01:00
invoices: remove obsolete code for AMP invoices.
We always fetch the HTLCs for the specific setID, so there is no need to keep this code. In earlier versions we would call the UpdateInvoice method with `nil` for the setID therefore we had to lookup the AMPState. However this was error prune because in case one partial payment times-out the AMPState would change to cancelled and that could lead to not resolve HTLCs.
This commit is contained in:
parent
728f8fc482
commit
8ce00a8e79
@ -654,7 +654,9 @@ func (i *InvoiceRegistry) startHtlcTimer(invoiceRef InvoiceRef,
|
||||
func (i *InvoiceRegistry) cancelSingleHtlc(invoiceRef InvoiceRef,
|
||||
key CircuitKey, result FailResolutionResult) error {
|
||||
|
||||
updateInvoice := func(invoice *Invoice) (*InvoiceUpdateDesc, error) {
|
||||
updateInvoice := func(invoice *Invoice, setID *SetID) (
|
||||
*InvoiceUpdateDesc, error) {
|
||||
|
||||
// Only allow individual htlc cancellation on open invoices.
|
||||
if invoice.State != ContractOpen {
|
||||
log.Debugf("cancelSingleHtlc: invoice %v no longer "+
|
||||
@ -663,37 +665,16 @@ func (i *InvoiceRegistry) cancelSingleHtlc(invoiceRef InvoiceRef,
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Lookup the current status of the htlc in the database.
|
||||
var (
|
||||
htlcState HtlcState
|
||||
setID *SetID
|
||||
)
|
||||
// Also for AMP invoices we fetch the relevant HTLCs, so
|
||||
// the HTLC should be found, otherwise we return an error.
|
||||
htlc, ok := invoice.Htlcs[key]
|
||||
if !ok {
|
||||
// If this is an AMP invoice, then all the HTLCs won't
|
||||
// be read out, so we'll consult the other mapping to
|
||||
// try to find the HTLC state in question here.
|
||||
var found bool
|
||||
for ampSetID, htlcSet := range invoice.AMPState {
|
||||
ampSetID := ampSetID
|
||||
for htlcKey := range htlcSet.InvoiceKeys {
|
||||
if htlcKey == key {
|
||||
htlcState = htlcSet.State
|
||||
setID = &SetID
|
||||
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
return nil, fmt.Errorf("htlc %v not found", key)
|
||||
}
|
||||
} else {
|
||||
htlcState = htlc.State
|
||||
return nil, fmt.Errorf("htlc %v not found on "+
|
||||
"invoice %v", key, invoiceRef)
|
||||
}
|
||||
|
||||
htlcState := htlc.State
|
||||
|
||||
// Cancellation is only possible if the htlc wasn't already
|
||||
// resolved.
|
||||
if htlcState != HtlcStateAccepted {
|
||||
@ -729,7 +710,7 @@ func (i *InvoiceRegistry) cancelSingleHtlc(invoiceRef InvoiceRef,
|
||||
func(invoice *Invoice) (
|
||||
*InvoiceUpdateDesc, error) {
|
||||
|
||||
updateDesc, err := updateInvoice(invoice)
|
||||
updateDesc, err := updateInvoice(invoice, setID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -756,8 +737,12 @@ func (i *InvoiceRegistry) cancelSingleHtlc(invoiceRef InvoiceRef,
|
||||
key, int32(htlc.AcceptHeight), result,
|
||||
)
|
||||
|
||||
log.Debugf("Cancelling htlc (%v) of invoice(%v) with "+
|
||||
"resolution: %v", key, invoiceRef, result)
|
||||
|
||||
i.notifyHodlSubscribers(resolution)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user