@@ -3264,7 +3264,7 @@ fn test_inverted_mon_completion_order() {
3264
3264
do_test_inverted_mon_completion_order ( false , false ) ;
3265
3265
}
3266
3266
3267
- fn do_test_durable_preimages_on_closed_channel ( close_chans_before_reload : bool , close_only_a : bool ) {
3267
+ fn do_test_durable_preimages_on_closed_channel ( close_chans_before_reload : bool , close_only_a : bool , hold_post_reload_mon_update : bool ) {
3268
3268
// Test that we can apply a `ChannelMonitorUpdate` with a payment preimage even if the channel
3269
3269
// is force-closed between when we generate the update on reload and when we go to handle the
3270
3270
// update or prior to generating the update at all.
@@ -3360,8 +3360,14 @@ fn do_test_durable_preimages_on_closed_channel(close_chans_before_reload: bool,
3360
3360
// After a timer tick a payment preimage ChannelMonitorUpdate is applied to the A<->B
3361
3361
// ChannelMonitor (possible twice), even though the channel has since been closed.
3362
3362
check_added_monitors ( & nodes[ 1 ] , 0 ) ;
3363
+ let mons_added = if close_chans_before_reload { if !close_only_a { 4 } else { 3 } } else { 2 } ;
3364
+ if hold_post_reload_mon_update {
3365
+ for _ in 0 ..mons_added {
3366
+ persister. set_update_ret ( ChannelMonitorUpdateStatus :: InProgress ) ;
3367
+ }
3368
+ }
3363
3369
nodes[ 1 ] . node . timer_tick_occurred ( ) ;
3364
- check_added_monitors ( & nodes[ 1 ] , if close_chans_before_reload { if !close_only_a { 4 } else { 3 } } else { 2 } ) ;
3370
+ check_added_monitors ( & nodes[ 1 ] , mons_added ) ;
3365
3371
3366
3372
// Finally, check that B created a payment preimage transaction and close out the payment.
3367
3373
let bs_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . split_off ( 0 ) ;
@@ -3381,11 +3387,36 @@ fn do_test_durable_preimages_on_closed_channel(close_chans_before_reload: bool,
3381
3387
mine_transactions ( & nodes[ 0 ] , & [ & as_closing_tx[ 0 ] , bs_preimage_tx] ) ;
3382
3388
check_closed_broadcast ( & nodes[ 0 ] , 1 , true ) ;
3383
3389
expect_payment_sent ( & nodes[ 0 ] , payment_preimage, None , true , true ) ;
3390
+
3391
+ if !close_chans_before_reload || close_only_a {
3392
+ // Make sure the B<->C channel is still alive and well by sending a payment over it.
3393
+ let mut reconnect_args = ReconnectArgs :: new ( & nodes[ 1 ] , & nodes[ 2 ] ) ;
3394
+ reconnect_args. pending_htlc_adds . 1 = if close_only_a {
3395
+ // XXX If
3396
+ -1
3397
+ } else { -2 } ;
3398
+ reconnect_args. pending_raa . 1 = true ;
3399
+
3400
+ reconnect_nodes ( reconnect_args) ;
3401
+ let ( outpoint, ab_update_id, _) = nodes[ 1 ] . chain_monitor . latest_monitor_update_id . lock ( ) . unwrap ( ) . get ( & chan_id_ab) . unwrap ( ) . clone ( ) ;
3402
+ nodes[ 1 ] . chain_monitor . chain_monitor . force_channel_monitor_updated ( outpoint, ab_update_id) ;
3403
+ expect_payment_forwarded ! ( nodes[ 1 ] , nodes[ 0 ] , nodes[ 2 ] , Some ( 1000 ) , true , false ) ;
3404
+ if !close_only_a {
3405
+ // Once we call `process_pending_events` the final `ChannelMonitor` for the B<->C
3406
+ // channel will fly, removing the payment preimage from it.
3407
+ check_added_monitors ( & nodes[ 1 ] , 1 ) ;
3408
+ }
3409
+ assert ! ( nodes[ 1 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
3410
+ send_payment ( & nodes[ 1 ] , & [ & nodes[ 2 ] ] , 100_000 ) ;
3411
+ }
3384
3412
}
3385
3413
3386
3414
#[ test]
3387
3415
fn test_durable_preimages_on_closed_channel ( ) {
3388
- do_test_durable_preimages_on_closed_channel ( true , true ) ;
3389
- do_test_durable_preimages_on_closed_channel ( true , false ) ;
3390
- do_test_durable_preimages_on_closed_channel ( false , false ) ;
3416
+ do_test_durable_preimages_on_closed_channel ( true , true , true ) ;
3417
+ do_test_durable_preimages_on_closed_channel ( true , true , false ) ;
3418
+ do_test_durable_preimages_on_closed_channel ( true , false , true ) ;
3419
+ do_test_durable_preimages_on_closed_channel ( true , false , false ) ;
3420
+ do_test_durable_preimages_on_closed_channel ( false , false , true ) ;
3421
+ do_test_durable_preimages_on_closed_channel ( false , false , false ) ;
3391
3422
}
0 commit comments