@@ -39,3 +39,149 @@ def test_splice(node_factory, bitcoind):
39
39
# Check that the splice doesn't generate a unilateral close transaction
40
40
time .sleep (5 )
41
41
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
+ l1 , l2 = make_pending_splice (node_factory )
96
+ l2 .restart ()
97
+ wait_for_await_and_finish (l1 , l2 , bitcoind )
98
+ nodes .append (l1 )
99
+ nodes .append (l2 )
100
+
101
+ l1 , l2 = make_pending_splice (node_factory )
102
+ l1 .restart ()
103
+ # failing here "bad commit sig"
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
+ l2 .restart ()
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
+ wait_for_await (l1 , l2 )
117
+ l1 .restart ()
118
+ confirm_and_wait (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
+ l2 .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
+ l1 .restart ()
132
+ l2 .restart ()
133
+ confirm_and_wait (l1 , l2 , bitcoind )
134
+ nodes .append (l1 )
135
+ nodes .append (l2 )
136
+
137
+ l1 , l2 = make_pending_splice (node_factory )
138
+ wait_for_await (l1 , l2 )
139
+ confirm (bitcoind )
140
+ l1 .restart ()
141
+ wait_for_confirm (l1 , l2 )
142
+ nodes .append (l1 )
143
+ nodes .append (l2 )
144
+
145
+ l1 , l2 = make_pending_splice (node_factory )
146
+ wait_for_await (l1 , l2 )
147
+ confirm (bitcoind )
148
+ l2 .restart ()
149
+ wait_for_confirm (l1 , l2 )
150
+ nodes .append (l1 )
151
+ nodes .append (l2 )
152
+
153
+ l1 , l2 = make_pending_splice (node_factory )
154
+ wait_for_await (l1 , l2 )
155
+ confirm (bitcoind )
156
+ l1 .restart ()
157
+ l2 .restart ()
158
+ wait_for_confirm (l1 , l2 )
159
+ nodes .append (l1 )
160
+ nodes .append (l2 )
161
+
162
+ l1 , l2 = make_pending_splice (node_factory )
163
+ wait_for_await (l1 , l2 )
164
+ confirm (bitcoind )
165
+ wait_for_await_and_finish (l1 , l2 , bitcoind )
166
+ l1 .restart ()
167
+ nodes .append (l1 )
168
+ nodes .append (l2 )
169
+
170
+ l1 , l2 = make_pending_splice (node_factory )
171
+ wait_for_await (l1 , l2 )
172
+ confirm (bitcoind )
173
+ wait_for_await_and_finish (l1 , l2 , bitcoind )
174
+ l2 .restart ()
175
+ nodes .append (l1 )
176
+ nodes .append (l2 )
177
+
178
+ l1 , l2 = make_pending_splice (node_factory )
179
+ wait_for_await (l1 , l2 )
180
+ confirm (bitcoind )
181
+ wait_for_await_and_finish (l1 , l2 , bitcoind )
182
+ l1 .restart ()
183
+ l2 .restart ()
184
+ nodes .append (l1 )
185
+ nodes .append (l2 )
186
+
187
+ confirm_funding_not_spent (nodes )
0 commit comments