Skip to content

Commit

Permalink
tapchannel: also check local buy quotes in bandwidth check
Browse files Browse the repository at this point in the history
Because the traffic shaper is now also used for checking the bandwidth
when forwarding HTLCs to the final recipient, we also need to check our
local buy quotes for a quote with the given RFQ ID.
  • Loading branch information
guggero committed Dec 9, 2024
1 parent de1b916 commit 4ce015d
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions tapchannel/aux_traffic_shaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,21 @@ func (s *AuxTrafficShaper) PaymentBandwidth(htlcBlob,
// up the accepted quote and determine the outgoing bandwidth in
// satoshis based on the local asset balance.
rfqID := htlc.RfqID.ValOpt().UnsafeFromSome()
acceptedQuotes := s.cfg.RfqManager.PeerAcceptedSellQuotes()
quote, ok := acceptedQuotes[rfqID.Scid()]
if !ok {
acceptedSellQuotes := s.cfg.RfqManager.PeerAcceptedSellQuotes()
acceptedBuyQuotes := s.cfg.RfqManager.LocalAcceptedBuyQuotes()

sellQuote, isSellQuote := acceptedSellQuotes[rfqID.Scid()]
buyQuote, isBuyQuote := acceptedBuyQuotes[rfqID.Scid()]

var rate rfqmsg.AssetRate
switch {
case isSellQuote:
rate = sellQuote.AssetRate

case isBuyQuote:
rate = buyQuote.AssetRate

default:
return 0, fmt.Errorf("no accepted quote found for RFQ ID "+
"%x (SCID %d)", rfqID[:], rfqID.Scid())
}
Expand All @@ -224,7 +236,7 @@ func (s *AuxTrafficShaper) PaymentBandwidth(htlcBlob,
// expressed in milli-satoshis.
localBalanceFp := rfqmath.NewBigIntFixedPoint(localBalance, 0)
availableBalanceMsat := rfqmath.UnitsToMilliSatoshi(
localBalanceFp, quote.AssetRate.Rate,
localBalanceFp, rate.Rate,
)

// At this point we have acquired what we need to express the asset
Expand Down

0 comments on commit 4ce015d

Please sign in to comment.