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

Function test_fail_after_success

tests/test_xpay.py:706–757  ·  view source on GitHub ↗
(node_factory, bitcoind, executor, slow_mode)

Source from the content-addressed store, hash-verified

704
705@pytest.mark.parametrize("slow_mode", [False, True])
706def test_fail_after_success(node_factory, bitcoind, executor, slow_mode):
707 # l1 -> l2 -> l3 -> l5
708 # \-> l4 -/^
709 l1, l2, l3, l4, l5 = node_factory.get_nodes(5, opts=[{'xpay-slow-mode': slow_mode},
710 {},
711 {},
712 {'disconnect': ['-WIRE_UPDATE_FULFILL_HTLC']},
713 {}])
714 node_factory.join_nodes([l2, l3, l5])
715 node_factory.join_nodes([l2, l4, l5])
716
717 # Make sure l1 can see all paths.
718 node_factory.join_nodes([l1, l2])
719 bitcoind.generate_block(5)
720 wait_for(lambda: len(l1.rpc.listchannels()['channels']) == 10)
721
722 inv = l5.rpc.invoice(800000000, 'test_xpay_slow_mode', 'test_xpay_slow_mode', preimage='00' * 32)['bolt11']
723 fut = executor.submit(l1.rpc.xpay, invstring=inv, retry_for=0, dev_use_shadow=False)
724
725 # Part via l3 is fine. Part via l4 is stuck, so we kill l4 and mine
726 # blocks to make l2 force close.
727 l4.daemon.wait_for_log('dev_disconnect: -WIRE_UPDATE_FULFILL_HTLC')
728 l4.stop()
729
730 # Normally, we return as soon as first part succeeds.
731 if slow_mode is False:
732 assert fut.result(TIMEOUT) == {'payment_preimage': '00' * 32,
733 'amount_msat': 800000000,
734 'amount_sent_msat': 800016004,
735 'failed_parts': 0,
736 'successful_parts': 2}
737
738 # Time it out, l2 will collect it.
739 bitcoind.generate_block(13)
740 l2.daemon.wait_for_log('Peer permanent failure in CHANNELD_NORMAL: Offered HTLC 0 SENT_ADD_ACK_REVOCATION cltv 124 hit deadline')
741 bitcoind.generate_block(3, wait_for_mempool=1)
742
743 l1.daemon.wait_for_log(r"UNUSUAL.*Destination accepted partial payment, failed a part \(Error permanent_channel_failure for path ->033845802d25b4e074ccfd7cd8b339a41dc75bf9978a034800444b51d42b07799a->02287bfac8b99b35477ebe9334eede1e32b189e24644eb701c079614712331cec0->0258f3ff3e0853ccc09f6fe89823056d7c0c55c95fab97674df5e1ad97a72f6265, from 033845802d25b4e074ccfd7cd8b339a41dc75bf9978a034800444b51d42b07799a\)")
744 # Could be either way around, check both
745 line = l1.daemon.is_in_log(r"UNUSUAL.*Destination accepted partial payment, failed a part")
746 assert re.search(r'but accepted only .* of 800000000msat\. Winning\?!', line)
747
748 if slow_mode is True:
749 # Now it succeeds, but notes that it only sent one part!
750 res = fut.result(TIMEOUT)
751 # Some variation due to floating point.
752 assert res['amount_sent_msat'] < 800000000
753 assert res == {'payment_preimage': '00' * 32,
754 'amount_msat': 800000000,
755 'amount_sent_msat': res['amount_sent_msat'],
756 'failed_parts': 1,
757 'successful_parts': 1}
758
759
760def test_xpay_twohop_bug(node_factory, bitcoind):

Callers

nothing calls this directly

Calls 9

wait_forFunction · 0.90
get_nodesMethod · 0.80
join_nodesMethod · 0.80
generate_blockMethod · 0.80
wait_for_logMethod · 0.80
is_in_logMethod · 0.80
listchannelsMethod · 0.45
invoiceMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected