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

Function test_pay_retry

tests/test_pay.py:1802–1880  ·  view source on GitHub ↗

Make sure pay command retries properly.

(node_factory, bitcoind, executor, chainparams)

Source from the content-addressed store, hash-verified

1800
1801@pytest.mark.slow_test
1802def test_pay_retry(node_factory, bitcoind, executor, chainparams):
1803 """Make sure pay command retries properly. """
1804
1805 def exhaust_channel(opener, peer, scid, already_spent=0):
1806 """Spend all available capacity (10^6 - 1%) of channel
1807 """
1808 chan = only_one(opener.rpc.listpeerchannels(peer.info['id'])["channels"])
1809 maxpay = chan['spendable_msat']
1810 lbl = ''.join(random.choice(string.ascii_letters) for _ in range(20))
1811 inv = peer.rpc.invoice(maxpay, lbl, "exhaust_channel")
1812 routestep = {
1813 'amount_msat': maxpay,
1814 'id': peer.info['id'],
1815 'delay': 10,
1816 'channel': scid
1817 }
1818 opener.rpc.sendpay([routestep], inv['payment_hash'], payment_secret=inv['payment_secret'])
1819 opener.rpc.waitsendpay(inv['payment_hash'])
1820
1821 # We connect every node to l5; in a line and individually.
1822 # Keep fixed fees so we can easily calculate exhaustion
1823 l1, l2, l3, l4, l5 = node_factory.line_graph(5, fundchannel=False,
1824 opts={'feerates': (7500, 7500, 7500, 7500), 'disable-mpp': None})
1825
1826 # scid12
1827 l1.fundchannel(l2, 10**6, wait_for_active=False)
1828 # scid23
1829 l2.fundchannel(l3, 10**6, wait_for_active=False)
1830 # scid34
1831 l3.fundchannel(l4, 10**6, wait_for_active=False)
1832 scid45, _ = l4.fundchannel(l5, 10**6, wait_for_active=False)
1833
1834 l1.rpc.connect(l5.info['id'], 'localhost', l5.port)
1835 scid15, _ = l1.fundchannel(l5, 10**6, wait_for_active=False)
1836 l2.rpc.connect(l5.info['id'], 'localhost', l5.port)
1837 scid25, _ = l2.fundchannel(l5, 10**6, wait_for_active=False)
1838 l3.rpc.connect(l5.info['id'], 'localhost', l5.port)
1839 scid35, _ = l3.fundchannel(l5, 10**6, wait_for_active=False)
1840
1841 # Make sure l1 sees all 7 channels
1842 mine_funding_to_announce(bitcoind, [l1, l2, l3, l4, l5])
1843 wait_for(lambda: len(l1.rpc.listchannels()['channels']) == 14)
1844
1845 # Exhaust shortcut channels one at a time, to force retries.
1846 exhaust_channel(l1, l5, scid15)
1847 exhaust_channel(l2, l5, scid25)
1848 exhaust_channel(l3, l5, scid35)
1849
1850 def listpays_nofail(b11):
1851 while True:
1852 pays = l1.rpc.listpays(b11)['pays']
1853 if len(pays) != 0:
1854 if only_one(pays)['status'] == 'complete':
1855 return
1856 assert only_one(pays)['status'] != 'failed'
1857
1858 inv = l5.rpc.invoice(10**8, 'test_retry', 'test_retry')
1859

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