Skip to content

Commit 1ea6175

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 67b4d2e commit 1ea6175

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

tapchannel/aux_traffic_shaper.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
@@ -196,6 +189,14 @@ func (s *AuxTrafficShaper) PaymentBandwidth(htlcBlob,
196189
// means in terms of satoshis. But the satoshi amount doesn't
197190
// matter too much here, we just want to signal that this
198191
// channel _does_ have available bandwidth.
192+
193+
// Check if the current link bandwidth can afford sending out the htlc
194+
// amount without dipping into the channel reserve. If it goes below the
195+
// reserve, we report zero bandwdith as we cannot push the htlc amount.
196+
if linkBandwidth < htlcAmt {
197+
return 0, nil
198+
}
199+
199200
return lnwire.NewMSatFromSatoshis(btcutil.MaxSatoshi), nil
200201
}
201202

@@ -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 dust htlc to the
226+
// 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)