Skip to content

Commit 21be6e7

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

File tree

2 files changed

+155
-5
lines changed

2 files changed

+155
-5
lines changed

lightningd/channel.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ new_inflight(struct channel *channel,
137137
s64 splice_amnt,
138138
bool i_am_initiator)
139139
{
140-
struct wally_psbt *last_tx_psbt_clone;
141140
struct channel_inflight *inflight
142141
= tal(channel, struct channel_inflight);
143142
struct funding_info *funding
@@ -156,10 +155,8 @@ new_inflight(struct channel *channel,
156155

157156
/* Make a 'clone' of this tx */
158157
inflight->last_tx = NULL;
159-
if (last_tx) {
160-
last_tx_psbt_clone = clone_psbt(inflight, last_tx->psbt);
161-
inflight->last_tx = bitcoin_tx_with_psbt(inflight, last_tx_psbt_clone);
162-
}
158+
if (last_tx)
159+
inflight->last_tx = clone_bitcoin_tx(inflight, last_tx);
163160
inflight->last_sig = last_sig;
164161
inflight->tx_broadcast = false;
165162

tests/test_splicing.py

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,156 @@ def test_splice(node_factory, bitcoind):
3939
# Check that the splice doesn't generate a unilateral close transaction
4040
time.sleep(5)
4141
assert l1.db_query("SELECT count(*) as c FROM channeltxs;")[0]['c'] == 0
42+
43+
44+
def make_pending_splice(node_factory):
45+
l1, l2 = node_factory.line_graph(2, fundamount=1000000, wait_for_announce=True, opts={'experimental-splicing': None, 'may_reconnect': True})
46+
47+
chan_id = l1.get_channel_id(l2)
48+
49+
funds_result = l1.rpc.fundpsbt("109000sat", "slow", 166, excess_as_change=True)
50+
51+
result = l1.rpc.splice_init(chan_id, 100000, funds_result['psbt'])
52+
result = l1.rpc.splice_update(chan_id, result['psbt'])
53+
result = l1.rpc.signpsbt(result['psbt'])
54+
result = l1.rpc.splice_signed(chan_id, result['signed_psbt'])
55+
56+
return [l1, l2]
57+
58+
59+
def wait_for_await(l1, l2):
60+
l2.daemon.wait_for_log(r'CHANNELD_NORMAL to CHANNELD_AWAITING_SPLICE')
61+
l1.daemon.wait_for_log(r'CHANNELD_NORMAL to CHANNELD_AWAITING_SPLICE')
62+
63+
64+
def wait_for_confirm(l1, l2):
65+
l2.daemon.wait_for_log(r'CHANNELD_AWAITING_SPLICE to CHANNELD_NORMAL')
66+
l1.daemon.wait_for_log(r'CHANNELD_AWAITING_SPLICE to CHANNELD_NORMAL')
67+
68+
69+
def confirm(bitcoind):
70+
bitcoind.generate_block(6, wait_for_mempool=1)
71+
72+
73+
def confirm_and_wait(l1, l2, bitcoind):
74+
confirm(bitcoind)
75+
wait_for_confirm(l1, l2)
76+
77+
78+
def wait_for_await_and_finish(l1, l2, bitcoind):
79+
wait_for_await(l1, l2)
80+
confirm_and_wait(l1, l2, bitcoind)
81+
82+
83+
def confirm_funding_not_spent(nodes):
84+
for node in nodes:
85+
assert not node.daemon.is_in_log("Funding transaction spent")
86+
assert node.db_query("SELECT count(*) as c FROM channeltxs;")[0]['c'] == 0
87+
88+
89+
@pytest.mark.openchannel('v1')
90+
@pytest.mark.openchannel('v2')
91+
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
92+
def test_splice_restart(node_factory, bitcoind):
93+
nodes = []
94+
95+
# First test the test with a basic splice
96+
l1, l2 = make_pending_splice(node_factory)
97+
wait_for_await_and_finish(l1, l2, bitcoind)
98+
nodes.append(l1)
99+
nodes.append(l2)
100+
confirm_funding_not_spent(nodes)
101+
102+
l1, l2 = make_pending_splice(node_factory)
103+
l2.restart()
104+
wait_for_await_and_finish(l1, l2, bitcoind)
105+
nodes.append(l1)
106+
nodes.append(l2)
107+
108+
l1, l2 = make_pending_splice(node_factory)
109+
l1.restart()
110+
# failing here "bad commit sig"
111+
wait_for_await_and_finish(l1, l2, bitcoind)
112+
nodes.append(l1)
113+
nodes.append(l2)
114+
115+
l1, l2 = make_pending_splice(node_factory)
116+
l1.restart()
117+
l2.restart()
118+
wait_for_await_and_finish(l1, l2, bitcoind)
119+
nodes.append(l1)
120+
nodes.append(l2)
121+
122+
l1, l2 = make_pending_splice(node_factory)
123+
wait_for_await(l1, l2)
124+
l1.restart()
125+
confirm_and_wait(l1, l2, bitcoind)
126+
nodes.append(l1)
127+
nodes.append(l2)
128+
129+
l1, l2 = make_pending_splice(node_factory)
130+
wait_for_await(l1, l2)
131+
l2.restart()
132+
confirm_and_wait(l1, l2, bitcoind)
133+
nodes.append(l1)
134+
nodes.append(l2)
135+
136+
l1, l2 = make_pending_splice(node_factory)
137+
wait_for_await(l1, l2)
138+
l1.restart()
139+
l2.restart()
140+
confirm_and_wait(l1, l2, bitcoind)
141+
nodes.append(l1)
142+
nodes.append(l2)
143+
144+
l1, l2 = make_pending_splice(node_factory)
145+
wait_for_await(l1, l2)
146+
confirm(bitcoind)
147+
l1.restart()
148+
wait_for_confirm(l1, l2)
149+
nodes.append(l1)
150+
nodes.append(l2)
151+
152+
l1, l2 = make_pending_splice(node_factory)
153+
wait_for_await(l1, l2)
154+
confirm(bitcoind)
155+
l2.restart()
156+
wait_for_confirm(l1, l2)
157+
nodes.append(l1)
158+
nodes.append(l2)
159+
160+
l1, l2 = make_pending_splice(node_factory)
161+
wait_for_await(l1, l2)
162+
confirm(bitcoind)
163+
l1.restart()
164+
l2.restart()
165+
wait_for_confirm(l1, l2)
166+
nodes.append(l1)
167+
nodes.append(l2)
168+
169+
l1, l2 = make_pending_splice(node_factory)
170+
wait_for_await(l1, l2)
171+
confirm(bitcoind)
172+
wait_for_await_and_finish(l1, l2, bitcoind)
173+
l1.restart()
174+
nodes.append(l1)
175+
nodes.append(l2)
176+
177+
l1, l2 = make_pending_splice(node_factory)
178+
wait_for_await(l1, l2)
179+
confirm(bitcoind)
180+
wait_for_await_and_finish(l1, l2, bitcoind)
181+
l2.restart()
182+
nodes.append(l1)
183+
nodes.append(l2)
184+
185+
l1, l2 = make_pending_splice(node_factory)
186+
wait_for_await(l1, l2)
187+
confirm(bitcoind)
188+
wait_for_await_and_finish(l1, l2, bitcoind)
189+
l1.restart()
190+
l2.restart()
191+
nodes.append(l1)
192+
nodes.append(l2)
193+
194+
confirm_funding_not_spent(nodes)

0 commit comments

Comments
 (0)