@@ -2756,16 +2756,16 @@ fn test_htlc_on_chain_success() {
2756
2756
added_monitors.clear();
2757
2757
}
2758
2758
assert_eq!(events.len(), 3);
2759
- match events [ 0 ] {
2760
- MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
2761
- _ => panic ! ( "Unexpected event" ) ,
2762
- }
2763
- match events [ 1 ] {
2759
+
2760
+ let (nodes_2_event, events) = remove_first_msg_event_to_node(&nodes[2].node.get_our_node_id(), &events);
2761
+ let (nodes_0_event, events) = remove_first_msg_event_to_node(&nodes[0].node.get_our_node_id(), &events);
2762
+
2763
+ match nodes_2_event {
2764
2764
MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { .. }, node_id: _ } => {},
2765
2765
_ => panic!("Unexpected event"),
2766
2766
}
2767
2767
2768
- match events [ 2 ] {
2768
+ match nodes_0_event {
2769
2769
MessageSendEvent::UpdateHTLCs { ref node_id, updates: msgs::CommitmentUpdate { ref update_add_htlcs, ref update_fail_htlcs, ref update_fulfill_htlcs, ref update_fail_malformed_htlcs, .. } } => {
2770
2770
assert!(update_add_htlcs.is_empty());
2771
2771
assert!(update_fail_htlcs.is_empty());
@@ -2775,6 +2775,13 @@ fn test_htlc_on_chain_success() {
2775
2775
},
2776
2776
_ => panic!("Unexpected event"),
2777
2777
};
2778
+
2779
+ // Ensure that the last remaining message event is the BroadcastChannelUpdate msg for chan_2
2780
+ match events[0] {
2781
+ MessageSendEvent::BroadcastChannelUpdate { .. } => {},
2782
+ _ => panic!("Unexpected event"),
2783
+ }
2784
+
2778
2785
macro_rules! check_tx_local_broadcast {
2779
2786
($node: expr, $htlc_offered: expr, $commitment_tx: expr) => { {
2780
2787
let mut node_txn = $node.tx_broadcaster.txn_broadcasted.lock().unwrap();
@@ -3192,21 +3199,12 @@ fn do_test_commitment_revoked_fail_backward_exhaustive(deliver_bs_raa: bool, use
3192
3199
nodes[1].node.process_pending_htlc_forwards();
3193
3200
check_added_monitors!(nodes[1], 1);
3194
3201
3195
- let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
3202
+ let mut events = nodes[1].node.get_and_clear_pending_msg_events();
3196
3203
assert_eq!(events.len(), if deliver_bs_raa { 4 } else { 3 });
3197
- match events[ if deliver_bs_raa { 1 } else { 0 } ] {
3198
- MessageSendEvent :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
3199
- _ => panic ! ( "Unexpected event" ) ,
3200
- }
3201
- match events[ if deliver_bs_raa { 2 } else { 1 } ] {
3202
- MessageSendEvent :: HandleError { action : ErrorAction :: SendErrorMessage { msg : msgs:: ErrorMessage { channel_id, ref data } } , node_id : _ } => {
3203
- assert_eq ! ( channel_id, chan_2. 2 ) ;
3204
- assert_eq ! ( data. as_str( ) , "Channel closed because commitment or closing transaction was confirmed on chain." ) ;
3205
- } ,
3206
- _ => panic ! ( "Unexpected event" ) ,
3207
- }
3208
- if deliver_bs_raa {
3209
- match events[ 0 ] {
3204
+
3205
+ let events = if deliver_bs_raa {
3206
+ let (nodes_2_event, events) = remove_first_msg_event_to_node(&nodes[2].node.get_our_node_id(), &events);
3207
+ match nodes_2_event {
3210
3208
MessageSendEvent::UpdateHTLCs { ref node_id, updates: msgs::CommitmentUpdate { ref update_add_htlcs, ref update_fail_htlcs, ref update_fulfill_htlcs, ref update_fail_malformed_htlcs, .. } } => {
3211
3209
assert_eq!(nodes[2].node.get_our_node_id(), *node_id);
3212
3210
assert_eq!(update_add_htlcs.len(), 1);
@@ -3216,8 +3214,20 @@ fn do_test_commitment_revoked_fail_backward_exhaustive(deliver_bs_raa: bool, use
3216
3214
},
3217
3215
_ => panic!("Unexpected event"),
3218
3216
}
3217
+ events
3218
+ } else { events };
3219
+
3220
+ let (nodes_2_event, events) = remove_first_msg_event_to_node(&nodes[2].node.get_our_node_id(), &events);
3221
+ match nodes_2_event {
3222
+ MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { msg: msgs::ErrorMessage { channel_id, ref data } }, node_id: _ } => {
3223
+ assert_eq!(channel_id, chan_2.2);
3224
+ assert_eq!(data.as_str(), "Channel closed because commitment or closing transaction was confirmed on chain.");
3225
+ },
3226
+ _ => panic!("Unexpected event"),
3219
3227
}
3220
- match events[ if deliver_bs_raa { 3 } else { 2 } ] {
3228
+
3229
+ let (nodes_0_event, events) = remove_first_msg_event_to_node(&nodes[0].node.get_our_node_id(), &events);
3230
+ match nodes_0_event {
3221
3231
MessageSendEvent::UpdateHTLCs { ref node_id, updates: msgs::CommitmentUpdate { ref update_add_htlcs, ref update_fail_htlcs, ref update_fulfill_htlcs, ref update_fail_malformed_htlcs, ref commitment_signed, .. } } => {
3222
3232
assert!(update_add_htlcs.is_empty());
3223
3233
assert_eq!(update_fail_htlcs.len(), 3);
@@ -3262,6 +3272,12 @@ fn do_test_commitment_revoked_fail_backward_exhaustive(deliver_bs_raa: bool, use
3262
3272
_ => panic!("Unexpected event"),
3263
3273
}
3264
3274
3275
+ // Ensure that the last remaining message event is the BroadcastChannelUpdate msg for chan_2
3276
+ match events[0] {
3277
+ MessageSendEvent::BroadcastChannelUpdate { msg: msgs::ChannelUpdate { .. } } => {},
3278
+ _ => panic!("Unexpected event"),
3279
+ }
3280
+
3265
3281
assert!(failed_htlcs.contains(&first_payment_hash.0));
3266
3282
assert!(failed_htlcs.contains(&second_payment_hash.0));
3267
3283
assert!(failed_htlcs.contains(&third_payment_hash.0));
@@ -4627,15 +4643,15 @@ fn test_onchain_to_onchain_claim() {
4627
4643
check_added_monitors!(nodes[1], 1);
4628
4644
let msg_events = nodes[1].node.get_and_clear_pending_msg_events();
4629
4645
assert_eq!(msg_events.len(), 3);
4630
- match msg_events[ 0 ] {
4631
- MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
4632
- _ => panic ! ( "Unexpected event" ) ,
4633
- }
4634
- match msg_events[ 1 ] {
4646
+ let (nodes_2_event, msg_events) = remove_first_msg_event_to_node(&nodes[2].node.get_our_node_id(), &msg_events);
4647
+ let (nodes_0_event, msg_events) = remove_first_msg_event_to_node(&nodes[0].node.get_our_node_id(), &msg_events);
4648
+
4649
+ match nodes_2_event {
4635
4650
MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { .. }, node_id: _ } => {},
4636
4651
_ => panic!("Unexpected event"),
4637
4652
}
4638
- match msg_events[ 2 ] {
4653
+
4654
+ match nodes_0_event {
4639
4655
MessageSendEvent::UpdateHTLCs { ref node_id, updates: msgs::CommitmentUpdate { ref update_add_htlcs, ref update_fulfill_htlcs, ref update_fail_htlcs, ref update_fail_malformed_htlcs, .. } } => {
4640
4656
assert!(update_add_htlcs.is_empty());
4641
4657
assert!(update_fail_htlcs.is_empty());
@@ -4645,6 +4661,13 @@ fn test_onchain_to_onchain_claim() {
4645
4661
},
4646
4662
_ => panic!("Unexpected event"),
4647
4663
};
4664
+
4665
+ // Ensure that the last remaining message event is the BroadcastChannelUpdate msg for chan_2
4666
+ match msg_events[0] {
4667
+ MessageSendEvent::BroadcastChannelUpdate { .. } => {},
4668
+ _ => panic!("Unexpected event"),
4669
+ }
4670
+
4648
4671
// Broadcast A's commitment tx on B's chain to see if we are able to claim inbound HTLC with our HTLC-Success tx
4649
4672
let commitment_tx = get_local_commitment_txn!(nodes[0], chan_1.2);
4650
4673
mine_transaction(&nodes[1], &commitment_tx[0]);
@@ -9254,7 +9277,8 @@ fn test_double_partial_claim() {
9254
9277
9255
9278
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
9256
9279
assert_eq!(events.len(), 2);
9257
- pass_along_path ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 3 ] ] , 15_000_000 , payment_hash, Some ( payment_secret) , events. drain ( ..) . next ( ) . unwrap ( ) , false , None ) ;
9280
+ let (node_1_msgs, _events) = remove_first_msg_event_to_node(&nodes[1].node.get_our_node_id(), &events);
9281
+ pass_along_path(&nodes[0], &[&nodes[1], &nodes[3]], 15_000_000, payment_hash, Some(payment_secret), node_1_msgs, false, None);
9258
9282
9259
9283
// At this point nodes[3] has received one half of the payment, and the user goes to handle
9260
9284
// that PaymentClaimable event they got hours ago and never handled...we should refuse to claim.
0 commit comments