Skip to content

Commit 87b639f

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

File tree

2 files changed

+154
-5
lines changed

2 files changed

+154
-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: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,155 @@ def test_splice(node_factory, bitcoind):
3434

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

0 commit comments

Comments
 (0)