Skip to content

Commit c5d356e

Browse files
committed
rfq: add PaymentMaxAmt check to AssetPurchasePolicy
This commit adds a check to ensure that the outgoing HTLC `msat` amount does not exceed the `PaymentMaxAmt` specified in the RFQ quote.
1 parent 9e8c663 commit c5d356e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

rfq/order.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ type AssetPurchasePolicy struct {
248248
// BidAssetRate is the quote's asset to BTC conversion rate.
249249
BidAssetRate rfqmath.BigIntFixedPoint
250250

251+
// PaymentMaxAmt is the maximum agreed BTC payment.
252+
PaymentMaxAmt lnwire.MilliSatoshi
253+
251254
// expiry is the policy's expiry unix timestamp in seconds after which
252255
// the policy is no longer valid.
253256
expiry uint64
@@ -260,6 +263,7 @@ func NewAssetPurchasePolicy(quote rfqmsg.SellAccept) *AssetPurchasePolicy {
260263
AssetSpecifier: quote.Request.AssetSpecifier,
261264
AcceptedQuoteId: quote.ID,
262265
BidAssetRate: quote.AssetRate,
266+
PaymentMaxAmt: quote.Request.PaymentMaxAmt,
263267
expiry: quote.Expiry,
264268
}
265269
}
@@ -308,6 +312,15 @@ func (c *AssetPurchasePolicy) CheckHtlcCompliance(
308312
assetAmt.String(), inboundAmountMSat)
309313
}
310314

315+
// Ensure that the outbound HTLC amount is less than the maximum agreed
316+
// BTC payment.
317+
if htlc.AmountOutMsat > c.PaymentMaxAmt {
318+
return fmt.Errorf("htlc out amount is more than the maximum "+
319+
"agreed BTC payment (htlc_out_msat=%d, "+
320+
"payment_max_amt=%d)", htlc.AmountOutMsat,
321+
c.PaymentMaxAmt)
322+
}
323+
311324
// Lastly, check to ensure that the policy has not expired.
312325
if time.Now().Unix() > int64(c.expiry) {
313326
return fmt.Errorf("policy has expired (expiry_unix_ts=%d)",

0 commit comments

Comments
 (0)