@@ -3247,7 +3247,7 @@ fn test_inverted_mon_completion_order() {
3247
3247
do_test_inverted_mon_completion_order ( false , false ) ;
3248
3248
}
3249
3249
3250
- fn do_test_durable_preimages_on_closed_channel ( close_chans_before_reload : bool , close_only_a : bool ) {
3250
+ fn do_test_durable_preimages_on_closed_channel ( close_chans_before_reload : bool , close_only_a : bool , hold_post_reload_mon_update : bool ) {
3251
3251
// Test that we can apply a `ChannelMonitorUpdate` with a payment preimage even if the channel
3252
3252
// is force-closed between when we generate the update on reload and when we go to handle the
3253
3253
// update or prior to generating the update at all.
@@ -3343,8 +3343,14 @@ fn do_test_durable_preimages_on_closed_channel(close_chans_before_reload: bool,
3343
3343
// After a timer tick a payment preimage ChannelMonitorUpdate is applied to the A<->B
3344
3344
// ChannelMonitor (possible twice), even though the channel has since been closed.
3345
3345
check_added_monitors ( & nodes[ 1 ] , 0 ) ;
3346
+ let mons_added = if close_chans_before_reload { if !close_only_a { 4 } else { 3 } } else { 2 } ;
3347
+ if hold_post_reload_mon_update {
3348
+ for _ in 0 ..mons_added {
3349
+ persister. set_update_ret ( ChannelMonitorUpdateStatus :: InProgress ) ;
3350
+ }
3351
+ }
3346
3352
nodes[ 1 ] . node . timer_tick_occurred ( ) ;
3347
- check_added_monitors ( & nodes[ 1 ] , if close_chans_before_reload { if !close_only_a { 4 } else { 3 } } else { 2 } ) ;
3353
+ check_added_monitors ( & nodes[ 1 ] , mons_added ) ;
3348
3354
3349
3355
// Finally, check that B created a payment preimage transaction and close out the payment.
3350
3356
let bs_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . split_off ( 0 ) ;
@@ -3358,17 +3364,39 @@ fn do_test_durable_preimages_on_closed_channel(close_chans_before_reload: bool,
3358
3364
} else {
3359
3365
// While we forwarded the payment a while ago, we don't want to process events too early or
3360
3366
// we'll run background tasks we wanted to test individually.
3361
- expect_payment_forwarded ! ( nodes[ 1 ] , nodes[ 0 ] , nodes[ 2 ] , None , false , !close_only_a) ;
3367
+ expect_payment_forwarded ! ( nodes[ 1 ] , nodes[ 0 ] , nodes[ 2 ] , None , true , !close_only_a) ;
3362
3368
}
3363
3369
3364
3370
mine_transactions ( & nodes[ 0 ] , & [ & as_closing_tx[ 0 ] , bs_preimage_tx] ) ;
3365
3371
check_closed_broadcast ( & nodes[ 0 ] , 1 , true ) ;
3366
3372
expect_payment_sent ( & nodes[ 0 ] , payment_preimage, None , true , true ) ;
3373
+
3374
+ if !close_chans_before_reload || close_only_a {
3375
+ // Make sure the B<->C channel is still alive and well by sending a payment over it.
3376
+ let have_mon = if close_only_a {
3377
+ // XXX If
3378
+ -1
3379
+ } else { -2 } ;
3380
+ reconnect_nodes ( & nodes[ 1 ] , & nodes[ 2 ] , ( false , false ) , ( 0 , have_mon) , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( false , true ) ) ;
3381
+ let ( outpoint, ab_update_id, _) = nodes[ 1 ] . chain_monitor . latest_monitor_update_id . lock ( ) . unwrap ( ) . get ( & chan_id_ab) . unwrap ( ) . clone ( ) ;
3382
+ nodes[ 1 ] . chain_monitor . chain_monitor . force_channel_monitor_updated ( outpoint, ab_update_id) ;
3383
+ expect_payment_forwarded ! ( nodes[ 1 ] , nodes[ 0 ] , nodes[ 2 ] , Some ( 1000 ) , true , false ) ;
3384
+ if !close_only_a {
3385
+ // Once we call `process_pending_events` the final `ChannelMonitor` for the B<->C
3386
+ // channel will fly, removing the payment preimage from it.
3387
+ check_added_monitors ( & nodes[ 1 ] , 1 ) ;
3388
+ }
3389
+ assert ! ( nodes[ 1 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
3390
+ send_payment ( & nodes[ 1 ] , & [ & nodes[ 2 ] ] , 100_000 ) ;
3391
+ }
3367
3392
}
3368
3393
3369
3394
#[ test]
3370
3395
fn test_durable_preimages_on_closed_channel ( ) {
3371
- do_test_durable_preimages_on_closed_channel ( true , true ) ;
3372
- do_test_durable_preimages_on_closed_channel ( true , false ) ;
3373
- do_test_durable_preimages_on_closed_channel ( false , false ) ;
3396
+ do_test_durable_preimages_on_closed_channel ( true , true , true ) ;
3397
+ do_test_durable_preimages_on_closed_channel ( true , true , false ) ;
3398
+ do_test_durable_preimages_on_closed_channel ( true , false , true ) ;
3399
+ do_test_durable_preimages_on_closed_channel ( true , false , false ) ;
3400
+ do_test_durable_preimages_on_closed_channel ( false , false , true ) ;
3401
+ do_test_durable_preimages_on_closed_channel ( false , false , false ) ;
3374
3402
}
0 commit comments