@@ -3598,3 +3598,117 @@ fn test_glacial_peer_cant_hang() {
3598
3598
do_test_glacial_peer_cant_hang ( false ) ;
3599
3599
do_test_glacial_peer_cant_hang ( true ) ;
3600
3600
}
3601
+
3602
+ #[ test]
3603
+ fn test_partial_claim_mon_update_compl_actions ( ) {
3604
+ // Test that if we have an MPP claim that we ensure the preimage for the claim is retained in
3605
+ // all the `ChannelMonitor`s until the preimage reaches every `ChannelMonitor` for a channel
3606
+ // which was a part of the MPP.
3607
+ let chanmon_cfgs = create_chanmon_cfgs ( 4 ) ;
3608
+ let node_cfgs = create_node_cfgs ( 4 , & chanmon_cfgs) ;
3609
+ let node_chanmgrs = create_node_chanmgrs ( 4 , & node_cfgs, & [ None , None , None , None ] ) ;
3610
+ let mut nodes = create_network ( 4 , & node_cfgs, & node_chanmgrs) ;
3611
+
3612
+ let chan_1_scid = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) . 0 . contents . short_channel_id ;
3613
+ let chan_2_scid = create_announced_chan_between_nodes ( & nodes, 0 , 2 ) . 0 . contents . short_channel_id ;
3614
+ let ( chan_3_update, _, chan_3_id, ..) = create_announced_chan_between_nodes ( & nodes, 1 , 3 ) ;
3615
+ let chan_3_scid = chan_3_update. contents . short_channel_id ;
3616
+ let ( chan_4_update, _, chan_4_id, ..) = create_announced_chan_between_nodes ( & nodes, 2 , 3 ) ;
3617
+ let chan_4_scid = chan_4_update. contents . short_channel_id ;
3618
+
3619
+ let ( mut route, payment_hash, preimage, payment_secret) = get_route_and_payment_hash ! ( & nodes[ 0 ] , nodes[ 3 ] , 100000 ) ;
3620
+ let path = route. paths [ 0 ] . clone ( ) ;
3621
+ route. paths . push ( path) ;
3622
+ route. paths [ 0 ] . hops [ 0 ] . pubkey = nodes[ 1 ] . node . get_our_node_id ( ) ;
3623
+ route. paths [ 0 ] . hops [ 0 ] . short_channel_id = chan_1_scid;
3624
+ route. paths [ 0 ] . hops [ 1 ] . short_channel_id = chan_3_scid;
3625
+ route. paths [ 1 ] . hops [ 0 ] . pubkey = nodes[ 2 ] . node . get_our_node_id ( ) ;
3626
+ route. paths [ 1 ] . hops [ 0 ] . short_channel_id = chan_2_scid;
3627
+ route. paths [ 1 ] . hops [ 1 ] . short_channel_id = chan_4_scid;
3628
+ send_along_route_with_secret ( & nodes[ 0 ] , route, & [ & [ & nodes[ 1 ] , & nodes[ 3 ] ] , & [ & nodes[ 2 ] , & nodes[ 3 ] ] ] , 200_000 , payment_hash, payment_secret) ;
3629
+
3630
+ // Claim along both paths, but only complete one of the two monitor updates.
3631
+ chanmon_cfgs[ 3 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: InProgress ) ;
3632
+ chanmon_cfgs[ 3 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: InProgress ) ;
3633
+ nodes[ 3 ] . node . claim_funds ( preimage) ;
3634
+ assert_eq ! ( nodes[ 3 ] . node. get_and_clear_pending_msg_events( ) , Vec :: new( ) ) ;
3635
+ assert_eq ! ( nodes[ 3 ] . node. get_and_clear_pending_events( ) , Vec :: new( ) ) ;
3636
+ check_added_monitors ( & nodes[ 3 ] , 2 ) ;
3637
+
3638
+ // Complete the 1<->3 monitor update and play the commitment_signed dance forward until it
3639
+ // blocks.
3640
+ nodes[ 3 ] . chain_monitor . complete_sole_pending_chan_update ( & chan_3_id) ;
3641
+ expect_payment_claimed ! ( & nodes[ 3 ] , payment_hash, 200_000 ) ;
3642
+ let updates = get_htlc_update_msgs ( & nodes[ 3 ] , & nodes[ 1 ] . node . get_our_node_id ( ) ) ;
3643
+
3644
+ nodes[ 1 ] . node . handle_update_fulfill_htlc ( & nodes[ 3 ] . node . get_our_node_id ( ) , & updates. update_fulfill_htlcs [ 0 ] ) ;
3645
+ check_added_monitors ( & nodes[ 1 ] , 1 ) ;
3646
+ expect_payment_forwarded ! ( nodes[ 1 ] , nodes[ 0 ] , nodes[ 3 ] , Some ( 1000 ) , false , false ) ;
3647
+ let _bs_updates_for_a = get_htlc_update_msgs ( & nodes[ 1 ] , & nodes[ 0 ] . node . get_our_node_id ( ) ) ;
3648
+
3649
+ nodes[ 1 ] . node . handle_commitment_signed ( & nodes[ 3 ] . node . get_our_node_id ( ) , & updates. commitment_signed ) ;
3650
+ check_added_monitors ( & nodes[ 1 ] , 1 ) ;
3651
+ let ( bs_raa, bs_cs) = get_revoke_commit_msgs ( & nodes[ 1 ] , & nodes[ 3 ] . node . get_our_node_id ( ) ) ;
3652
+
3653
+ nodes[ 3 ] . node . handle_revoke_and_ack ( & nodes[ 1 ] . node . get_our_node_id ( ) , & bs_raa) ;
3654
+ check_added_monitors ( & nodes[ 3 ] , 0 ) ;
3655
+
3656
+ nodes[ 3 ] . node . handle_commitment_signed ( & nodes[ 1 ] . node . get_our_node_id ( ) , & bs_cs) ;
3657
+ check_added_monitors ( & nodes[ 3 ] , 0 ) ;
3658
+ assert ! ( nodes[ 3 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
3659
+
3660
+ // Now double-check that the preimage is still in the 1<->3 channel and complete the pending
3661
+ // monitor update, allowing node 3 to claim the payment on the 2<->3 channel. This also
3662
+ // unblocks the 1<->3 channel, allowing node 3 to release the two blocked monitor updates and
3663
+ // respond to the final commitment_signed.
3664
+ assert ! ( get_monitor!( nodes[ 3 ] , chan_3_id) . get_stored_preimages( ) . contains_key( & payment_hash) ) ;
3665
+
3666
+ nodes[ 3 ] . chain_monitor . complete_sole_pending_chan_update ( & chan_4_id) ;
3667
+ let mut ds_msgs = nodes[ 3 ] . node . get_and_clear_pending_msg_events ( ) ;
3668
+ assert_eq ! ( ds_msgs. len( ) , 2 ) ;
3669
+ check_added_monitors ( & nodes[ 3 ] , 2 ) ;
3670
+
3671
+ match remove_first_msg_event_to_node ( & nodes[ 1 ] . node . get_our_node_id ( ) , & mut ds_msgs) {
3672
+ MessageSendEvent :: SendRevokeAndACK { msg, .. } => {
3673
+ nodes[ 1 ] . node . handle_revoke_and_ack ( & nodes[ 3 ] . node . get_our_node_id ( ) , & msg) ;
3674
+ check_added_monitors ( & nodes[ 1 ] , 1 ) ;
3675
+ }
3676
+ _ => panic ! ( ) ,
3677
+ }
3678
+
3679
+ match remove_first_msg_event_to_node ( & nodes[ 2 ] . node . get_our_node_id ( ) , & mut ds_msgs) {
3680
+ MessageSendEvent :: UpdateHTLCs { updates, .. } => {
3681
+ nodes[ 2 ] . node . handle_update_fulfill_htlc ( & nodes[ 3 ] . node . get_our_node_id ( ) , & updates. update_fulfill_htlcs [ 0 ] ) ;
3682
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
3683
+ expect_payment_forwarded ! ( nodes[ 2 ] , nodes[ 0 ] , nodes[ 3 ] , Some ( 1000 ) , false , false ) ;
3684
+ let _cs_updates_for_a = get_htlc_update_msgs ( & nodes[ 2 ] , & nodes[ 0 ] . node . get_our_node_id ( ) ) ;
3685
+
3686
+ nodes[ 2 ] . node . handle_commitment_signed ( & nodes[ 3 ] . node . get_our_node_id ( ) , & updates. commitment_signed ) ;
3687
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
3688
+ } ,
3689
+ _ => panic ! ( ) ,
3690
+ }
3691
+
3692
+ let ( cs_raa, cs_cs) = get_revoke_commit_msgs ( & nodes[ 2 ] , & nodes[ 3 ] . node . get_our_node_id ( ) ) ;
3693
+
3694
+ nodes[ 3 ] . node . handle_revoke_and_ack ( & nodes[ 2 ] . node . get_our_node_id ( ) , & cs_raa) ;
3695
+ check_added_monitors ( & nodes[ 3 ] , 1 ) ;
3696
+
3697
+ nodes[ 3 ] . node . handle_commitment_signed ( & nodes[ 2 ] . node . get_our_node_id ( ) , & cs_cs) ;
3698
+ check_added_monitors ( & nodes[ 3 ] , 1 ) ;
3699
+
3700
+ let ds_raa = get_event_msg ! ( nodes[ 3 ] , MessageSendEvent :: SendRevokeAndACK , nodes[ 2 ] . node. get_our_node_id( ) ) ;
3701
+ nodes[ 2 ] . node . handle_revoke_and_ack ( & nodes[ 3 ] . node . get_our_node_id ( ) , & ds_raa) ;
3702
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
3703
+
3704
+ // Our current `ChannelMonitor`s store preimages one RAA longer than they need to. That's nice
3705
+ // for safety, but means we have to send one more payment here to wipe the preimage.
3706
+ assert ! ( get_monitor!( nodes[ 3 ] , chan_3_id) . get_stored_preimages( ) . contains_key( & payment_hash) ) ;
3707
+ assert ! ( get_monitor!( nodes[ 3 ] , chan_4_id) . get_stored_preimages( ) . contains_key( & payment_hash) ) ;
3708
+
3709
+ send_payment ( & nodes[ 1 ] , & [ & nodes[ 3 ] ] , 100_000 ) ;
3710
+ assert ! ( !get_monitor!( nodes[ 3 ] , chan_3_id) . get_stored_preimages( ) . contains_key( & payment_hash) ) ;
3711
+
3712
+ send_payment ( & nodes[ 2 ] , & [ & nodes[ 3 ] ] , 100_000 ) ;
3713
+ assert ! ( !get_monitor!( nodes[ 3 ] , chan_4_id) . get_stored_preimages( ) . contains_key( & payment_hash) ) ;
3714
+ }
0 commit comments