Skip to content

Commit

Permalink
rfq: add PaymentMaxAmt check to AssetPurchasePolicy
Browse files Browse the repository at this point in the history
This commit adds a check to ensure that the outgoing HTLC `msat` amount
does not exceed the `PaymentMaxAmt` specified in the RFQ quote.
  • Loading branch information
ffranr committed Nov 4, 2024
1 parent a70f2b7 commit 98080aa
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions rfq/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ type AssetPurchasePolicy struct {
// BidAssetRate is the quote's asset to BTC conversion rate.
BidAssetRate rfqmath.BigIntFixedPoint

// PaymentMaxAmt is the maximum agreed BTC payment.
PaymentMaxAmt lnwire.MilliSatoshi

// expiry is the policy's expiry unix timestamp in seconds after which
// the policy is no longer valid.
expiry uint64
Expand All @@ -260,6 +263,7 @@ func NewAssetPurchasePolicy(quote rfqmsg.SellAccept) *AssetPurchasePolicy {
AssetSpecifier: quote.Request.AssetSpecifier,
AcceptedQuoteId: quote.ID,
BidAssetRate: quote.AssetRate,
PaymentMaxAmt: quote.Request.PaymentMaxAmt,
expiry: quote.Expiry,
}
}
Expand Down Expand Up @@ -308,6 +312,15 @@ func (c *AssetPurchasePolicy) CheckHtlcCompliance(
assetAmt.String(), inboundAmountMSat)
}

// Ensure that the outbound HTLC amount is less than the maximum agreed
// BTC payment.
if htlc.AmountOutMsat > c.PaymentMaxAmt {
return fmt.Errorf("htlc out amount is more than the maximum "+
"agreed BTC payment (htlc_out_msat=%d, "+
"payment_max_amt=%d)", htlc.AmountOutMsat,
c.PaymentMaxAmt)
}

// Lastly, check to ensure that the policy has not expired.
if time.Now().Unix() > int64(c.expiry) {
return fmt.Errorf("policy has expired (expiry_unix_ts=%d)",
Expand Down

0 comments on commit 98080aa

Please sign in to comment.