Skip to content

Commit 582468c

Browse files
authored
Merge pull request #9199 from GeorgeTsagk/htlc-modify-cancel-htlc
Add `cancelSet` flag HtlcModify interface
2 parents e488002 + 4b1bb10 commit 582468c

File tree

6 files changed

+55
-9
lines changed

6 files changed

+55
-9
lines changed

invoices/interface.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,12 @@ type HtlcModifyResponse struct {
247247
// HTLC was originally sent with, in case additional value is carried
248248
// along with it (which might be the case in custom channels).
249249
AmountPaid lnwire.MilliSatoshi
250+
251+
// CancelSet is a flag the interceptor client can set to force a
252+
// cancellation of all HTLCs associated with the invoice that are
253+
// currently accepted. Setting this field will ignore the AmountPaid
254+
// field.
255+
CancelSet bool
250256
}
251257

252258
// HtlcModifyCallback is a function that is called when an invoice is

invoices/invoiceregistry.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,8 @@ func (i *InvoiceRegistry) notifyExitHopHtlcLocked(
10491049
return nil, nil, err
10501050
}
10511051

1052+
var cancelSet bool
1053+
10521054
// Provide the invoice to the settlement interceptor to allow
10531055
// the interceptor's client an opportunity to manipulate the
10541056
// settlement process.
@@ -1066,6 +1068,8 @@ func (i *InvoiceRegistry) notifyExitHopHtlcLocked(
10661068
if resp.AmountPaid != 0 {
10671069
ctx.amtPaid = resp.AmountPaid
10681070
}
1071+
1072+
cancelSet = resp.CancelSet
10691073
})
10701074
if err != nil {
10711075
err := fmt.Errorf("error during invoice HTLC interception: %w",
@@ -1092,7 +1096,18 @@ func (i *InvoiceRegistry) notifyExitHopHtlcLocked(
10921096
updateDesc.State != nil
10931097

10941098
// Assign resolution to outer scope variable.
1095-
resolution = res
1099+
if cancelSet {
1100+
// If a cancel signal was set for the htlc set, we set
1101+
// the resolution as a failure with an underpayment
1102+
// indication. Something was wrong with this htlc, so
1103+
// we probably can't settle the invoice at all.
1104+
resolution = NewFailResolution(
1105+
ctx.circuitKey, ctx.currentHeight,
1106+
ResultAmountTooLow,
1107+
)
1108+
} else {
1109+
resolution = res
1110+
}
10961111

10971112
return updateDesc, nil
10981113
}

lnrpc/invoicesrpc/htlc_modifier.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,6 @@ func (r *htlcModifier) onIntercept(
8282

8383
return &invoices.HtlcModifyResponse{
8484
AmountPaid: amtPaid,
85+
CancelSet: resp.CancelSet,
8586
}, nil
8687
}

lnrpc/invoicesrpc/invoices.pb.go

Lines changed: 22 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lnrpc/invoicesrpc/invoices.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,10 @@ message HtlcModifyResponse {
242242
// HTLC carries other valuable items, as can be the case with custom channel
243243
// types.
244244
optional uint64 amt_paid = 2;
245+
246+
// This flag indicates whether the HTLCs associated with the invoices should
247+
// be cancelled. The interceptor client may set this field if some
248+
// unexpected behavior is encountered. Setting this will ignore the amt_paid
249+
// field.
250+
bool cancel_set = 3;
245251
}

lnrpc/invoicesrpc/invoices.swagger.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,10 @@
423423
"type": "string",
424424
"format": "uint64",
425425
"description": "The modified amount in milli-satoshi that the exit HTLC is paying. This\nvalue can be different from the actual on-chain HTLC amount, in case the\nHTLC carries other valuable items, as can be the case with custom channel\ntypes."
426+
},
427+
"cancel_set": {
428+
"type": "boolean",
429+
"description": "This flag indicates whether the HTLCs associated with the invoices should\nbe cancelled. The interceptor client may set this field if some\nunexpected behavior is encountered. Setting this will ignore the amt_paid\nfield."
426430
}
427431
}
428432
},

0 commit comments

Comments
 (0)