@@ -654,7 +654,9 @@ func (i *InvoiceRegistry) startHtlcTimer(invoiceRef InvoiceRef,
654
654
func (i * InvoiceRegistry ) cancelSingleHtlc (invoiceRef InvoiceRef ,
655
655
key CircuitKey , result FailResolutionResult ) error {
656
656
657
- updateInvoice := func (invoice * Invoice ) (* InvoiceUpdateDesc , error ) {
657
+ updateInvoice := func (invoice * Invoice , setID * SetID ) (
658
+ * InvoiceUpdateDesc , error ) {
659
+
658
660
// Only allow individual htlc cancellation on open invoices.
659
661
if invoice .State != ContractOpen {
660
662
log .Debugf ("cancelSingleHtlc: invoice %v no longer " +
@@ -663,37 +665,16 @@ func (i *InvoiceRegistry) cancelSingleHtlc(invoiceRef InvoiceRef,
663
665
return nil , nil
664
666
}
665
667
666
- // Lookup the current status of the htlc in the database.
667
- var (
668
- htlcState HtlcState
669
- setID * SetID
670
- )
668
+ // Also for AMP invoices we fetch the relevant HTLCs, so
669
+ // the HTLC should be found, otherwise we return an error.
671
670
htlc , ok := invoice .Htlcs [key ]
672
671
if ! ok {
673
- // If this is an AMP invoice, then all the HTLCs won't
674
- // be read out, so we'll consult the other mapping to
675
- // try to find the HTLC state in question here.
676
- var found bool
677
- for ampSetID , htlcSet := range invoice .AMPState {
678
- ampSetID := ampSetID
679
- for htlcKey := range htlcSet .InvoiceKeys {
680
- if htlcKey == key {
681
- htlcState = htlcSet .State
682
- setID = & ampSetID
683
-
684
- found = true
685
- break
686
- }
687
- }
688
- }
689
-
690
- if ! found {
691
- return nil , fmt .Errorf ("htlc %v not found" , key )
692
- }
693
- } else {
694
- htlcState = htlc .State
672
+ return nil , fmt .Errorf ("htlc %v not found on " +
673
+ "invoice %v" , key , invoiceRef )
695
674
}
696
675
676
+ htlcState := htlc .State
677
+
697
678
// Cancellation is only possible if the htlc wasn't already
698
679
// resolved.
699
680
if htlcState != HtlcStateAccepted {
@@ -729,7 +710,7 @@ func (i *InvoiceRegistry) cancelSingleHtlc(invoiceRef InvoiceRef,
729
710
func (invoice * Invoice ) (
730
711
* InvoiceUpdateDesc , error ) {
731
712
732
- updateDesc , err := updateInvoice (invoice )
713
+ updateDesc , err := updateInvoice (invoice , setID )
733
714
if err != nil {
734
715
return nil , err
735
716
}
@@ -756,8 +737,12 @@ func (i *InvoiceRegistry) cancelSingleHtlc(invoiceRef InvoiceRef,
756
737
key , int32 (htlc .AcceptHeight ), result ,
757
738
)
758
739
740
+ log .Debugf ("Cancelling htlc (%v) of invoice(%v) with " +
741
+ "resolution: %v" , key , invoiceRef , result )
742
+
759
743
i .notifyHodlSubscribers (resolution )
760
744
}
745
+
761
746
return nil
762
747
}
763
748
0 commit comments