Check that we track forwarded payments correctly. We wire up the network to have l1 as payment initiator, l2 as forwarded (the one we check) and l3-l5 as payment recipients. l3 accepts correctly, l4 rejects (because it doesn't know the payment hash) and l5 will keep the HTLC danglin
(node_factory, bitcoind)
| 1415 | |
| 1416 | |
| 1417 | def test_forward_stats(node_factory, bitcoind): |
| 1418 | """Check that we track forwarded payments correctly. |
| 1419 | |
| 1420 | We wire up the network to have l1 as payment initiator, l2 as |
| 1421 | forwarded (the one we check) and l3-l5 as payment recipients. l3 |
| 1422 | accepts correctly, l4 rejects (because it doesn't know the payment |
| 1423 | hash) and l5 will keep the HTLC dangling by disconnecting. |
| 1424 | |
| 1425 | """ |
| 1426 | amount = 10**5 |
| 1427 | l1, l2, l3, l4, l5 = node_factory.get_nodes(5, opts=[{}] * 4 + [{'may_fail': True}]) |
| 1428 | node_factory.join_nodes([l1, l2, l3], wait_for_announce=False) |
| 1429 | l2.openchannel(l4, 10**6, wait_for_announce=False) |
| 1430 | l2.openchannel(l5, 10**6, wait_for_announce=False) |
| 1431 | |
| 1432 | mine_funding_to_announce(bitcoind, [l1, l2, l3, l4, l5]) |
| 1433 | |
| 1434 | wait_for(lambda: len(l1.rpc.listchannels()['channels']) == 8) |
| 1435 | |
| 1436 | inv = l3.rpc.invoice(amount, "first", "desc") |
| 1437 | payment_hash = inv['payment_hash'] |
| 1438 | route = l1.single_route(l3.info['id'], amount) |
| 1439 | |
| 1440 | l1.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret']) |
| 1441 | l1.rpc.waitsendpay(payment_hash) |
| 1442 | |
| 1443 | # l4 rejects since it doesn't know the payment_hash |
| 1444 | route = l1.single_route(l4.info['id'], amount) |
| 1445 | payment_hash = "F" * 64 |
| 1446 | with pytest.raises(RpcError): |
| 1447 | l1.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret']) |
| 1448 | l1.rpc.waitsendpay(payment_hash) |
| 1449 | |
| 1450 | # l5 will hold the HTLC hostage. |
| 1451 | l5.rpc.dev_ignore_htlcs(id=l2.info['id'], ignore=True) |
| 1452 | route = l1.single_route(l5.info['id'], amount) |
| 1453 | inv = l5.rpc.invoice(amount, "first", "desc") |
| 1454 | payment_hash = inv['payment_hash'] |
| 1455 | l1.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret']) |
| 1456 | |
| 1457 | l5.daemon.wait_for_log(r'their htlc .* dev_ignore_htlcs') |
| 1458 | |
| 1459 | # Select all forwardings, ordered by htlc_id to ensure the order |
| 1460 | # matches below |
| 1461 | forwardings = l2.db_query("SELECT *, in_msatoshi - out_msatoshi as fee " |
| 1462 | "FROM forwards " |
| 1463 | "ORDER BY in_htlc_id;") |
| 1464 | assert(len(forwardings) == 3) |
| 1465 | states = [f['state'] for f in forwardings] |
| 1466 | assert(states == [1, 2, 0]) # settled, failed, offered |
| 1467 | |
| 1468 | inchan = l2.rpc.listpeerchannels(l1.info['id'])['channels'][0] |
| 1469 | outchan = l2.rpc.listpeerchannels(l3.info['id'])['channels'][0] |
| 1470 | |
| 1471 | # Check that we correctly account channel changes |
| 1472 | assert inchan['in_payments_offered'] == 3 |
| 1473 | assert inchan['in_payments_fulfilled'] == 1 |
| 1474 | assert inchan['in_offered_msat'] >= Millisatoshi(3 * amount) |
nothing calls this directly
no test coverage detected