@@ -183,7 +183,7 @@ fn test_onchain_htlc_timeout_delay_remote_commitment() {
183
183
do_test_onchain_htlc_reorg ( false , false ) ;
184
184
}
185
185
186
- fn do_test_unconf_chan ( reload_node : bool , reorg_after_reload : bool , connect_style : ConnectStyle ) {
186
+ fn do_test_unconf_chan ( reload_node : bool , reorg_after_reload : bool , use_funding_unconfirmed : bool , connect_style : ConnectStyle ) {
187
187
// After creating a chan between nodes, we disconnect all blocks previously seen to force a
188
188
// channel close on nodes[0] side. We also use this to provide very basic testing of logic
189
189
// around freeing background events which store monitor updates during block_[dis]connected.
@@ -196,16 +196,27 @@ fn do_test_unconf_chan(reload_node: bool, reorg_after_reload: bool, connect_styl
196
196
let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
197
197
* nodes[ 0 ] . connect_style . borrow_mut ( ) = connect_style;
198
198
199
- let chan_id = create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) . 2 ;
199
+ let chan = create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
200
200
201
201
let channel_state = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) ;
202
202
assert_eq ! ( channel_state. by_id. len( ) , 1 ) ;
203
203
assert_eq ! ( channel_state. short_to_id. len( ) , 1 ) ;
204
204
mem:: drop ( channel_state) ;
205
205
206
206
if !reorg_after_reload {
207
- disconnect_all_blocks ( & nodes[ 0 ] ) ;
208
- check_closed_broadcast ! ( nodes[ 0 ] , true ) ;
207
+ if use_funding_unconfirmed {
208
+ let relevant_txids = nodes[ 0 ] . node . get_relevant_txids ( ) ;
209
+ assert_eq ! ( & relevant_txids[ ..] , & [ chan. 3 . txid( ) ] ) ;
210
+ nodes[ 0 ] . node . transaction_unconfirmed ( & relevant_txids[ 0 ] ) ;
211
+ } else {
212
+ disconnect_all_blocks ( & nodes[ 0 ] ) ;
213
+ }
214
+ if connect_style == ConnectStyle :: FullBlockViaListen && !use_funding_unconfirmed {
215
+ handle_announce_close_broadcast_events ( & nodes, 0 , 1 , true , "Funding transaction was un-confirmed. Locked at 6 confs, now have 2 confs." ) ;
216
+ } else {
217
+ handle_announce_close_broadcast_events ( & nodes, 0 , 1 , true , "Funding transaction was un-confirmed. Locked at 6 confs, now have 0 confs." ) ;
218
+ }
219
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
209
220
{
210
221
let channel_state = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) ;
211
222
assert_eq ! ( channel_state. by_id. len( ) , 0 ) ;
@@ -249,14 +260,31 @@ fn do_test_unconf_chan(reload_node: bool, reorg_after_reload: bool, connect_styl
249
260
} ;
250
261
nodes[ 0 ] . node = & nodes_0_deserialized;
251
262
assert ! ( nodes_0_read. is_empty( ) ) ;
263
+ if !reorg_after_reload {
264
+ // If the channel is already closed when we reload the node, we'll broadcast a closing
265
+ // transaction via the ChannelMonitor which is missing a corresponding channel.
266
+ assert_eq ! ( nodes[ 0 ] . tx_broadcaster. txn_broadcasted. lock( ) . unwrap( ) . len( ) , 1 ) ;
267
+ nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clear ( ) ;
268
+ }
252
269
253
270
nodes[ 0 ] . chain_monitor . watch_channel ( chan_0_monitor. get_funding_txo ( ) . 0 . clone ( ) , chan_0_monitor) . unwrap ( ) ;
254
271
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
255
272
}
256
273
257
274
if reorg_after_reload {
258
- disconnect_all_blocks ( & nodes[ 0 ] ) ;
259
- check_closed_broadcast ! ( nodes[ 0 ] , true ) ;
275
+ if use_funding_unconfirmed {
276
+ let relevant_txids = nodes[ 0 ] . node . get_relevant_txids ( ) ;
277
+ assert_eq ! ( & relevant_txids[ ..] , & [ chan. 3 . txid( ) ] ) ;
278
+ nodes[ 0 ] . node . transaction_unconfirmed ( & relevant_txids[ 0 ] ) ;
279
+ } else {
280
+ disconnect_all_blocks ( & nodes[ 0 ] ) ;
281
+ }
282
+ if connect_style == ConnectStyle :: FullBlockViaListen && !use_funding_unconfirmed {
283
+ handle_announce_close_broadcast_events ( & nodes, 0 , 1 , true , "Funding transaction was un-confirmed. Locked at 6 confs, now have 2 confs." ) ;
284
+ } else {
285
+ handle_announce_close_broadcast_events ( & nodes, 0 , 1 , true , "Funding transaction was un-confirmed. Locked at 6 confs, now have 0 confs." ) ;
286
+ }
287
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
260
288
{
261
289
let channel_state = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) ;
262
290
assert_eq ! ( channel_state. by_id. len( ) , 0 ) ;
@@ -265,25 +293,44 @@ fn do_test_unconf_chan(reload_node: bool, reorg_after_reload: bool, connect_styl
265
293
}
266
294
// With expect_channel_force_closed set the TestChainMonitor will enforce that the next update
267
295
// is a ChannelForcClosed on the right channel with should_broadcast set.
268
- * nodes[ 0 ] . chain_monitor . expect_channel_force_closed . lock ( ) . unwrap ( ) = Some ( ( chan_id , true ) ) ;
296
+ * nodes[ 0 ] . chain_monitor . expect_channel_force_closed . lock ( ) . unwrap ( ) = Some ( ( chan . 2 , true ) ) ;
269
297
nodes[ 0 ] . node . test_process_background_events ( ) ; // Required to free the pending background monitor update
270
298
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
299
+ assert_eq ! ( nodes[ 0 ] . tx_broadcaster. txn_broadcasted. lock( ) . unwrap( ) . len( ) , 1 ) ;
300
+ nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clear ( ) ;
301
+
302
+ // Now check that we can create a new channel
303
+ create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
304
+ send_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 8000000 , 8_000_000 ) ;
271
305
}
272
306
273
307
#[ test]
274
308
fn test_unconf_chan ( ) {
275
- do_test_unconf_chan ( true , true , ConnectStyle :: BestBlockFirstSkippingBlocks ) ;
276
- do_test_unconf_chan ( false , true , ConnectStyle :: BestBlockFirstSkippingBlocks ) ;
277
- do_test_unconf_chan ( true , false , ConnectStyle :: BestBlockFirstSkippingBlocks ) ;
278
- do_test_unconf_chan ( false , false , ConnectStyle :: BestBlockFirstSkippingBlocks ) ;
309
+ do_test_unconf_chan ( true , true , false , ConnectStyle :: BestBlockFirstSkippingBlocks ) ;
310
+ do_test_unconf_chan ( false , true , false , ConnectStyle :: BestBlockFirstSkippingBlocks ) ;
311
+ do_test_unconf_chan ( true , false , false , ConnectStyle :: BestBlockFirstSkippingBlocks ) ;
312
+ do_test_unconf_chan ( false , false , false , ConnectStyle :: BestBlockFirstSkippingBlocks ) ;
279
313
}
280
314
281
315
#[ test]
282
316
fn test_unconf_chan_via_listen ( ) {
283
- do_test_unconf_chan ( true , true , ConnectStyle :: FullBlockViaListen ) ;
284
- do_test_unconf_chan ( false , true , ConnectStyle :: FullBlockViaListen ) ;
285
- do_test_unconf_chan ( true , false , ConnectStyle :: FullBlockViaListen ) ;
286
- do_test_unconf_chan ( false , false , ConnectStyle :: FullBlockViaListen ) ;
317
+ do_test_unconf_chan ( true , true , false , ConnectStyle :: FullBlockViaListen ) ;
318
+ do_test_unconf_chan ( false , true , false , ConnectStyle :: FullBlockViaListen ) ;
319
+ do_test_unconf_chan ( true , false , false , ConnectStyle :: FullBlockViaListen ) ;
320
+ do_test_unconf_chan ( false , false , false , ConnectStyle :: FullBlockViaListen ) ;
321
+ }
322
+
323
+ #[ test]
324
+ fn test_unconf_chan_via_funding_unconfirmed ( ) {
325
+ do_test_unconf_chan ( true , true , true , ConnectStyle :: BestBlockFirstSkippingBlocks ) ;
326
+ do_test_unconf_chan ( false , true , true , ConnectStyle :: BestBlockFirstSkippingBlocks ) ;
327
+ do_test_unconf_chan ( true , false , true , ConnectStyle :: BestBlockFirstSkippingBlocks ) ;
328
+ do_test_unconf_chan ( false , false , true , ConnectStyle :: BestBlockFirstSkippingBlocks ) ;
329
+
330
+ do_test_unconf_chan ( true , true , true , ConnectStyle :: FullBlockViaListen ) ;
331
+ do_test_unconf_chan ( false , true , true , ConnectStyle :: FullBlockViaListen ) ;
332
+ do_test_unconf_chan ( true , false , true , ConnectStyle :: FullBlockViaListen ) ;
333
+ do_test_unconf_chan ( false , false , true , ConnectStyle :: FullBlockViaListen ) ;
287
334
}
288
335
289
336
#[ test]
0 commit comments