From 4ad84627e108e1edf9835af39ac45c235274bdbd Mon Sep 17 00:00:00 2001 From: George Tsagkarelis Date: Thu, 26 Jun 2025 12:11:56 +0200 Subject: [PATCH] htlcswitch+routing: PaymentBandwidth accepts channel peer pubkey argument --- htlcswitch/interfaces.go | 3 ++- htlcswitch/link.go | 11 ++++++++++- routing/bandwidth_test.go | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/htlcswitch/interfaces.go b/htlcswitch/interfaces.go index ad7b1b097..4739afff6 100644 --- a/htlcswitch/interfaces.go +++ b/htlcswitch/interfaces.go @@ -522,7 +522,8 @@ type AuxTrafficShaper interface { PaymentBandwidth(fundingBlob, htlcBlob, commitmentBlob fn.Option[tlv.Blob], linkBandwidth, htlcAmt lnwire.MilliSatoshi, - htlcView lnwallet.AuxHtlcView) (lnwire.MilliSatoshi, error) + htlcView lnwallet.AuxHtlcView, + peer route.Vertex) (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 d2bc4f4bf..3aa47caf3 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -31,6 +31,7 @@ import ( "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/queue" "github.com/lightningnetwork/lnd/record" + "github.com/lightningnetwork/lnd/routing/route" "github.com/lightningnetwork/lnd/ticker" "github.com/lightningnetwork/lnd/tlv" ) @@ -3503,11 +3504,19 @@ func (l *channelLink) AuxBandwidth(amount lnwire.MilliSatoshi, }) } + peerBytes := l.cfg.Peer.PubKey() + + peer, err := route.NewVertexFromBytes(peerBytes[:]) + if err != nil { + return fn.Err[OptionalBandwidth](fmt.Errorf("failed to decode "+ + "peer pub key: %v", err)) + } + // Ask for a specific bandwidth to be used for the channel. commitmentBlob := l.CommitmentCustomBlob() auxBandwidth, err := ts.PaymentBandwidth( fundingBlob, htlcBlob, commitmentBlob, l.Bandwidth(), amount, - l.channel.FetchLatestAuxHTLCView(), + l.channel.FetchLatestAuxHTLCView(), peer, ) 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 6ee1f1f64..b7f6e3f13 100644 --- a/routing/bandwidth_test.go +++ b/routing/bandwidth_test.go @@ -153,7 +153,7 @@ func (*mockTrafficShaper) ShouldHandleTraffic(_ lnwire.ShortChannelID, // ShouldHandleTraffic method should be called first. func (*mockTrafficShaper) PaymentBandwidth(_, _, _ fn.Option[tlv.Blob], linkBandwidth, _ lnwire.MilliSatoshi, - _ lnwallet.AuxHtlcView) (lnwire.MilliSatoshi, error) { + _ lnwallet.AuxHtlcView, _ route.Vertex) (lnwire.MilliSatoshi, error) { return linkBandwidth, nil }