Skip to content

Commit d96fe7e

Browse files
committed
splice: Test for two channel splice
A python test that splices into two channels at the same time with on transaction. Changelog-Added: Adding support for cross-channel splicing.
1 parent eb4b056 commit d96fe7e

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

tests/test_splicing.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,82 @@ def test_splice(node_factory, bitcoind):
4747
assert l1.db_query("SELECT count(*) as c FROM channeltxs;")[0]['c'] == 0
4848

4949

50+
@pytest.mark.openchannel('v1')
51+
@pytest.mark.openchannel('v2')
52+
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
53+
def test_two_chan_splice_in(node_factory, bitcoind):
54+
l1, l2, l3 = node_factory.line_graph(3, fundamount=1000000, wait_for_announce=True, opts={'experimental-splicing': None})
55+
56+
# l2 will splice funds into the channels with l1 and l3 at the same time
57+
58+
chan_id1 = l2.get_channel_id(l1)
59+
chan_id2 = l2.get_channel_id(l3)
60+
61+
# add extra sats to pay fee
62+
funds_result = l2.rpc.fundpsbt("209000sat", "slow", 166, excess_as_change=True)
63+
64+
# Intiate splices to both channels
65+
result = l2.rpc.splice_init(chan_id1, 100000, funds_result['psbt'])
66+
result = l2.rpc.splice_init(chan_id2, 100000, result['psbt']) # start with psbt from first channel
67+
68+
done1 = False
69+
done2 = False
70+
sigs1 = False
71+
sigs2 = False
72+
73+
while not done1 or not done2:
74+
if not done1:
75+
result = l2.rpc.splice_update(chan_id1, result['psbt'])
76+
done1 = result['commitments_secured']
77+
sigs1 = result['signatures_secured']
78+
print("chan 1 " + result['psbt'])
79+
if not done2:
80+
result = l2.rpc.splice_update(chan_id2, result['psbt'])
81+
done2 = result['commitments_secured']
82+
sigs2 = result['signatures_secured']
83+
print("chan 2 " + result['psbt'])
84+
85+
print("Sigs1 " + str(sigs1) + ", Sigs2 " + str(sigs2))
86+
assert(sigs1 or sigs2)
87+
88+
# Sign and finish splice for both channels
89+
result = l2.rpc.signpsbt(result['psbt'])
90+
result['psbt'] = result['signed_psbt']
91+
92+
if sigs2:
93+
# If chan2 gave us sigs, start with chan1
94+
result = l2.rpc.splice_signed(chan_id1, result['psbt'])
95+
result = l2.rpc.splice_signed(chan_id2, result['psbt'])
96+
else:
97+
# If chan1 gave us sigs, start with chan2
98+
result = l2.rpc.splice_signed(chan_id2, result['psbt'])
99+
result = l2.rpc.splice_signed(chan_id1, result['psbt'])
100+
101+
l3.daemon.wait_for_log(r'CHANNELD_NORMAL to CHANNELD_AWAITING_SPLICE')
102+
l2.daemon.wait_for_log(r'CHANNELD_NORMAL to CHANNELD_AWAITING_SPLICE')
103+
l1.daemon.wait_for_log(r'CHANNELD_NORMAL to CHANNELD_AWAITING_SPLICE')
104+
105+
wait_for(lambda: len(list(bitcoind.rpc.getrawmempool(True).keys())) == 1)
106+
mempool = bitcoind.rpc.getrawmempool(True)
107+
assert result['txid'] in list(mempool.keys())
108+
109+
bitcoind.generate_block(6, wait_for_mempool=1)
110+
111+
l3.daemon.wait_for_log(r'CHANNELD_AWAITING_SPLICE to CHANNELD_NORMAL')
112+
l2.daemon.wait_for_log(r'CHANNELD_AWAITING_SPLICE to CHANNELD_NORMAL')
113+
l1.daemon.wait_for_log(r'CHANNELD_AWAITING_SPLICE to CHANNELD_NORMAL')
114+
115+
inv = l2.rpc.invoice(10**2, '1', 'no_1')
116+
l1.rpc.pay(inv['bolt11'])
117+
118+
inv = l3.rpc.invoice(10**2, '2', 'no_2')
119+
l2.rpc.pay(inv['bolt11'])
120+
121+
# Check that the splice doesn't generate a unilateral close transaction
122+
time.sleep(5)
123+
assert l1.db_query("SELECT count(*) as c FROM channeltxs;")[0]['c'] == 0
124+
125+
50126
@pytest.mark.openchannel('v1')
51127
@pytest.mark.openchannel('v2')
52128
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')

0 commit comments

Comments
 (0)