Skip to content

Commit

Permalink
lightningd: fix spurious "more than twice final" error.
Browse files Browse the repository at this point in the history
Bastien TEINTURIER <[email protected]> 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 <[email protected]>
  • Loading branch information
rustyrussell committed Dec 12, 2019
1 parent 2b4ca09 commit 207ae69
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions lightningd/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
6 changes: 3 additions & 3 deletions tests/test_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -2593,8 +2593,8 @@ def test_partial_payment(node_factory, bitcoind, executor):
paysecret = l4.rpc.decodepay(inv['bolt11'])['payment_secret']

# Separate routes for each part of the payment.
r134 = l1.rpc.getroute(l4.info['id'], 500, 1, exclude=[scid24 + '/0', scid24 + '/1'])['route']
r124 = l1.rpc.getroute(l4.info['id'], 500, 1, exclude=[scid34 + '/0', scid34 + '/1'])['route']
r134 = l1.rpc.getroute(l4.info['id'], 501, 1, exclude=[scid24 + '/0', scid24 + '/1'])['route']
r124 = l1.rpc.getroute(l4.info['id'], 499, 1, exclude=[scid34 + '/0', scid34 + '/1'])['route']

# These can happen in parallel.
l1.rpc.call('sendpay', [r134, inv['payment_hash'], None, 1000, inv['bolt11'], paysecret, 1])
Expand Down Expand Up @@ -2638,7 +2638,7 @@ def test_partial_payment(node_factory, bitcoind, executor):
for i in range(2):
line = l4.daemon.wait_for_log('print_htlc_onion.py: Got onion')
assert "'type': 'tlv'" in line
assert "'forward_amount': '500msat'" in line
assert "'forward_amount': '499msat'" in line or "'forward_amount': '501msat'" in line
assert "'total_msat': '1000msat'" in line
assert "'payment_secret': '{}'".format(paysecret) in line

Expand Down

0 comments on commit 207ae69

Please sign in to comment.