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 17, 2024
1 parent 1fbefbc commit a875044
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions tapchannel/aux_traffic_shaper.go
Original file line number Diff line number Diff line change
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 Down Expand Up @@ -196,6 +189,14 @@ func (s *AuxTrafficShaper) PaymentBandwidth(htlcBlob,
// means in terms of satoshis. But the satoshi amount doesn't
// matter too much here, we just want to signal that this
// channel _does_ have available bandwidth.

// 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
}

return lnwire.NewMSatFromSatoshis(btcutil.MaxSatoshi), nil
}

Expand All @@ -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 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 a875044

Please sign in to comment.