Skip to content

Commit 4ce015d

Browse files
committed
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.
1 parent de1b916 commit 4ce015d

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

tapchannel/aux_traffic_shaper.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,21 @@ func (s *AuxTrafficShaper) PaymentBandwidth(htlcBlob,
213213
// up the accepted quote and determine the outgoing bandwidth in
214214
// satoshis based on the local asset balance.
215215
rfqID := htlc.RfqID.ValOpt().UnsafeFromSome()
216-
acceptedQuotes := s.cfg.RfqManager.PeerAcceptedSellQuotes()
217-
quote, ok := acceptedQuotes[rfqID.Scid()]
218-
if !ok {
216+
acceptedSellQuotes := s.cfg.RfqManager.PeerAcceptedSellQuotes()
217+
acceptedBuyQuotes := s.cfg.RfqManager.LocalAcceptedBuyQuotes()
218+
219+
sellQuote, isSellQuote := acceptedSellQuotes[rfqID.Scid()]
220+
buyQuote, isBuyQuote := acceptedBuyQuotes[rfqID.Scid()]
221+
222+
var rate rfqmsg.AssetRate
223+
switch {
224+
case isSellQuote:
225+
rate = sellQuote.AssetRate
226+
227+
case isBuyQuote:
228+
rate = buyQuote.AssetRate
229+
230+
default:
219231
return 0, fmt.Errorf("no accepted quote found for RFQ ID "+
220232
"%x (SCID %d)", rfqID[:], rfqID.Scid())
221233
}
@@ -224,7 +236,7 @@ func (s *AuxTrafficShaper) PaymentBandwidth(htlcBlob,
224236
// expressed in milli-satoshis.
225237
localBalanceFp := rfqmath.NewBigIntFixedPoint(localBalance, 0)
226238
availableBalanceMsat := rfqmath.UnitsToMilliSatoshi(
227-
localBalanceFp, quote.AssetRate.Rate,
239+
localBalanceFp, rate.Rate,
228240
)
229241

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

0 commit comments

Comments
 (0)