lightningd: fix spurious "more than twice final" error.

Bastien TEINTURIER <bastien@acinq.fr> writes:
> It looks like the split on c-lightning side is quite limited at the moment:
> the only option is to split a payment in exactly its two halves,
> otherwise I get rejected because of the rule of overpaying more than
> twice the amount?

We only tested exactly two equal-size payments; indeed, our finalhop
test was backwards.  We only complain if the final hop pays more than
twice msat (technically, this test is still too loose for mpp: the
spec says we should sum to the exact amount).

Reported-by: @t-bast
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2019-12-12 10:48:27 +10:30
committed by Christian Decker
parent 7fb4efd98a
commit edab0df611
2 changed files with 12 additions and 12 deletions

View File

@@ -1292,26 +1292,26 @@ static struct command_result *json_sendpay(struct command *cmd,
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Must specify msatoshi with partid");
/* if not: finalhop.amount <= 2 * msatoshi, fail. */
/* finalhop.amount > 2 * msatoshi, fail. */
if (msat) {
struct amount_msat limit = route[routetok->size-1].amount;
struct amount_msat limit;
if (!amount_msat_add(&limit, limit, limit))
if (!amount_msat_add(&limit, *msat, *msat))
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Unbelievable final amount %s",
"Unbelievable msatoshi %s",
type_to_string(tmpctx,
struct amount_msat,
&route[routetok->size-1].amount));
msat));
if (amount_msat_greater(*msat, limit))
if (amount_msat_greater(route[routetok->size-1].amount, limit))
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"msatoshi %s more than twice final %s",
"final %s more than twice msatoshi %s",
type_to_string(tmpctx,
struct amount_msat,
msat),
&route[routetok->size-1].amount),
type_to_string(tmpctx,
struct amount_msat,
&route[routetok->size-1].amount));
msat));
}
/* It's easier to leave this in the API, then ignore it here. */