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