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

Function test_pay_retry

tests/test_pay.py:1775–1853  ·  view source on GitHub ↗

Make sure pay command retries properly.

(node_factory, bitcoind, executor, chainparams)

Source from the content-addressed store, hash-verified

1773
1774@pytest.mark.slow_test
1775def test_pay_retry(node_factory, bitcoind, executor, chainparams):
1776 """Make sure pay command retries properly. """
1777
1778 def exhaust_channel(opener, peer, scid, already_spent=0):
1779 """Spend all available capacity (10^6 - 1%) of channel
1780 """
1781 chan = only_one(opener.rpc.listpeerchannels(peer.info['id'])["channels"])
1782 maxpay = chan['spendable_msat']
1783 lbl = ''.join(random.choice(string.ascii_letters) for _ in range(20))
1784 inv = peer.rpc.invoice(maxpay, lbl, "exhaust_channel")
1785 routestep = {
1786 'amount_msat': maxpay,
1787 'id': peer.info['id'],
1788 'delay': 10,
1789 'channel': scid
1790 }
1791 opener.rpc.sendpay([routestep], inv['payment_hash'], payment_secret=inv['payment_secret'])
1792 opener.rpc.waitsendpay(inv['payment_hash'])
1793
1794 # We connect every node to l5; in a line and individually.
1795 # Keep fixed fees so we can easily calculate exhaustion
1796 l1, l2, l3, l4, l5 = node_factory.line_graph(5, fundchannel=False,
1797 opts={'feerates': (7500, 7500, 7500, 7500), 'disable-mpp': None})
1798
1799 # scid12
1800 l1.fundchannel(l2, 10**6, wait_for_active=False)
1801 # scid23
1802 l2.fundchannel(l3, 10**6, wait_for_active=False)
1803 # scid34
1804 l3.fundchannel(l4, 10**6, wait_for_active=False)
1805 scid45, _ = l4.fundchannel(l5, 10**6, wait_for_active=False)
1806
1807 l1.rpc.connect(l5.info['id'], 'localhost', l5.port)
1808 scid15, _ = l1.fundchannel(l5, 10**6, wait_for_active=False)
1809 l2.rpc.connect(l5.info['id'], 'localhost', l5.port)
1810 scid25, _ = l2.fundchannel(l5, 10**6, wait_for_active=False)
1811 l3.rpc.connect(l5.info['id'], 'localhost', l5.port)
1812 scid35, _ = l3.fundchannel(l5, 10**6, wait_for_active=False)
1813
1814 # Make sure l1 sees all 7 channels
1815 mine_funding_to_announce(bitcoind, [l1, l2, l3, l4, l5])
1816 wait_for(lambda: len(l1.rpc.listchannels()['channels']) == 14)
1817
1818 # Exhaust shortcut channels one at a time, to force retries.
1819 exhaust_channel(l1, l5, scid15)
1820 exhaust_channel(l2, l5, scid25)
1821 exhaust_channel(l3, l5, scid35)
1822
1823 def listpays_nofail(b11):
1824 while True:
1825 pays = l1.rpc.listpays(b11)['pays']
1826 if len(pays) != 0:
1827 if only_one(pays)['status'] == 'complete':
1828 return
1829 assert only_one(pays)['status'] != 'failed'
1830
1831 inv = l5.rpc.invoice(10**8, 'test_retry', 'test_retry')
1832

Callers

nothing calls this directly

Calls 9

mine_funding_to_announceFunction · 0.90
wait_forFunction · 0.90
exhaust_channelFunction · 0.85
line_graphMethod · 0.80
fundchannelMethod · 0.45
connectMethod · 0.45
listchannelsMethod · 0.45
invoiceMethod · 0.45
dev_payMethod · 0.45

Tested by

no test coverage detected