Skip to content

Commit 76212e2

Browse files
committed
rpcserver: addinvoice checks if final quote satisfies msat amt
As a final sanity check, let's check if the actual max routable amount of the quote can satisfy the msat value of the invoice.
1 parent 0f48be4 commit 76212e2

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

rpcserver.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7808,12 +7808,27 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
78087808

78097809
invUnits := req.AssetAmount
78107810

7811-
// If the invoice was created over a satoshi amount, we need to
7812-
// calculate the units.
78137811
if satsMode {
7812+
// If the invoice was created over a satoshi amount, we need to
7813+
// calculate the units.
78147814
invUnits = rfqmath.MilliSatoshiToUnits(
78157815
amtMsat, *askAssetRate,
78167816
).ToUint64()
7817+
7818+
// Now let's see if the negotiated quote can actually route the
7819+
// amount we need in msat.
7820+
maxFixedUnits := rfqmath.NewBigIntFixedPoint(
7821+
acceptedQuote.AssetMaxAmount, 0,
7822+
)
7823+
maxRoutableMsat := rfqmath.UnitsToMilliSatoshi(
7824+
maxFixedUnits, *askAssetRate,
7825+
)
7826+
7827+
if maxRoutableMsat <= amtMsat {
7828+
return nil, fmt.Errorf("cannot create invoice for %v "+
7829+
"msat, max routable amount is %v msat", amtMsat,
7830+
maxRoutableMsat)
7831+
}
78177832
}
78187833

78197834
// If the invoice is for an asset unit amount smaller than the minimal

0 commit comments

Comments
 (0)