Skip to content

Commit ed13ed7

Browse files
committed
(fixup)tapchannel: conditionally check linkbandwidth against htlcAmt in PaymentBandwidth
Previously we would always perform a check between htlcAmt and link bandwidth in the PaymentBandwidth hook. This would not work as for RFQ payments the htlcAmt passed to this function would be the overall translated asset value, which could easily exceed the remaining link bandwidth expressed in sats. We now perform two distinct htlc budget checks, once in the keysend path and once in the RFQ path.
1 parent c9909ea commit ed13ed7

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

server.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,8 @@ func (s *Server) HandleTraffic(cid lnwire.ShortChannelID,
990990
//
991991
// NOTE: This method is part of the routing.TlvTrafficShaper interface.
992992
func (s *Server) PaymentBandwidth(htlcBlob, commitmentBlob lfn.Option[tlv.Blob],
993-
linkBandwidth, htlcAmt lnwire.MilliSatoshi) (lnwire.MilliSatoshi, error) {
993+
linkBandwidth,
994+
htlcAmt lnwire.MilliSatoshi) (lnwire.MilliSatoshi, error) {
994995

995996
srvrLog.Debugf("PaymentBandwidth called, htlcBlob=%v, "+
996997
"commitmentBlob=%v", spew.Sdump(htlcBlob),

tapchannel/aux_traffic_shaper.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ func (s *AuxTrafficShaper) HandleTraffic(_ lnwire.ShortChannelID,
120120
// should be handled by the traffic shaper, the HandleTraffic method should be
121121
// called first.
122122
func (s *AuxTrafficShaper) PaymentBandwidth(htlcBlob,
123-
commitmentBlob lfn.Option[tlv.Blob],
124-
linkBandwidth, htlcAmt lnwire.MilliSatoshi) (lnwire.MilliSatoshi, error) {
123+
commitmentBlob lfn.Option[tlv.Blob], linkBandwidth,
124+
htlcAmt lnwire.MilliSatoshi) (lnwire.MilliSatoshi, error) {
125125

126126
// If the commitment or HTLC blob is not set, we don't have any
127127
// information about the channel and cannot determine the available
@@ -162,13 +162,6 @@ func (s *AuxTrafficShaper) PaymentBandwidth(htlcBlob,
162162
htlcAmt = minHtlcAmt
163163
}
164164

165-
// Check if the current link bandwidth can afford sending out the htlc
166-
// amount without dipping into the channel reserve. If it goes below the
167-
// reserve, we report zero bandwdith as we cannot push the htlc amount.
168-
if linkBandwidth < htlcAmt {
169-
return 0, nil
170-
}
171-
172165
commitment, err := cmsg.DecodeCommitment(commitmentBytes)
173166
if err != nil {
174167
return 0, fmt.Errorf("error decoding commitment blob: %w", err)
@@ -190,6 +183,14 @@ func (s *AuxTrafficShaper) PaymentBandwidth(htlcBlob,
190183
// the amount.
191184
htlcAssetAmount := htlc.Amounts.Val.Sum()
192185
if htlcAssetAmount != 0 && htlcAssetAmount <= localBalance {
186+
// Check if the current link bandwidth can afford sending out
187+
// the htlc amount without dipping into the channel reserve. If
188+
// it goes below the reserve, we report zero bandwdith as we
189+
// cannot push the htlc amount.
190+
if linkBandwidth < htlcAmt {
191+
return 0, nil
192+
}
193+
193194
// We signal "infinite" bandwidth by returning a very high
194195
// value (number of Satoshis ever in existence), since we might
195196
// not have a quote available to know what the asset amount
@@ -219,6 +220,14 @@ func (s *AuxTrafficShaper) PaymentBandwidth(htlcBlob,
219220

220221
mSatPerAssetUnit := quote.BidPrice
221222

223+
// At this point we have acquired what we need to express the asset
224+
// bandwidth expressed in satoshis. Before we return the result, we need
225+
// to check if the link bandwidth can afford sending a non-dust htlc to
226+
// the other side.
227+
if linkBandwidth < minHtlcAmt {
228+
return 0, nil
229+
}
230+
222231
// The available balance is the local asset unit expressed in
223232
// milli-satoshis.
224233
return lnwire.MilliSatoshi(localBalance) * mSatPerAssetUnit, nil

0 commit comments

Comments
 (0)