@@ -1403,6 +1403,7 @@ fn claim_while_disconnected_monitor_update_fail() {
14031403 MessageSendEvent :: UpdateHTLCs { ref node_id, ref updates } => {
14041404 assert_eq ! ( * node_id, nodes[ 0 ] . node. get_our_node_id( ) ) ;
14051405 nodes[ 0 ] . node . handle_update_fulfill_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & updates. update_fulfill_htlcs [ 0 ] ) ;
1406+ expect_payment_sent ( & nodes[ 0 ] , payment_preimage_1, None , false , false ) ;
14061407 nodes[ 0 ] . node . handle_commitment_signed ( & nodes[ 1 ] . node . get_our_node_id ( ) , & updates. commitment_signed ) ;
14071408 check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
14081409
@@ -1440,7 +1441,7 @@ fn claim_while_disconnected_monitor_update_fail() {
14401441
14411442 nodes[ 0 ] . node . handle_revoke_and_ack ( & nodes[ 1 ] . node . get_our_node_id ( ) , & bs_raa) ;
14421443 check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
1443- expect_payment_sent ! ( nodes[ 0 ] , payment_preimage_1 ) ;
1444+ expect_payment_path_successful ! ( nodes[ 0 ] ) ;
14441445
14451446 claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , payment_preimage_2) ;
14461447}
@@ -2196,7 +2197,7 @@ fn test_fail_htlc_on_broadcast_after_claim() {
21962197 expect_pending_htlcs_forwardable_and_htlc_handling_failed ! ( nodes[ 1 ] , vec![ HTLCDestination :: NextHopChannel { node_id: Some ( nodes[ 2 ] . node. get_our_node_id( ) ) , channel_id: chan_id_2 } ] ) ;
21972198
21982199 nodes[ 0 ] . node . handle_update_fulfill_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & bs_updates. update_fulfill_htlcs [ 0 ] ) ;
2199- expect_payment_sent_without_paths ! ( nodes[ 0 ] , payment_preimage) ;
2200+ expect_payment_sent ( & nodes[ 0 ] , payment_preimage, None , false , false ) ;
22002201 commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , bs_updates. commitment_signed, true , true ) ;
22012202 expect_payment_path_successful ! ( nodes[ 0 ] ) ;
22022203}
@@ -2449,7 +2450,7 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
24492450 assert ! ( updates. update_fee. is_none( ) ) ;
24502451 assert_eq ! ( updates. update_fulfill_htlcs. len( ) , 1 ) ;
24512452 nodes[ 1 ] . node . handle_update_fulfill_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & updates. update_fulfill_htlcs [ 0 ] ) ;
2452- expect_payment_sent_without_paths ! ( nodes[ 1 ] , payment_preimage_0) ;
2453+ expect_payment_sent ( & nodes[ 1 ] , payment_preimage_0, None , false , false ) ;
24532454 assert_eq ! ( updates. update_add_htlcs. len( ) , 1 ) ;
24542455 nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & updates. update_add_htlcs [ 0 ] ) ;
24552456 updates. commitment_signed
@@ -2466,7 +2467,7 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
24662467 expect_payment_claimable ! ( nodes[ 1 ] , payment_hash_1, payment_secret_1, 100000 ) ;
24672468 check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
24682469
2469- commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 0 ] , ( ) , false , true , false ) ;
2470+ commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 0 ] , ( ) , false , true , false , false ) ;
24702471
24712472 let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
24722473 assert_eq ! ( events. len( ) , 2 ) ;
@@ -2567,7 +2568,7 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim, second_f
25672568 bs_updates = Some ( get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ) ;
25682569 assert_eq ! ( bs_updates. as_ref( ) . unwrap( ) . update_fulfill_htlcs. len( ) , 1 ) ;
25692570 nodes[ 0 ] . node . handle_update_fulfill_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & bs_updates. as_ref ( ) . unwrap ( ) . update_fulfill_htlcs [ 0 ] ) ;
2570- expect_payment_sent_without_paths ! ( nodes[ 0 ] , payment_preimage) ;
2571+ expect_payment_sent ( & nodes[ 0 ] , payment_preimage, None , false , false ) ;
25712572 if htlc_status == HTLCStatusAtDupClaim :: Cleared {
25722573 commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , & bs_updates. as_ref( ) . unwrap( ) . commitment_signed, false ) ;
25732574 expect_payment_path_successful ! ( nodes[ 0 ] ) ;
@@ -2598,7 +2599,7 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim, second_f
25982599 bs_updates = Some ( get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ) ;
25992600 assert_eq ! ( bs_updates. as_ref( ) . unwrap( ) . update_fulfill_htlcs. len( ) , 1 ) ;
26002601 nodes[ 0 ] . node . handle_update_fulfill_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & bs_updates. as_ref ( ) . unwrap ( ) . update_fulfill_htlcs [ 0 ] ) ;
2601- expect_payment_sent_without_paths ! ( nodes[ 0 ] , payment_preimage) ;
2602+ expect_payment_sent ( & nodes[ 0 ] , payment_preimage, None , false , false ) ;
26022603 }
26032604 if htlc_status != HTLCStatusAtDupClaim :: Cleared {
26042605 commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , & bs_updates. as_ref( ) . unwrap( ) . commitment_signed, false ) ;
@@ -2797,7 +2798,7 @@ fn double_temp_error() {
27972798 assert_eq ! ( node_id, nodes[ 0 ] . node. get_our_node_id( ) ) ;
27982799 nodes[ 0 ] . node . handle_update_fulfill_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & update_fulfill_1) ;
27992800 check_added_monitors ! ( nodes[ 0 ] , 0 ) ;
2800- expect_payment_sent_without_paths ! ( nodes[ 0 ] , payment_preimage_1) ;
2801+ expect_payment_sent ( & nodes[ 0 ] , payment_preimage_1, None , false , false ) ;
28012802 nodes[ 0 ] . node . handle_commitment_signed ( & nodes[ 1 ] . node . get_our_node_id ( ) , & commitment_signed_b1) ;
28022803 check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
28032804 nodes[ 0 ] . node . process_pending_htlc_forwards ( ) ;
@@ -3024,3 +3025,67 @@ fn test_inbound_reload_without_init_mon() {
30243025 do_test_inbound_reload_without_init_mon ( false , true ) ;
30253026 do_test_inbound_reload_without_init_mon ( false , false ) ;
30263027}
3028+
3029+ #[ test]
3030+ fn test_blocked_chan_preimage_release ( ) {
3031+ // Test that even if a channel's `ChannelMonitorUpdate` flow is blocked waiting on an event to
3032+ // be handled HTLC preimage `ChannelMonitorUpdate`s will still go out.
3033+ let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
3034+ let node_cfgs = create_node_cfgs ( 3 , & chanmon_cfgs) ;
3035+ let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & [ None , None , None ] ) ;
3036+ let mut nodes = create_network ( 3 , & node_cfgs, & node_chanmgrs) ;
3037+
3038+ create_announced_chan_between_nodes ( & nodes, 0 , 1 ) . 2 ;
3039+ create_announced_chan_between_nodes ( & nodes, 1 , 2 ) . 2 ;
3040+
3041+ send_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , 5_000_000 ) ;
3042+
3043+ // Tee up two payments in opposite directions across nodes[1], one it sent to generate a
3044+ // PaymentSent event and one it forwards.
3045+ let ( payment_preimage_1, payment_hash_1, _) = route_payment ( & nodes[ 1 ] , & [ & nodes[ 2 ] ] , 1_000_000 ) ;
3046+ let ( payment_preimage_2, payment_hash_2, _) = route_payment ( & nodes[ 2 ] , & [ & nodes[ 1 ] , & nodes[ 0 ] ] , 1_000_000 ) ;
3047+
3048+ // Claim the first payment to get a `PaymentSent` event (but don't handle it yet).
3049+ nodes[ 2 ] . node . claim_funds ( payment_preimage_1) ;
3050+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
3051+ expect_payment_claimed ! ( nodes[ 2 ] , payment_hash_1, 1_000_000 ) ;
3052+
3053+ let cs_htlc_fulfill_updates = get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
3054+ nodes[ 1 ] . node . handle_update_fulfill_htlc ( & nodes[ 2 ] . node . get_our_node_id ( ) , & cs_htlc_fulfill_updates. update_fulfill_htlcs [ 0 ] ) ;
3055+ do_commitment_signed_dance ( & nodes[ 1 ] , & nodes[ 2 ] , & cs_htlc_fulfill_updates. commitment_signed , false , false ) ;
3056+ check_added_monitors ( & nodes[ 1 ] , 0 ) ;
3057+
3058+ // Now claim the second payment on nodes[0], which will ultimately result in nodes[1] trying to
3059+ // claim an HTLC on its channel with nodes[2], but that channel is blocked on the above
3060+ // `PaymentSent` event.
3061+ nodes[ 0 ] . node . claim_funds ( payment_preimage_2) ;
3062+ check_added_monitors ( & nodes[ 0 ] , 1 ) ;
3063+ expect_payment_claimed ! ( nodes[ 0 ] , payment_hash_2, 1_000_000 ) ;
3064+
3065+ let as_htlc_fulfill_updates = get_htlc_update_msgs ! ( nodes[ 0 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
3066+ nodes[ 1 ] . node . handle_update_fulfill_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & as_htlc_fulfill_updates. update_fulfill_htlcs [ 0 ] ) ;
3067+ check_added_monitors ( & nodes[ 1 ] , 1 ) ; // We generate only a preimage monitor update
3068+ assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
3069+
3070+ // Finish the CS dance between nodes[0] and nodes[1].
3071+ do_commitment_signed_dance ( & nodes[ 1 ] , & nodes[ 0 ] , & as_htlc_fulfill_updates. commitment_signed , false , false ) ;
3072+ check_added_monitors ( & nodes[ 1 ] , 0 ) ;
3073+
3074+ let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
3075+ assert_eq ! ( events. len( ) , 3 ) ;
3076+ if let Event :: PaymentSent { .. } = events[ 0 ] { } else { panic ! ( ) ; }
3077+ if let Event :: PaymentPathSuccessful { .. } = events[ 2 ] { } else { panic ! ( ) ; }
3078+ if let Event :: PaymentForwarded { .. } = events[ 1 ] { } else { panic ! ( ) ; }
3079+
3080+ // The event processing should release the last RAA update.
3081+ check_added_monitors ( & nodes[ 1 ] , 1 ) ;
3082+
3083+ // When we fetch the next update the message getter will generate the next update for nodes[2],
3084+ // generating a further monitor update.
3085+ let bs_htlc_fulfill_updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 2 ] . node. get_our_node_id( ) ) ;
3086+ check_added_monitors ( & nodes[ 1 ] , 1 ) ;
3087+
3088+ nodes[ 2 ] . node . handle_update_fulfill_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & bs_htlc_fulfill_updates. update_fulfill_htlcs [ 0 ] ) ;
3089+ do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & bs_htlc_fulfill_updates. commitment_signed , false , false ) ;
3090+ expect_payment_sent ( & nodes[ 2 ] , payment_preimage_2, None , true , true ) ;
3091+ }
0 commit comments