From cf0e0ff32c2bb1768fb2d56a90da8db47f3510f8 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Thu, 17 Apr 2025 10:51:57 +0200 Subject: [PATCH 1/2] switch: add trace log for circular route detection Helps with debugging of strict forwarding issues. --- htlcswitch/switch.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/htlcswitch/switch.go b/htlcswitch/switch.go index c7b154751..d034e732e 100644 --- a/htlcswitch/switch.go +++ b/htlcswitch/switch.go @@ -1149,6 +1149,9 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error { func (s *Switch) checkCircularForward(incoming, outgoing lnwire.ShortChannelID, allowCircular bool, paymentHash lntypes.Hash) *LinkError { + log.Tracef("Checking for circular route: incoming=%v, outgoing=%v "+ + "(payment hash: %x)", incoming, outgoing, paymentHash[:]) + // If they are equal, we can skip the alias mapping checks. if incoming == outgoing { // The switch may be configured to allow circular routes, so @@ -1189,6 +1192,10 @@ func (s *Switch) checkCircularForward(incoming, outgoing lnwire.ShortChannelID, // Check base SCID equality. if incomingBaseScid != outgoingBaseScid { + log.Tracef("Incoming base SCID %v does not match outgoing "+ + "base SCID %v (payment hash: %x)", incomingBaseScid, + outgoingBaseScid, paymentHash[:]) + // The base SCIDs are not equal so these are not the same // channel. return nil From 5fb0f4317227ac5f57307be36bd7cf60dba63d20 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Thu, 17 Apr 2025 11:52:56 +0200 Subject: [PATCH 2/2] htlcswitch+routing: add htlc blob to ShouldHandleTraffic Whether we should let the aux bandwidth manager decide what the bandwidth of a channel is should also depend on whether the HTLC is a custom HTLC, not just the channel. --- htlcswitch/interfaces.go | 2 +- htlcswitch/link.go | 2 +- routing/bandwidth_test.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htlcswitch/interfaces.go b/htlcswitch/interfaces.go index 786788e09..cd7f7e250 100644 --- a/htlcswitch/interfaces.go +++ b/htlcswitch/interfaces.go @@ -509,7 +509,7 @@ type AuxTrafficShaper interface { // identified by the provided channel ID may have external mechanisms // that would allow it to carry out the payment. ShouldHandleTraffic(cid lnwire.ShortChannelID, - fundingBlob fn.Option[tlv.Blob]) (bool, error) + fundingBlob, htlcBlob fn.Option[tlv.Blob]) (bool, error) // PaymentBandwidth returns the available bandwidth for a custom channel // decided by the given channel aux blob and HTLC blob. A return value diff --git a/htlcswitch/link.go b/htlcswitch/link.go index bddf8d95e..7b93b018a 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -3484,7 +3484,7 @@ func (l *channelLink) AuxBandwidth(amount lnwire.MilliSatoshi, ts AuxTrafficShaper) fn.Result[OptionalBandwidth] { fundingBlob := l.FundingCustomBlob() - shouldHandle, err := ts.ShouldHandleTraffic(cid, fundingBlob) + shouldHandle, err := ts.ShouldHandleTraffic(cid, fundingBlob, htlcBlob) if err != nil { return fn.Err[OptionalBandwidth](fmt.Errorf("traffic shaper "+ "failed to decide whether to handle traffic: %w", err)) diff --git a/routing/bandwidth_test.go b/routing/bandwidth_test.go index 726275a6c..fa1955e02 100644 --- a/routing/bandwidth_test.go +++ b/routing/bandwidth_test.go @@ -140,7 +140,7 @@ type mockTrafficShaper struct{} // by the provided channel ID may have external mechanisms that would // allow it to carry out the payment. func (*mockTrafficShaper) ShouldHandleTraffic(_ lnwire.ShortChannelID, - _ fn.Option[tlv.Blob]) (bool, error) { + _, _ fn.Option[tlv.Blob]) (bool, error) { return true, nil }