keysend: Add error when trying to send to self

There is little point in faking a self-payment, but we should also not
crash :-)

Fixes #4438

Changelog-Fixed: keysend: Keysend returns an error when a self-payment is requested
This commit is contained in:
Christian Decker
2021-03-17 12:30:06 +01:00
committed by Rusty Russell
parent 3a031bf0e3
commit 6cfb72ea1b
2 changed files with 11 additions and 1 deletions

View File

@@ -171,13 +171,19 @@ static struct command_result *json_keysend(struct command *cmd, const char *buf,
p->deadline = timeabs_add(time_now(), time_from_sec(*retryfor));
p->getroute->riskfactorppm = 10000000;
if (node_id_eq(&my_id, p->destination)) {
return command_fail(
cmd, JSONRPC2_INVALID_PARAMS,
"We are the destination. Keysend cannot be used to send funds to yourself");
}
if (!amount_msat_fee(&p->constraints.fee_budget, p->amount, 0,
*maxfee_pct_millionths / 100)) {
tal_free(p);
return command_fail(
cmd, JSONRPC2_INVALID_PARAMS,
"Overflow when computing fee budget, fee rate too high.");
}
p->constraints.cltv_budget = *maxdelay;
payment_mod_exemptfee_get_data(p)->amount = *exemptfee;