Skip to content

Commit 8433c27

Browse files
committed
tests: add test_pay_avoid_low_fee_chan
Tests whether we're able to route around a low-fee channel in the graph. We should be able to find the more expensive route if the cheaper route is depleted.
1 parent 6260052 commit 8433c27

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

tests/test_pay.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,6 +1865,74 @@ def listpays_nofail(b11):
18651865
l1.dev_pay(inv, dev_use_shadow=False)
18661866

18671867

1868+
@pytest.mark.slow_test
1869+
def test_pay_avoid_low_fee_chan(node_factory, bitcoind, executor, chainparams):
1870+
"""Make sure we're able to route around a low fee depleted channel """
1871+
1872+
# NOTE: This test did not consistently fail. If this test is flaky, that
1873+
# probably means it needs to be fixed!
1874+
1875+
# Setup:
1876+
# sender - router --------- dest
1877+
# \ /
1878+
# - randomnode -
1879+
# router is connected to the destination
1880+
# randomnode is also connected to router and the destination, with a low fee
1881+
# path. The channel however, is depleted.
1882+
sender, router, randomnode, dest = node_factory.get_nodes(4)
1883+
sender.rpc.connect(router.info['id'], 'localhost', router.port)
1884+
sender.fundchannel(router, 200000, wait_for_active=True)
1885+
router.rpc.connect(dest.info['id'], 'localhost', dest.port)
1886+
router_dest_scid, _ = router.fundchannel(dest, 10**6, wait_for_active=True)
1887+
randomnode.rpc.connect(dest.info['id'], 'localhost', dest.port)
1888+
randomnode_dest_scid, _ = randomnode.fundchannel(dest, 10**6, wait_for_active=True)
1889+
1890+
# Router has a depleted channel to randomnode. Mimic this by opening the
1891+
# channel the other way around.
1892+
randomnode.rpc.connect(router.info['id'], 'localhost', router.port)
1893+
scid_router_random, _ = randomnode.fundchannel(router, 10**6, wait_for_active=True)
1894+
1895+
# Set relevant fees:
1896+
# - High fee from router to dest
1897+
# - Low fee from router to randomnode and randomnode to dest
1898+
router.rpc.setchannel(router_dest_scid, feebase=0, feeppm=2000, htlcmin=1)
1899+
router.rpc.setchannel(scid_router_random, feebase=0, feeppm=1, htlcmin=1)
1900+
randomnode.rpc.setchannel(randomnode_dest_scid, feebase=0, feeppm=1, htlcmin=1)
1901+
1902+
def has_gossip():
1903+
channels = sender.rpc.listchannels()['channels']
1904+
if sum(1 for c in channels if c['fee_per_millionth'] == 1) != 2:
1905+
return False
1906+
1907+
if sum(1 for c in channels if c['fee_per_millionth'] == 2000) != 1:
1908+
return False
1909+
1910+
return True
1911+
1912+
# Make sure all relevant gossip reached the sender.
1913+
mine_funding_to_announce(bitcoind, [sender, router, randomnode, dest])
1914+
wait_for(has_gossip)
1915+
1916+
def listpays_nofail(b11):
1917+
while True:
1918+
pays = sender.rpc.listpays(b11)['pays']
1919+
if len(pays) != 0:
1920+
if only_one(pays)['status'] == 'complete':
1921+
return
1922+
assert only_one(pays)['status'] != 'failed'
1923+
1924+
inv = dest.rpc.invoice(100000000, 'test_low_fee', 'test_low_fee')
1925+
1926+
# Make sure listpays doesn't transiently show failure while pay
1927+
# is retrying.
1928+
fut = executor.submit(listpays_nofail, inv['bolt11'])
1929+
1930+
# Pay sender->dest should succeed via non-depleted channel
1931+
sender.dev_pay(inv['bolt11'], dev_use_shadow=False)
1932+
1933+
fut.result()
1934+
1935+
18681936
@pytest.mark.slow_test
18691937
def test_pay_routeboost(node_factory, bitcoind):
18701938
"""Make sure we can use routeboost information. """

0 commit comments

Comments
 (0)