Skip to content

Commit a52f621

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 43989dc commit a52f621

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

rfq/order.go

Lines changed: 20 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,11 @@ func (c *AssetSalePolicy) GenerateInterceptorResponse(
284285
fn.None[[]rfqmsg.ID](),
285286
)
286287

288+
// We are about to create an outgoing HTLC that carries assets. Let's
289+
// set the noop flag in order to eventually only settle the assets but
290+
// never settle the sats anchor amount that will carry them.
291+
htlcRecord.SetNoopAdd(rfqmsg.UseNoOpHTLCs)
292+
287293
customRecords, err := lnwire.ParseCustomRecords(htlcRecord.Bytes())
288294
if err != nil {
289295
return nil, fmt.Errorf("error parsing custom records: %w", err)
@@ -731,7 +737,21 @@ func (h *OrderHandler) handleIncomingHtlc(ctx context.Context,
731737
}
732738

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

0 commit comments

Comments
 (0)