Skip to content

Commit 87a19b8

Browse files
committed
xpay: refuse request to pay 0msat.
Signed-off-by: Rusty Russell <[email protected]> Changelog-Fixed: JSON-RPC: `xpay` will refuse to make a 0msat payment (0msat invoice, partial payment, or manually-set on amountless invoice). Fixes: #8016
1 parent b871ea0 commit 87a19b8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

plugins/xpay/xpay.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,13 @@ static struct command_result *json_xpay_core(struct command *cmd,
15061506
if (msat)
15071507
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
15081508
"Cannot override amount for bolt12 invoices");
1509+
/* FIXME: This is actually spec legal, since invoice_amount is
1510+
* the *minumum* it will accept. We could change this to
1511+
* 1msat if required. */
1512+
if (amount_msat_is_zero(payment->full_amount))
1513+
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1514+
"Invalid bolt12 invoice with zero amount");
1515+
15091516
payment->route_hints = NULL;
15101517
payment->payment_secret = NULL;
15111518
payment->payment_metadata = NULL;
@@ -1572,6 +1579,9 @@ static struct command_result *json_xpay_core(struct command *cmd,
15721579
else
15731580
payment->full_amount = *msat;
15741581

1582+
if (amount_msat_is_zero(payment->full_amount))
1583+
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1584+
"Cannot pay bolt11 invoice with zero amount");
15751585
invexpiry = b11->timestamp + b11->expiry;
15761586
}
15771587

@@ -1587,6 +1597,9 @@ static struct command_result *json_xpay_core(struct command *cmd,
15871597
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
15881598
"partial_msat must be less or equal to total amount %s",
15891599
fmt_amount_msat(tmpctx, payment->full_amount));
1600+
if (amount_msat_is_zero(payment->amount))
1601+
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1602+
"partial_msat must be non-zero");
15901603
} else {
15911604
payment->amount = payment->full_amount;
15921605
}

0 commit comments

Comments
 (0)