@@ -1403,6 +1403,7 @@ fn claim_while_disconnected_monitor_update_fail() {
1403
1403
MessageSendEvent :: UpdateHTLCs { ref node_id, ref updates } => {
1404
1404
assert_eq ! ( * node_id, nodes[ 0 ] . node. get_our_node_id( ) ) ;
1405
1405
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 ) ;
1406
1407
nodes[ 0 ] . node . handle_commitment_signed ( & nodes[ 1 ] . node . get_our_node_id ( ) , & updates. commitment_signed ) ;
1407
1408
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
1408
1409
@@ -1440,7 +1441,7 @@ fn claim_while_disconnected_monitor_update_fail() {
1440
1441
1441
1442
nodes[ 0 ] . node . handle_revoke_and_ack ( & nodes[ 1 ] . node . get_our_node_id ( ) , & bs_raa) ;
1442
1443
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
1443
- expect_payment_sent ! ( nodes[ 0 ] , payment_preimage_1 ) ;
1444
+ expect_payment_path_successful ! ( nodes[ 0 ] ) ;
1444
1445
1445
1446
claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , payment_preimage_2) ;
1446
1447
}
@@ -2196,7 +2197,7 @@ fn test_fail_htlc_on_broadcast_after_claim() {
2196
2197
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 } ] ) ;
2197
2198
2198
2199
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 ) ;
2200
2201
commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , bs_updates. commitment_signed, true , true ) ;
2201
2202
expect_payment_path_successful ! ( nodes[ 0 ] ) ;
2202
2203
}
@@ -2449,7 +2450,7 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
2449
2450
assert ! ( updates. update_fee. is_none( ) ) ;
2450
2451
assert_eq ! ( updates. update_fulfill_htlcs. len( ) , 1 ) ;
2451
2452
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 ) ;
2453
2454
assert_eq ! ( updates. update_add_htlcs. len( ) , 1 ) ;
2454
2455
nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & updates. update_add_htlcs [ 0 ] ) ;
2455
2456
updates. commitment_signed
@@ -2466,7 +2467,7 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
2466
2467
expect_payment_claimable ! ( nodes[ 1 ] , payment_hash_1, payment_secret_1, 100000 ) ;
2467
2468
check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
2468
2469
2469
- commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 0 ] , ( ) , false , true , false ) ;
2470
+ commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 0 ] , ( ) , false , true , false , false ) ;
2470
2471
2471
2472
let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
2472
2473
assert_eq ! ( events. len( ) , 2 ) ;
@@ -2567,7 +2568,7 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim, second_f
2567
2568
bs_updates = Some ( get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ) ;
2568
2569
assert_eq ! ( bs_updates. as_ref( ) . unwrap( ) . update_fulfill_htlcs. len( ) , 1 ) ;
2569
2570
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 ) ;
2571
2572
if htlc_status == HTLCStatusAtDupClaim :: Cleared {
2572
2573
commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , & bs_updates. as_ref( ) . unwrap( ) . commitment_signed, false ) ;
2573
2574
expect_payment_path_successful ! ( nodes[ 0 ] ) ;
@@ -2598,7 +2599,7 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim, second_f
2598
2599
bs_updates = Some ( get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ) ;
2599
2600
assert_eq ! ( bs_updates. as_ref( ) . unwrap( ) . update_fulfill_htlcs. len( ) , 1 ) ;
2600
2601
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 ) ;
2602
2603
}
2603
2604
if htlc_status != HTLCStatusAtDupClaim :: Cleared {
2604
2605
commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , & bs_updates. as_ref( ) . unwrap( ) . commitment_signed, false ) ;
@@ -2797,7 +2798,7 @@ fn double_temp_error() {
2797
2798
assert_eq ! ( node_id, nodes[ 0 ] . node. get_our_node_id( ) ) ;
2798
2799
nodes[ 0 ] . node . handle_update_fulfill_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & update_fulfill_1) ;
2799
2800
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 ) ;
2801
2802
nodes[ 0 ] . node . handle_commitment_signed ( & nodes[ 1 ] . node . get_our_node_id ( ) , & commitment_signed_b1) ;
2802
2803
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
2803
2804
nodes[ 0 ] . node . process_pending_htlc_forwards ( ) ;
@@ -3024,3 +3025,67 @@ fn test_inbound_reload_without_init_mon() {
3024
3025
do_test_inbound_reload_without_init_mon ( false , true ) ;
3025
3026
do_test_inbound_reload_without_init_mon ( false , false ) ;
3026
3027
}
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