From d0ef248ae2ee1249be5459fec9ee2cb0a66aa707 Mon Sep 17 00:00:00 2001 From: George Tsagkarelis Date: Tue, 8 Apr 2025 19:51:29 +0200 Subject: [PATCH] htlcswitch: add HtlcView as PaymentBandwidth argument In order to get more precise bandwidth reports, we also need to provide this method with the latest htlc view. Since aux data is committed to in the channel commitment, some uncommited HTLCs may not be accounted for, so we need to manually provide them via the HTLC view. --- htlcswitch/interfaces.go | 5 +++-- htlcswitch/link.go | 1 + routing/bandwidth_test.go | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/htlcswitch/interfaces.go b/htlcswitch/interfaces.go index 30a336085..786788e09 100644 --- a/htlcswitch/interfaces.go +++ b/htlcswitch/interfaces.go @@ -10,6 +10,7 @@ import ( "github.com/lightningnetwork/lnd/graph/db/models" "github.com/lightningnetwork/lnd/invoices" "github.com/lightningnetwork/lnd/lntypes" + "github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet/chainfee" "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/record" @@ -516,8 +517,8 @@ type AuxTrafficShaper interface { // is a custom channel that should be handled by the traffic shaper, the // ShouldHandleTraffic method should be called first. PaymentBandwidth(htlcBlob, commitmentBlob fn.Option[tlv.Blob], - linkBandwidth, - htlcAmt lnwire.MilliSatoshi) (lnwire.MilliSatoshi, error) + linkBandwidth, htlcAmt lnwire.MilliSatoshi, + htlcView lnwallet.AuxHtlcView) (lnwire.MilliSatoshi, error) // IsCustomHTLC returns true if the HTLC carries the set of relevant // custom records to put it under the purview of the traffic shaper, diff --git a/htlcswitch/link.go b/htlcswitch/link.go index ec26b0918..bddf8d95e 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -3505,6 +3505,7 @@ func (l *channelLink) AuxBandwidth(amount lnwire.MilliSatoshi, commitmentBlob := l.CommitmentCustomBlob() auxBandwidth, err := ts.PaymentBandwidth( htlcBlob, commitmentBlob, l.Bandwidth(), amount, + l.channel.FetchLatestAuxHTLCView(), ) if err != nil { return fn.Err[OptionalBandwidth](fmt.Errorf("failed to get "+ diff --git a/routing/bandwidth_test.go b/routing/bandwidth_test.go index 259f347ba..726275a6c 100644 --- a/routing/bandwidth_test.go +++ b/routing/bandwidth_test.go @@ -7,6 +7,7 @@ import ( "github.com/go-errors/errors" "github.com/lightningnetwork/lnd/fn/v2" "github.com/lightningnetwork/lnd/htlcswitch" + "github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/tlv" "github.com/stretchr/testify/require" @@ -150,7 +151,8 @@ func (*mockTrafficShaper) ShouldHandleTraffic(_ lnwire.ShortChannelID, // is a custom channel that should be handled by the traffic shaper, the // HandleTraffic method should be called first. func (*mockTrafficShaper) PaymentBandwidth(_, _ fn.Option[tlv.Blob], - linkBandwidth, _ lnwire.MilliSatoshi) (lnwire.MilliSatoshi, error) { + linkBandwidth, _ lnwire.MilliSatoshi, + _ lnwallet.AuxHtlcView) (lnwire.MilliSatoshi, error) { return linkBandwidth, nil }