@@ -2756,16 +2756,16 @@ fn test_htlc_on_chain_success() {
27562756 added_monitors.clear();
27572757 }
27582758 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 {
27642764 MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { .. }, node_id: _ } => {},
27652765 _ => panic!("Unexpected event"),
27662766 }
27672767
2768- match events [ 2 ] {
2768+ match nodes_0_event {
27692769 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, .. } } => {
27702770 assert!(update_add_htlcs.is_empty());
27712771 assert!(update_fail_htlcs.is_empty());
@@ -2775,6 +2775,13 @@ fn test_htlc_on_chain_success() {
27752775 },
27762776 _ => panic!("Unexpected event"),
27772777 };
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+
27782785 macro_rules! check_tx_local_broadcast {
27792786 ($node: expr, $htlc_offered: expr, $commitment_tx: expr) => { {
27802787 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
31923199 nodes[1].node.process_pending_htlc_forwards();
31933200 check_added_monitors!(nodes[1], 1);
31943201
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();
31963203 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 {
32103208 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, .. } } => {
32113209 assert_eq!(nodes[2].node.get_our_node_id(), *node_id);
32123210 assert_eq!(update_add_htlcs.len(), 1);
@@ -3216,8 +3214,20 @@ fn do_test_commitment_revoked_fail_backward_exhaustive(deliver_bs_raa: bool, use
32163214 },
32173215 _ => panic!("Unexpected event"),
32183216 }
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"),
32193227 }
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 {
32213231 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, .. } } => {
32223232 assert!(update_add_htlcs.is_empty());
32233233 assert_eq!(update_fail_htlcs.len(), 3);
@@ -3262,6 +3272,12 @@ fn do_test_commitment_revoked_fail_backward_exhaustive(deliver_bs_raa: bool, use
32623272 _ => panic!("Unexpected event"),
32633273 }
32643274
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+
32653281 assert!(failed_htlcs.contains(&first_payment_hash.0));
32663282 assert!(failed_htlcs.contains(&second_payment_hash.0));
32673283 assert!(failed_htlcs.contains(&third_payment_hash.0));
@@ -4627,15 +4643,15 @@ fn test_onchain_to_onchain_claim() {
46274643 check_added_monitors!(nodes[1], 1);
46284644 let msg_events = nodes[1].node.get_and_clear_pending_msg_events();
46294645 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 {
46354650 MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { .. }, node_id: _ } => {},
46364651 _ => panic!("Unexpected event"),
46374652 }
4638- match msg_events[ 2 ] {
4653+
4654+ match nodes_0_event {
46394655 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, .. } } => {
46404656 assert!(update_add_htlcs.is_empty());
46414657 assert!(update_fail_htlcs.is_empty());
@@ -4645,6 +4661,13 @@ fn test_onchain_to_onchain_claim() {
46454661 },
46464662 _ => panic!("Unexpected event"),
46474663 };
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+
46484671 // Broadcast A's commitment tx on B's chain to see if we are able to claim inbound HTLC with our HTLC-Success tx
46494672 let commitment_tx = get_local_commitment_txn!(nodes[0], chan_1.2);
46504673 mine_transaction(&nodes[1], &commitment_tx[0]);
@@ -9254,7 +9277,8 @@ fn test_double_partial_claim() {
92549277
92559278 let mut events = nodes[0].node.get_and_clear_pending_msg_events();
92569279 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);
92589282
92599283 // At this point nodes[3] has received one half of the payment, and the user goes to handle
92609284 // that PaymentClaimable event they got hours ago and never handled...we should refuse to claim.
0 commit comments