Skip to content

Commit

Permalink
(fixup)tapchannel: conditionally check linkbandwidth against htlcAmt …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
GeorgeTsagk committed Sep 18, 2024
1 parent c9909ea commit ed13ed7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
3 changes: 2 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,8 @@ func (s *Server) HandleTraffic(cid lnwire.ShortChannelID,
//
// NOTE: This method is part of the routing.TlvTrafficShaper interface.
func (s *Server) PaymentBandwidth(htlcBlob, commitmentBlob lfn.Option[tlv.Blob],
linkBandwidth, htlcAmt lnwire.MilliSatoshi) (lnwire.MilliSatoshi, error) {
linkBandwidth,
htlcAmt lnwire.MilliSatoshi) (lnwire.MilliSatoshi, error) {

srvrLog.Debugf("PaymentBandwidth called, htlcBlob=%v, "+
"commitmentBlob=%v", spew.Sdump(htlcBlob),
Expand Down
27 changes: 18 additions & 9 deletions tapchannel/aux_traffic_shaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ func (s *AuxTrafficShaper) HandleTraffic(_ lnwire.ShortChannelID,
// should be handled by the traffic shaper, the HandleTraffic method should be
// called first.
func (s *AuxTrafficShaper) PaymentBandwidth(htlcBlob,
commitmentBlob lfn.Option[tlv.Blob],
linkBandwidth, htlcAmt lnwire.MilliSatoshi) (lnwire.MilliSatoshi, error) {
commitmentBlob lfn.Option[tlv.Blob], linkBandwidth,
htlcAmt lnwire.MilliSatoshi) (lnwire.MilliSatoshi, error) {

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

// Check if the current link bandwidth can afford sending out the htlc
// amount without dipping into the channel reserve. If it goes below the
// reserve, we report zero bandwdith as we cannot push the htlc amount.
if linkBandwidth < htlcAmt {
return 0, nil
}

commitment, err := cmsg.DecodeCommitment(commitmentBytes)
if err != nil {
return 0, fmt.Errorf("error decoding commitment blob: %w", err)
Expand All @@ -190,6 +183,14 @@ func (s *AuxTrafficShaper) PaymentBandwidth(htlcBlob,
// the amount.
htlcAssetAmount := htlc.Amounts.Val.Sum()
if htlcAssetAmount != 0 && htlcAssetAmount <= localBalance {
// Check if the current link bandwidth can afford sending out
// the htlc amount without dipping into the channel reserve. If
// it goes below the reserve, we report zero bandwdith as we
// cannot push the htlc amount.
if linkBandwidth < htlcAmt {
return 0, nil
}

// We signal "infinite" bandwidth by returning a very high
// value (number of Satoshis ever in existence), since we might
// not have a quote available to know what the asset amount
Expand Down Expand Up @@ -219,6 +220,14 @@ func (s *AuxTrafficShaper) PaymentBandwidth(htlcBlob,

mSatPerAssetUnit := quote.BidPrice

// At this point we have acquired what we need to express the asset
// bandwidth expressed in satoshis. Before we return the result, we need
// to check if the link bandwidth can afford sending a non-dust htlc to
// the other side.
if linkBandwidth < minHtlcAmt {
return 0, nil
}

// The available balance is the local asset unit expressed in
// milli-satoshis.
return lnwire.MilliSatoshi(localBalance) * mSatPerAssetUnit, nil
Expand Down

0 comments on commit ed13ed7

Please sign in to comment.