Skip to content

Commit fb6c014

Browse files
committed
tapchannel: fail early if we'd send 0 assets
Fixes #1006. In this commit we make sure that we'll never end up attempting to send a zero asset amount HTLC, which would then fail further down the line. A zero amount can happen if the resolution of asset unit to satoshis is insufficient and one unit costs more than the satoshi amount that should be represented in the HTLC. The main mitigation for this is on the issuer side that they make sure the decimal display value is high enough and one asset unit represents a fraction of a cent (and is therefore close to being equal to one satoshi).
1 parent e1e1405 commit fb6c014

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tapchannel/aux_traffic_shaper.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,17 @@ func (s *AuxTrafficShaper) ProduceHtlcExtraData(totalAmount lnwire.MilliSatoshi,
256256
return 0, nil, fmt.Errorf("quote has no asset ID")
257257
}
258258

259+
// If the number of asset units to send is zero due to integer division
260+
// and insufficient asset unit precision vs. satoshis, we cannot send
261+
// this payment. This should only happen if the amount to pay is very
262+
// small (small satoshi or sub satoshi total value) or the price oracle
263+
// has given a very high price for the asset.
264+
if numAssetUnits == 0 {
265+
return 0, nil, fmt.Errorf("asset unit price (%d mSat per "+
266+
"asset unit) too high to represent HTLC value of %v",
267+
mSatPerAssetUnit, totalAmount)
268+
}
269+
259270
log.Debugf("Producing HTLC extra data for RFQ ID %x (SCID %d): "+
260271
"asset ID %x, asset amount %d", rfqID[:], rfqID.Scid(),
261272
quote.Request.AssetID[:], numAssetUnits)

0 commit comments

Comments
 (0)