Skip to content

Commit dafd55e

Browse files
committed
rfq: fix precision issue in HTLC compliance check
Due to the integer nature of asset units, when converting to milli-satoshi and back, we might be off by a fraction of an asset unit when comparing to the milli-satoshi amount of an HTLC. We'll add a single asset unit to the reported inbound amount when checking in-out amount compliance to allow for those asset rounding imprecisions. In a real-world scenario where an asset has a decimal display value of 6, this would result in an imprecision of fractions of cents and be earned back by the spread on the actual conversion itself.
1 parent ee06af7 commit dafd55e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

rfq/order.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,13 @@ func (c *AssetPurchasePolicy) CheckHtlcCompliance(
297297
return fmt.Errorf("error summing asset balance: %w", err)
298298
}
299299

300+
// Due to rounding errors, we may slightly underreport the incoming
301+
// value of the asset. So we increase it by exactly one asset unit to
302+
// ensure that we do not reject the HTLC in the "inbound amount cannot
303+
// be less than outbound amount" check below.
304+
roundingCorrection := rfqmath.NewBigIntFromUint64(1)
305+
assetAmt = assetAmt.Add(roundingCorrection)
306+
300307
// Convert the inbound asset amount to millisatoshis and ensure that the
301308
// outgoing HTLC amount is not more than the inbound asset amount.
302309
assetAmtFp := new(rfqmath.BigIntFixedPoint).SetIntValue(assetAmt)

0 commit comments

Comments
 (0)