@@ -34,3 +34,155 @@ def test_splice(node_factory, bitcoind):
34
34
35
35
inv = l2 .rpc .invoice (10 ** 2 , '3' , 'no_3' )
36
36
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