Skip to content

Commit bc1cce8

Browse files
committed
splice: Agressive restart testing during splices
Test node restarts in lots of phases of splice. Changelog-None
1 parent a48e225 commit bc1cce8

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

tests/test_splicing_insane.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
from fixtures import * # noqa: F401,F403
2+
from utils import TEST_NETWORK
3+
import pytest
4+
import unittest
5+
6+
7+
def make_pending_splice(node_factory):
8+
l1, l2 = node_factory.line_graph(2, fundamount=1000000, wait_for_announce=True, opts={'experimental-splicing': None, 'may_reconnect': True})
9+
10+
chan_id = l1.get_channel_id(l2)
11+
12+
funds_result = l1.rpc.fundpsbt("109000sat", "slow", 166, excess_as_change=True)
13+
14+
result = l1.rpc.splice_init(chan_id, 100000, funds_result['psbt'])
15+
result = l1.rpc.splice_update(chan_id, result['psbt'])
16+
result = l1.rpc.signpsbt(result['psbt'])
17+
result = l1.rpc.splice_signed(chan_id, result['signed_psbt'])
18+
19+
return [l1, l2]
20+
21+
22+
def wait_for_confirm(l1, l2):
23+
l2.daemon.wait_for_log(r'CHANNELD_AWAITING_SPLICE to CHANNELD_NORMAL')
24+
l1.daemon.wait_for_log(r'CHANNELD_AWAITING_SPLICE to CHANNELD_NORMAL')
25+
26+
27+
def confirm(bitcoind):
28+
bitcoind.generate_block(6, wait_for_mempool=1)
29+
30+
31+
def confirm_and_wait(l1, l2, bitcoind):
32+
confirm(bitcoind)
33+
wait_for_confirm(l1, l2)
34+
35+
36+
def confirm_funding_not_spent(nodes):
37+
for node in nodes:
38+
assert not node.daemon.is_in_log("Funding transaction spent")
39+
assert node.db_query("SELECT count(*) as c FROM channeltxs;")[0]['c'] == 0
40+
41+
42+
def wait_for_restart(l1, l2):
43+
l1.daemon.wait_for_log(r'peer_in WIRE_CHANNEL_REESTABLISH')
44+
l2.daemon.wait_for_log(r'peer_in WIRE_CHANNEL_REESTABLISH')
45+
46+
47+
@pytest.mark.openchannel('v1')
48+
@pytest.mark.openchannel('v2')
49+
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
50+
def test_splice_insane(node_factory, bitcoind):
51+
nodes = []
52+
53+
l1, l2 = make_pending_splice(node_factory)
54+
l2.restart()
55+
wait_for_restart(l1, l2)
56+
confirm_and_wait(l1, l2, bitcoind)
57+
nodes.append(l1)
58+
nodes.append(l2)
59+
60+
l1, l2 = make_pending_splice(node_factory)
61+
l1.restart()
62+
wait_for_restart(l1, l2)
63+
confirm_and_wait(l1, l2, bitcoind)
64+
nodes.append(l1)
65+
nodes.append(l2)
66+
67+
l1, l2 = make_pending_splice(node_factory)
68+
l1.restart()
69+
wait_for_restart(l1, l2)
70+
confirm_and_wait(l1, l2, bitcoind)
71+
nodes.append(l1)
72+
nodes.append(l2)
73+
74+
l1, l2 = make_pending_splice(node_factory)
75+
l2.restart()
76+
wait_for_restart(l1, l2)
77+
confirm_and_wait(l1, l2, bitcoind)
78+
nodes.append(l1)
79+
nodes.append(l2)
80+
81+
l1, l2 = make_pending_splice(node_factory)
82+
confirm_and_wait(l1, l2, bitcoind)
83+
l1.restart()
84+
wait_for_restart(l1, l2)
85+
nodes.append(l1)
86+
nodes.append(l2)
87+
88+
l1, l2 = make_pending_splice(node_factory)
89+
confirm_and_wait(l1, l2, bitcoind)
90+
l2.restart()
91+
wait_for_restart(l1, l2)
92+
nodes.append(l1)
93+
nodes.append(l2)
94+
95+
confirm_funding_not_spent(nodes)

0 commit comments

Comments
 (0)