Skip to content

Commit 34e9a05

Browse files
committed
rfq: update order handler for noop HTLCs
When routing HTLCs we also want to do 2 things: a) Upon receiving an HTLC with no matching policy, we want to make sure that this HTLC is not using the noop feature, as that would lead to loss of funds. b) Upon producing an outgoing HTLC over an asset channel (that carries assets) we also want to set the noop flag, in order to not shift the satoshi balance.
1 parent 33ad31e commit 34e9a05

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

rfq/order.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/lightningnetwork/lnd/graph/db/models"
1818
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
1919
"github.com/lightningnetwork/lnd/lnutils"
20+
"github.com/lightningnetwork/lnd/lnwallet"
2021
"github.com/lightningnetwork/lnd/lnwire"
2122
"github.com/lightningnetwork/lnd/tlv"
2223
)
@@ -284,6 +285,8 @@ func (c *AssetSalePolicy) GenerateInterceptorResponse(
284285
fn.None[[]rfqmsg.ID](),
285286
)
286287

288+
htlcRecord.SetNoopAdd(rfqmsg.UseNoOpHTLCs)
289+
287290
customRecords, err := lnwire.ParseCustomRecords(htlcRecord.Bytes())
288291
if err != nil {
289292
return nil, fmt.Errorf("error parsing custom records: %w", err)
@@ -731,7 +734,21 @@ func (h *OrderHandler) handleIncomingHtlc(ctx context.Context,
731734
}
732735

733736
if !ok {
737+
noopTLV := uint64(lnwallet.NoOpHtlcTLVEntry.TypeVal())
738+
_, noopActive := htlc.InWireCustomRecords[noopTLV]
739+
740+
// If we don't have a matching policy for this HTLC but the
741+
// sender set the noop flag, that means we were about to push
742+
// some outgoing sats amount that we would eventually never
743+
// receive. The HTLC must be failed.
744+
if noopActive {
745+
return &lndclient.InterceptedHtlcResponse{
746+
Action: lndclient.InterceptorActionFail,
747+
}, nil
748+
}
749+
734750
log.Debug("Failed to find a policy for the HTLC. Resuming.")
751+
735752
return &lndclient.InterceptedHtlcResponse{
736753
Action: lndclient.InterceptorActionResume,
737754
}, nil

0 commit comments

Comments
 (0)