MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_pay_middle_fail

Function test_pay_middle_fail

tests/test_pay.py:5424–5464  ·  view source on GitHub ↗

Test the case where a HTLC is failed, but not on peer's side, then we go onchain

(node_factory, bitcoind, executor)

Source from the content-addressed store, hash-verified

5422
5423
5424def test_pay_middle_fail(node_factory, bitcoind, executor):
5425 """Test the case where a HTLC is failed, but not on peer's side, then
5426 we go onchain"""
5427 # Set feerates the same so we don't have update_fee interfering.
5428 # We want to disconnect on revoke-and-ack we send for failing htlc.
5429 l1, l2, l3 = node_factory.line_graph(3, wait_for_announce=True,
5430 opts=[{'feerates': (1500,) * 4},
5431 {'feerates': (1500,) * 4},
5432 {'feerates': (1500,) * 4,
5433 'disconnect': ['-WIRE_REVOKE_AND_ACK*2']}])
5434
5435 chanid12 = only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])['short_channel_id']
5436 chanid23 = only_one(l2.rpc.listpeerchannels(l3.info['id'])['channels'])['short_channel_id']
5437
5438 # Make a failing payment.
5439 route = [{'amount_msat': 1011,
5440 'id': l2.info['id'],
5441 'delay': 20,
5442 'channel': chanid12},
5443 {'amount_msat': 1000,
5444 'id': l3.info['id'],
5445 'delay': 10,
5446 'channel': chanid23}]
5447
5448 # Start payment, it will fail.
5449 l1.rpc.sendpay(route, payment_hash='00' * 32)
5450
5451 wait_for(lambda: only_one(l3.rpc.listpeers(l2.info['id'])['peers'])['connected'] is False)
5452
5453 # After this (cltv is actually +11, and we give it 1 block grace)
5454 # l2 will go onchain since HTLC is not resolved.
5455 bitcoind.generate_block(12)
5456 sync_blockheight(bitcoind, [l1, l2, l3])
5457 wait_for(lambda: only_one(l2.rpc.listpeerchannels(l3.info['id'])['channels'])['state'] == 'AWAITING_UNILATERAL')
5458
5459 # Three blocks and it will resolve the parent.
5460 bitcoind.generate_block(3, wait_for_mempool=1)
5461
5462 # And that will fail upstream
5463 with pytest.raises(RpcError, match=r'WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS'):
5464 l1.rpc.waitsendpay('00' * 32)
5465
5466
5467@unittest.skipIf(TEST_NETWORK != 'regtest', "Invoice is network specific")

Callers

nothing calls this directly

Calls 9

only_oneFunction · 0.90
wait_forFunction · 0.90
sync_blockheightFunction · 0.90
line_graphMethod · 0.80
listpeerchannelsMethod · 0.80
sendpayMethod · 0.80
generate_blockMethod · 0.80
waitsendpayMethod · 0.80
listpeersMethod · 0.45

Tested by

no test coverage detected