Skip to content

Commit 77749bf

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

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

tests/test_splicing_insane.py

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

0 commit comments

Comments
 (0)