Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions invoices/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@ type HtlcModifyResponse struct {
// HTLC was originally sent with, in case additional value is carried
// along with it (which might be the case in custom channels).
AmountPaid lnwire.MilliSatoshi

// CancelSet is a flag the interceptor client can set to force a
// cancellation of all HTLCs associated with the invoice that are
// currently accepted. Setting this field will ignore the AmountPaid
// field.
CancelSet bool
}

// HtlcModifyCallback is a function that is called when an invoice is
Expand Down
17 changes: 16 additions & 1 deletion invoices/invoiceregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,8 @@ func (i *InvoiceRegistry) notifyExitHopHtlcLocked(
return nil, nil, err
}

var cancelSet bool

// Provide the invoice to the settlement interceptor to allow
// the interceptor's client an opportunity to manipulate the
// settlement process.
Expand All @@ -1066,6 +1068,8 @@ func (i *InvoiceRegistry) notifyExitHopHtlcLocked(
if resp.AmountPaid != 0 {
ctx.amtPaid = resp.AmountPaid
}

cancelSet = resp.CancelSet
})
if err != nil {
err := fmt.Errorf("error during invoice HTLC interception: %w",
Expand All @@ -1092,7 +1096,18 @@ func (i *InvoiceRegistry) notifyExitHopHtlcLocked(
updateDesc.State != nil

// Assign resolution to outer scope variable.
resolution = res
if cancelSet {
// If a cancel signal was set for the htlc set, we set
// the resolution as a failure with an underpayment
// indication. Something was wrong with this htlc, so
// we probably can't settle the invoice at all.
resolution = NewFailResolution(
ctx.circuitKey, ctx.currentHeight,
ResultAmountTooLow,
)
} else {
resolution = res
}

return updateDesc, nil
}
Expand Down
1 change: 1 addition & 0 deletions lnrpc/invoicesrpc/htlc_modifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,6 @@ func (r *htlcModifier) onIntercept(

return &invoices.HtlcModifyResponse{
AmountPaid: amtPaid,
CancelSet: resp.CancelSet,
}, nil
}
30 changes: 22 additions & 8 deletions lnrpc/invoicesrpc/invoices.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions lnrpc/invoicesrpc/invoices.proto
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,10 @@ message HtlcModifyResponse {
// HTLC carries other valuable items, as can be the case with custom channel
// types.
optional uint64 amt_paid = 2;

// This flag indicates whether the HTLCs associated with the invoices should
Comment thread
GeorgeTsagk marked this conversation as resolved.
// be cancelled. The interceptor client may set this field if some
// unexpected behavior is encountered. Setting this will ignore the amt_paid
// field.
bool cancel_set = 3;
}
4 changes: 4 additions & 0 deletions lnrpc/invoicesrpc/invoices.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,10 @@
"type": "string",
"format": "uint64",
"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."
},
"cancel_set": {
"type": "boolean",
"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."
}
}
},
Expand Down