Skip to content

Commit a9790be

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 40aad27 commit a9790be

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
@@ -1502,6 +1502,13 @@ static struct command_result *json_xpay_core(struct command *cmd,
15021502
if (msat)
15031503
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
15041504
"Cannot override amount for bolt12 invoices");
1505+
/* FIXME: This is actually spec legal, since invoice_amount is
1506+
* the *minumum* it will accept. We could change this to
1507+
* 1msat if required. */
1508+
if (amount_msat_is_zero(payment->full_amount))
1509+
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1510+
"Invalid bolt12 invoice with zero amount");
1511+
15051512
payment->route_hints = NULL;
15061513
payment->payment_secret = NULL;
15071514
payment->payment_metadata = NULL;
@@ -1568,6 +1575,9 @@ static struct command_result *json_xpay_core(struct command *cmd,
15681575
else
15691576
payment->full_amount = *msat;
15701577

1578+
if (amount_msat_is_zero(payment->full_amount))
1579+
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1580+
"Cannot pay bolt11 invoice with zero amount");
15711581
invexpiry = b11->timestamp + b11->expiry;
15721582
}
15731583

@@ -1583,6 +1593,9 @@ static struct command_result *json_xpay_core(struct command *cmd,
15831593
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
15841594
"partial_msat must be less or equal to total amount %s",
15851595
fmt_amount_msat(tmpctx, payment->full_amount));
1596+
if (amount_msat_is_zero(payment->amount))
1597+
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1598+
"partial_msat must be non-zero");
15861599
} else {
15871600
payment->amount = payment->full_amount;
15881601
}

0 commit comments

Comments
 (0)