@@ -3247,7 +3247,7 @@ fn test_inverted_mon_completion_order() {
32473247 do_test_inverted_mon_completion_order ( false , false ) ;
32483248}
32493249
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 ) {
32513251 // Test that we can apply a `ChannelMonitorUpdate` with a payment preimage even if the channel
32523252 // is force-closed between when we generate the update on reload and when we go to handle the
32533253 // 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,
33433343 // After a timer tick a payment preimage ChannelMonitorUpdate is applied to the A<->B
33443344 // ChannelMonitor (possible twice), even though the channel has since been closed.
33453345 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+ }
33463352 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 ) ;
33483354
33493355 // Finally, check that B created a payment preimage transaction and close out the payment.
33503356 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,
33583364 } else {
33593365 // While we forwarded the payment a while ago, we don't want to process events too early or
33603366 // 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) ;
33623368 }
33633369
33643370 mine_transactions ( & nodes[ 0 ] , & [ & as_closing_tx[ 0 ] , bs_preimage_tx] ) ;
33653371 check_closed_broadcast ( & nodes[ 0 ] , 1 , true ) ;
33663372 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+ }
33673392}
33683393
33693394#[ test]
33703395fn 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 ) ;
33743402}
0 commit comments