mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-29 03:01:52 +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,
|
func (i *InvoiceRegistry) cancelSingleHtlc(invoiceRef InvoiceRef,
|
||||||
key CircuitKey, result FailResolutionResult) error {
|
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.
|
// Only allow individual htlc cancellation on open invoices.
|
||||||
if invoice.State != ContractOpen {
|
if invoice.State != ContractOpen {
|
||||||
log.Debugf("cancelSingleHtlc: invoice %v no longer "+
|
log.Debugf("cancelSingleHtlc: invoice %v no longer "+
|
||||||
@ -663,37 +665,16 @@ func (i *InvoiceRegistry) cancelSingleHtlc(invoiceRef InvoiceRef,
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lookup the current status of the htlc in the database.
|
// Also for AMP invoices we fetch the relevant HTLCs, so
|
||||||
var (
|
// the HTLC should be found, otherwise we return an error.
|
||||||
htlcState HtlcState
|
|
||||||
setID *SetID
|
|
||||||
)
|
|
||||||
htlc, ok := invoice.Htlcs[key]
|
htlc, ok := invoice.Htlcs[key]
|
||||||
if !ok {
|
if !ok {
|
||||||
// If this is an AMP invoice, then all the HTLCs won't
|
return nil, fmt.Errorf("htlc %v not found on "+
|
||||||
// be read out, so we'll consult the other mapping to
|
"invoice %v", key, invoiceRef)
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
htlcState := htlc.State
|
||||||
|
|
||||||
// Cancellation is only possible if the htlc wasn't already
|
// Cancellation is only possible if the htlc wasn't already
|
||||||
// resolved.
|
// resolved.
|
||||||
if htlcState != HtlcStateAccepted {
|
if htlcState != HtlcStateAccepted {
|
||||||
@ -729,7 +710,7 @@ func (i *InvoiceRegistry) cancelSingleHtlc(invoiceRef InvoiceRef,
|
|||||||
func(invoice *Invoice) (
|
func(invoice *Invoice) (
|
||||||
*InvoiceUpdateDesc, error) {
|
*InvoiceUpdateDesc, error) {
|
||||||
|
|
||||||
updateDesc, err := updateInvoice(invoice)
|
updateDesc, err := updateInvoice(invoice, setID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -756,8 +737,12 @@ func (i *InvoiceRegistry) cancelSingleHtlc(invoiceRef InvoiceRef,
|
|||||||
key, int32(htlc.AcceptHeight), result,
|
key, int32(htlc.AcceptHeight), result,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
log.Debugf("Cancelling htlc (%v) of invoice(%v) with "+
|
||||||
|
"resolution: %v", key, invoiceRef, result)
|
||||||
|
|
||||||
i.notifyHodlSubscribers(resolution)
|
i.notifyHodlSubscribers(resolution)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user