|
3 | 3 | from pyln.client import RpcError |
4 | 4 | from pyln.testing.utils import SLOW_MACHINE |
5 | 5 | from utils import ( |
6 | | - only_one, first_scid, GenChannel, generate_gossip_store, |
| 6 | + only_one, first_scid, first_scidd, GenChannel, generate_gossip_store, |
7 | 7 | sync_blockheight, wait_for, TEST_NETWORK, TIMEOUT, mine_funding_to_announce |
8 | 8 | ) |
9 | 9 | import os |
10 | 10 | import pytest |
11 | 11 | import subprocess |
12 | 12 | import time |
13 | 13 | import tempfile |
| 14 | +import unittest |
14 | 15 |
|
15 | 16 |
|
16 | 17 | def direction(src, dst): |
@@ -1915,3 +1916,46 @@ def test_askrene_reserve_clash(node_factory, bitcoind): |
1915 | 1916 | layers=['layer2'], |
1916 | 1917 | maxfee_msat=1000, |
1917 | 1918 | 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]) |
0 commit comments