Skip to content

Commit 816e4ea

Browse files
committed
pytest: test the askrene doesn't use local dying channels.
We don't want it to think that it can use both pre-splice and post-splice channels! Signed-off-by: Rusty Russell <[email protected]>
1 parent 836e9f2 commit 816e4ea

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

tests/test_askrene.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
from pyln.client import RpcError
44
from pyln.testing.utils import SLOW_MACHINE
55
from utils import (
6-
only_one, first_scid, GenChannel, generate_gossip_store,
6+
only_one, first_scid, first_scidd, GenChannel, generate_gossip_store,
77
sync_blockheight, wait_for, TEST_NETWORK, TIMEOUT, mine_funding_to_announce
88
)
99
import os
1010
import pytest
1111
import subprocess
1212
import time
1313
import tempfile
14+
import unittest
1415

1516

1617
def direction(src, dst):
@@ -1915,3 +1916,46 @@ def test_askrene_reserve_clash(node_factory, bitcoind):
19151916
layers=['layer2'],
19161917
maxfee_msat=1000,
19171918
final_cltv=5)
1919+
1920+
1921+
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
1922+
@pytest.mark.openchannel('v1')
1923+
@pytest.mark.openchannel('v2')
1924+
def test_splice_dying_channel(node_factory, bitcoind):
1925+
"""We should NOT try to use the pre-splice channel here"""
1926+
l1, l2, l3 = node_factory.line_graph(3,
1927+
wait_for_announce=True,
1928+
fundamount=200000,
1929+
opts={'experimental-splicing': None})
1930+
1931+
chan_id = l1.get_channel_id(l2)
1932+
funds_result = l1.rpc.addpsbtoutput(100000)
1933+
pre_splice_scidd = first_scidd(l1, l2)
1934+
1935+
# Pay with fee by subjtracting 5000 from channel balance
1936+
result = l1.rpc.splice_init(chan_id, -105000, funds_result['psbt'])
1937+
result = l1.rpc.splice_update(chan_id, result['psbt'])
1938+
assert(result['commitments_secured'] is False)
1939+
result = l1.rpc.splice_update(chan_id, result['psbt'])
1940+
assert(result['commitments_secured'] is True)
1941+
result = l1.rpc.splice_signed(chan_id, result['psbt'])
1942+
1943+
mine_funding_to_announce(bitcoind,
1944+
[l1, l2, l3],
1945+
num_blocks=6, wait_for_mempool=1)
1946+
1947+
wait_for(lambda: only_one(l1.rpc.listpeerchannels()['channels'])['state'] == 'CHANNELD_NORMAL')
1948+
post_splice_scidd = first_scidd(l1, l2)
1949+
1950+
# You will use the new scid
1951+
route = only_one(l1.rpc.getroutes(l1.info['id'], l2.info['id'], '50000sat', ['auto.localchans'], 100000, 6)['routes'])
1952+
assert only_one(route['path'])['short_channel_id_dir'] == post_splice_scidd
1953+
1954+
# And you will not be able to route 100001 sats:
1955+
with pytest.raises(RpcError, match="We could not find a usable set of paths"):
1956+
l1.rpc.getroutes(l1.info['id'], l2.info['id'], '100001sat', ['auto.localchans'], 100000, 6)
1957+
1958+
# But l3 would think it can use both, since it doesn't eliminate dying channel!
1959+
wait_for(lambda: [c['active'] for c in l3.rpc.listchannels()['channels']] == [True] * 6)
1960+
routes = l3.rpc.getroutes(l1.info['id'], l2.info['id'], '200001sat', [], 100000, 6)['routes']
1961+
assert set([only_one(r['path'])['short_channel_id_dir'] for r in routes]) == set([pre_splice_scidd, post_splice_scidd])

tests/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,11 @@ def first_scid(n1, n2):
458458
return only_one(n1.rpc.listpeerchannels(n2.info['id'])['channels'])['short_channel_id']
459459

460460

461+
def first_scidd(n1, n2):
462+
c = only_one(n1.rpc.listpeerchannels(n2.info['id'])['channels'])
463+
return c['short_channel_id'] + '/' + str(c['direction'])
464+
465+
461466
def basic_fee(feerate, anchor_expected):
462467
if anchor_expected:
463468
# option_anchor_outputs / option_anchors_zero_fee_htlc_tx

0 commit comments

Comments
 (0)