Skip to content

Commit

Permalink
cln: handle missing htlc_accepted fields
Browse files Browse the repository at this point in the history
  • Loading branch information
JssDWt committed Nov 18, 2024
1 parent 74f12b9 commit ff1ce12
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 107 deletions.
16 changes: 11 additions & 5 deletions cln/cln_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,27 +140,33 @@ func (i *ClnHtlcInterceptor) intercept() error {
return
}

if request.Onion == nil || request.Onion.ShortChannelId == "" {
if request.Onion == nil ||
request.Onion.ShortChannelId == nil ||
*request.Onion.ShortChannelId == "" ||
request.Onion.SharedSecret == nil ||
request.Onion.ForwardMsat == nil ||
request.Onion.OutgoingCltvValue == nil {

interceptorClient.Send(i.defaultResolution(request))
i.doneWg.Done()
return
}

scid, err := lightning.NewShortChannelIDFromString(request.Onion.ShortChannelId)
scid, err := lightning.NewShortChannelIDFromString(*request.Onion.ShortChannelId)
if err != nil {
interceptorClient.Send(i.defaultResolution(request))
i.doneWg.Done()
return
}

interceptResult := i.interceptor.Intercept(common.InterceptRequest{
Identifier: request.Onion.SharedSecret,
Identifier: *request.Onion.SharedSecret,
Scid: *scid,
PaymentHash: paymentHash,
IncomingAmountMsat: request.Htlc.AmountMsat,
OutgoingAmountMsat: request.Onion.ForwardMsat,
OutgoingAmountMsat: *request.Onion.ForwardMsat,
IncomingExpiry: request.Htlc.CltvExpiry,
OutgoingExpiry: request.Onion.OutgoingCltvValue,
OutgoingExpiry: *request.Onion.OutgoingCltvValue,
})
switch interceptResult.Action {
case common.INTERCEPT_RESUME_WITH_ONION:
Expand Down
12 changes: 6 additions & 6 deletions cln_plugin/cln_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ type HtlcAccepted struct {
}

type Onion struct {
Payload string `json:"payload"`
ShortChannelId string `json:"short_channel_id"`
ForwardMsat uint64 `json:"forward_msat"`
OutgoingCltvValue uint32 `json:"outgoing_cltv_value"`
SharedSecret string `json:"shared_secret"`
NextOnion string `json:"next_onion"`
Payload string `json:"payload"`
ShortChannelId *string `json:"short_channel_id,omitempty"`
ForwardMsat *uint64 `json:"forward_msat,omitempty"`
OutgoingCltvValue *uint32 `json:"outgoing_cltv_value,omitempty"`
SharedSecret *string `json:"shared_secret,omitempty"`
NextOnion *string `json:"next_onion,omitempty"`
}

type Htlc struct {
Expand Down
Loading

0 comments on commit ff1ce12

Please sign in to comment.