@@ -2501,9 +2501,10 @@ impl ChannelMessageHandler for ChannelManager {
2501
2501
}
2502
2502
}
2503
2503
2504
- fn peer_connected ( & self , their_node_id : & PublicKey ) -> Vec < msgs:: ChannelReestablish > {
2505
- let mut res = Vec :: new ( ) ;
2506
- let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
2504
+ fn peer_connected ( & self , their_node_id : & PublicKey ) {
2505
+ let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
2506
+ let channel_state = channel_state_lock. borrow_parts ( ) ;
2507
+ let pending_msg_events = channel_state. pending_msg_events ;
2507
2508
channel_state. by_id . retain ( |_, chan| {
2508
2509
if chan. get_their_node_id ( ) == * their_node_id {
2509
2510
if !chan. have_received_message ( ) {
@@ -2513,13 +2514,15 @@ impl ChannelMessageHandler for ChannelManager {
2513
2514
// drop it.
2514
2515
false
2515
2516
} else {
2516
- res. push ( chan. get_channel_reestablish ( ) ) ;
2517
+ pending_msg_events. push ( events:: MessageSendEvent :: SendChannelReestablish {
2518
+ node_id : chan. get_their_node_id ( ) ,
2519
+ msg : chan. get_channel_reestablish ( ) ,
2520
+ } ) ;
2517
2521
true
2518
2522
}
2519
2523
} else { true }
2520
2524
} ) ;
2521
2525
//TODO: Also re-broadcast announcement_signatures
2522
- res
2523
2526
}
2524
2527
2525
2528
fn handle_error ( & self , their_node_id : & PublicKey , msg : & msgs:: ErrorMessage ) {
@@ -5011,6 +5014,23 @@ mod tests {
5011
5014
assert_eq ! ( channel_state. short_to_id. len( ) , 0 ) ;
5012
5015
}
5013
5016
5017
+ macro_rules! get_chan_reestablish_msgs {
5018
+ ( $src_node: expr, $dst_node: expr) => {
5019
+ {
5020
+ let mut res = Vec :: with_capacity( 1 ) ;
5021
+ for msg in $src_node. node. get_and_clear_pending_msg_events( ) {
5022
+ if let MessageSendEvent :: SendChannelReestablish { ref node_id, ref msg } = msg {
5023
+ assert_eq!( * node_id, $dst_node. node. get_our_node_id( ) ) ;
5024
+ res. push( msg. clone( ) ) ;
5025
+ } else {
5026
+ panic!( "Unexpected event" )
5027
+ }
5028
+ }
5029
+ res
5030
+ }
5031
+ }
5032
+ }
5033
+
5014
5034
macro_rules! handle_chan_reestablish_msgs {
5015
5035
( $src_node: expr, $dst_node: expr) => {
5016
5036
{
@@ -5069,8 +5089,10 @@ mod tests {
5069
5089
/// pending_htlc_adds includes both the holding cell and in-flight update_add_htlcs, whereas
5070
5090
/// for claims/fails they are separated out.
5071
5091
fn reconnect_nodes ( node_a : & Node , node_b : & Node , pre_all_htlcs : bool , pending_htlc_adds : ( i64 , i64 ) , pending_htlc_claims : ( usize , usize ) , pending_cell_htlc_claims : ( usize , usize ) , pending_cell_htlc_fails : ( usize , usize ) , pending_raa : ( bool , bool ) ) {
5072
- let reestablish_1 = node_a. node . peer_connected ( & node_b. node . get_our_node_id ( ) ) ;
5073
- let reestablish_2 = node_b. node . peer_connected ( & node_a. node . get_our_node_id ( ) ) ;
5092
+ node_a. node . peer_connected ( & node_b. node . get_our_node_id ( ) ) ;
5093
+ let reestablish_1 = get_chan_reestablish_msgs ! ( node_a, node_b) ;
5094
+ node_b. node . peer_connected ( & node_a. node . get_our_node_id ( ) ) ;
5095
+ let reestablish_2 = get_chan_reestablish_msgs ! ( node_b, node_a) ;
5074
5096
5075
5097
let mut resp_1 = Vec :: new ( ) ;
5076
5098
for msg in reestablish_1 {
@@ -5567,9 +5589,11 @@ mod tests {
5567
5589
nodes[ 0 ] . node . peer_disconnected ( & nodes[ 1 ] . node . get_our_node_id ( ) , false ) ;
5568
5590
nodes[ 1 ] . node . peer_disconnected ( & nodes[ 0 ] . node . get_our_node_id ( ) , false ) ;
5569
5591
5570
- let reestablish_1 = nodes[ 0 ] . node . peer_connected ( & nodes[ 1 ] . node . get_our_node_id ( ) ) ;
5592
+ nodes[ 0 ] . node . peer_connected ( & nodes[ 1 ] . node . get_our_node_id ( ) ) ;
5593
+ let reestablish_1 = get_chan_reestablish_msgs ! ( nodes[ 0 ] , nodes[ 1 ] ) ;
5571
5594
assert_eq ! ( reestablish_1. len( ) , 1 ) ;
5572
- let reestablish_2 = nodes[ 1 ] . node . peer_connected ( & nodes[ 0 ] . node . get_our_node_id ( ) ) ;
5595
+ nodes[ 1 ] . node . peer_connected ( & nodes[ 0 ] . node . get_our_node_id ( ) ) ;
5596
+ let reestablish_2 = get_chan_reestablish_msgs ! ( nodes[ 1 ] , nodes[ 0 ] ) ;
5573
5597
assert_eq ! ( reestablish_2. len( ) , 1 ) ;
5574
5598
5575
5599
nodes[ 0 ] . node . handle_channel_reestablish ( & nodes[ 1 ] . node . get_our_node_id ( ) , & reestablish_2[ 0 ] ) . unwrap ( ) ;
@@ -5855,9 +5879,11 @@ mod tests {
5855
5879
nodes[ 0 ] . node. peer_disconnected( & nodes[ 1 ] . node. get_our_node_id( ) , false ) ;
5856
5880
nodes[ 1 ] . node. peer_disconnected( & nodes[ 0 ] . node. get_our_node_id( ) , false ) ;
5857
5881
5858
- let reestablish_1 = nodes[ 0 ] . node. peer_connected( & nodes[ 1 ] . node. get_our_node_id( ) ) ;
5882
+ nodes[ 0 ] . node. peer_connected( & nodes[ 1 ] . node. get_our_node_id( ) ) ;
5883
+ let reestablish_1 = get_chan_reestablish_msgs!( nodes[ 0 ] , nodes[ 1 ] ) ;
5859
5884
assert_eq!( reestablish_1. len( ) , 1 ) ;
5860
- let reestablish_2 = nodes[ 1 ] . node. peer_connected( & nodes[ 0 ] . node. get_our_node_id( ) ) ;
5885
+ nodes[ 1 ] . node. peer_connected( & nodes[ 0 ] . node. get_our_node_id( ) ) ;
5886
+ let reestablish_2 = get_chan_reestablish_msgs!( nodes[ 1 ] , nodes[ 0 ] ) ;
5861
5887
assert_eq!( reestablish_2. len( ) , 1 ) ;
5862
5888
5863
5889
nodes[ 0 ] . node. handle_channel_reestablish( & nodes[ 1 ] . node. get_our_node_id( ) , & reestablish_2[ 0 ] ) . unwrap( ) ;
@@ -5875,9 +5901,11 @@ mod tests {
5875
5901
assert ! ( nodes[ 0 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
5876
5902
assert ! ( nodes[ 0 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
5877
5903
5878
- let reestablish_1 = nodes[ 0 ] . node . peer_connected ( & nodes[ 1 ] . node . get_our_node_id ( ) ) ;
5904
+ nodes[ 0 ] . node . peer_connected ( & nodes[ 1 ] . node . get_our_node_id ( ) ) ;
5905
+ let reestablish_1 = get_chan_reestablish_msgs ! ( nodes[ 0 ] , nodes[ 1 ] ) ;
5879
5906
assert_eq ! ( reestablish_1. len( ) , 1 ) ;
5880
- let reestablish_2 = nodes[ 1 ] . node . peer_connected ( & nodes[ 0 ] . node . get_our_node_id ( ) ) ;
5907
+ nodes[ 1 ] . node . peer_connected ( & nodes[ 0 ] . node . get_our_node_id ( ) ) ;
5908
+ let reestablish_2 = get_chan_reestablish_msgs ! ( nodes[ 1 ] , nodes[ 0 ] ) ;
5881
5909
assert_eq ! ( reestablish_2. len( ) , 1 ) ;
5882
5910
5883
5911
nodes[ 0 ] . node . handle_channel_reestablish ( & nodes[ 1 ] . node . get_our_node_id ( ) , & reestablish_2[ 0 ] ) . unwrap ( ) ;
0 commit comments