Browse Source

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>
travis-debug
Rusty Russell 5 years ago
committed by Christian Decker
parent
commit
edab0df611
  1. 18
      lightningd/pay.c
  2. 6
      tests/test_pay.py

18
lightningd/pay.c

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

6
tests/test_pay.py

@ -2593,8 +2593,8 @@ def test_partial_payment(node_factory, bitcoind, executor):
paysecret = l4.rpc.decodepay(inv['bolt11'])['payment_secret'] paysecret = l4.rpc.decodepay(inv['bolt11'])['payment_secret']
# Separate routes for each part of the payment. # Separate routes for each part of the payment.
r134 = l1.rpc.getroute(l4.info['id'], 500, 1, exclude=[scid24 + '/0', scid24 + '/1'])['route'] r134 = l1.rpc.getroute(l4.info['id'], 501, 1, exclude=[scid24 + '/0', scid24 + '/1'])['route']
r124 = l1.rpc.getroute(l4.info['id'], 500, 1, exclude=[scid34 + '/0', scid34 + '/1'])['route'] r124 = l1.rpc.getroute(l4.info['id'], 499, 1, exclude=[scid34 + '/0', scid34 + '/1'])['route']
# These can happen in parallel. # These can happen in parallel.
l1.rpc.call('sendpay', [r134, inv['payment_hash'], None, 1000, inv['bolt11'], paysecret, 1]) l1.rpc.call('sendpay', [r134, inv['payment_hash'], None, 1000, inv['bolt11'], paysecret, 1])
@ -2638,7 +2638,7 @@ def test_partial_payment(node_factory, bitcoind, executor):
for i in range(2): for i in range(2):
line = l4.daemon.wait_for_log('print_htlc_onion.py: Got onion') line = l4.daemon.wait_for_log('print_htlc_onion.py: Got onion')
assert "'type': 'tlv'" in line 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 "'total_msat': '1000msat'" in line
assert "'payment_secret': '{}'".format(paysecret) in line assert "'payment_secret': '{}'".format(paysecret) in line

Loading…
Cancel
Save