From 4ce015de6096dbae1e928cb9a926bb2abc620c5c Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Wed, 4 Dec 2024 15:09:35 +0100 Subject: [PATCH] tapchannel: also check local buy quotes in bandwidth check 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. --- tapchannel/aux_traffic_shaper.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tapchannel/aux_traffic_shaper.go b/tapchannel/aux_traffic_shaper.go index a22d908fd..5de385d5d 100644 --- a/tapchannel/aux_traffic_shaper.go +++ b/tapchannel/aux_traffic_shaper.go @@ -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()) } @@ -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