@@ -2703,9 +2703,10 @@ impl ChannelMessageHandler for ChannelManager {
27032703 }
27042704 }
27052705
2706- fn peer_connected ( & self , their_node_id : & PublicKey ) -> Vec < msgs:: ChannelReestablish > {
2707- let mut res = Vec :: new ( ) ;
2708- let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
2706+ fn peer_connected ( & self , their_node_id : & PublicKey ) {
2707+ let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
2708+ let channel_state = channel_state_lock. borrow_parts ( ) ;
2709+ let pending_msg_events = channel_state. pending_msg_events ;
27092710 channel_state. by_id . retain ( |_, chan| {
27102711 if chan. get_their_node_id ( ) == * their_node_id {
27112712 if !chan. have_received_message ( ) {
@@ -2715,13 +2716,15 @@ impl ChannelMessageHandler for ChannelManager {
27152716 // drop it.
27162717 false
27172718 } else {
2718- res. push ( chan. get_channel_reestablish ( ) ) ;
2719+ pending_msg_events. push ( events:: MessageSendEvent :: SendChannelReestablish {
2720+ node_id : chan. get_their_node_id ( ) ,
2721+ msg : chan. get_channel_reestablish ( ) ,
2722+ } ) ;
27192723 true
27202724 }
27212725 } else { true }
27222726 } ) ;
27232727 //TODO: Also re-broadcast announcement_signatures
2724- res
27252728 }
27262729
27272730 fn handle_error ( & self , their_node_id : & PublicKey , msg : & msgs:: ErrorMessage ) {
@@ -5224,6 +5227,23 @@ mod tests {
52245227 assert_eq ! ( channel_state. short_to_id. len( ) , 0 ) ;
52255228 }
52265229
5230+ macro_rules! get_chan_reestablish_msgs {
5231+ ( $src_node: expr, $dst_node: expr) => {
5232+ {
5233+ let mut res = Vec :: with_capacity( 1 ) ;
5234+ for msg in $src_node. node. get_and_clear_pending_msg_events( ) {
5235+ if let MessageSendEvent :: SendChannelReestablish { ref node_id, ref msg } = msg {
5236+ assert_eq!( * node_id, $dst_node. node. get_our_node_id( ) ) ;
5237+ res. push( msg. clone( ) ) ;
5238+ } else {
5239+ panic!( "Unexpected event" )
5240+ }
5241+ }
5242+ res
5243+ }
5244+ }
5245+ }
5246+
52275247 macro_rules! handle_chan_reestablish_msgs {
52285248 ( $src_node: expr, $dst_node: expr) => {
52295249 {
@@ -5282,8 +5302,10 @@ mod tests {
52825302 /// pending_htlc_adds includes both the holding cell and in-flight update_add_htlcs, whereas
52835303 /// for claims/fails they are separated out.
52845304 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 ) ) {
5285- let reestablish_1 = node_a. node . peer_connected ( & node_b. node . get_our_node_id ( ) ) ;
5286- let reestablish_2 = node_b. node . peer_connected ( & node_a. node . get_our_node_id ( ) ) ;
5305+ node_a. node . peer_connected ( & node_b. node . get_our_node_id ( ) ) ;
5306+ let reestablish_1 = get_chan_reestablish_msgs ! ( node_a, node_b) ;
5307+ node_b. node . peer_connected ( & node_a. node . get_our_node_id ( ) ) ;
5308+ let reestablish_2 = get_chan_reestablish_msgs ! ( node_b, node_a) ;
52875309
52885310 let mut resp_1 = Vec :: new ( ) ;
52895311 for msg in reestablish_1 {
@@ -5781,9 +5803,11 @@ mod tests {
57815803 nodes[ 0 ] . node . peer_disconnected ( & nodes[ 1 ] . node . get_our_node_id ( ) , false ) ;
57825804 nodes[ 1 ] . node . peer_disconnected ( & nodes[ 0 ] . node . get_our_node_id ( ) , false ) ;
57835805
5784- let reestablish_1 = nodes[ 0 ] . node . peer_connected ( & nodes[ 1 ] . node . get_our_node_id ( ) ) ;
5806+ nodes[ 0 ] . node . peer_connected ( & nodes[ 1 ] . node . get_our_node_id ( ) ) ;
5807+ let reestablish_1 = get_chan_reestablish_msgs ! ( nodes[ 0 ] , nodes[ 1 ] ) ;
57855808 assert_eq ! ( reestablish_1. len( ) , 1 ) ;
5786- let reestablish_2 = nodes[ 1 ] . node . peer_connected ( & nodes[ 0 ] . node . get_our_node_id ( ) ) ;
5809+ nodes[ 1 ] . node . peer_connected ( & nodes[ 0 ] . node . get_our_node_id ( ) ) ;
5810+ let reestablish_2 = get_chan_reestablish_msgs ! ( nodes[ 1 ] , nodes[ 0 ] ) ;
57875811 assert_eq ! ( reestablish_2. len( ) , 1 ) ;
57885812
57895813 nodes[ 0 ] . node . handle_channel_reestablish ( & nodes[ 1 ] . node . get_our_node_id ( ) , & reestablish_2[ 0 ] ) . unwrap ( ) ;
@@ -6069,9 +6093,11 @@ mod tests {
60696093 nodes[ 0 ] . node. peer_disconnected( & nodes[ 1 ] . node. get_our_node_id( ) , false ) ;
60706094 nodes[ 1 ] . node. peer_disconnected( & nodes[ 0 ] . node. get_our_node_id( ) , false ) ;
60716095
6072- let reestablish_1 = nodes[ 0 ] . node. peer_connected( & nodes[ 1 ] . node. get_our_node_id( ) ) ;
6096+ nodes[ 0 ] . node. peer_connected( & nodes[ 1 ] . node. get_our_node_id( ) ) ;
6097+ let reestablish_1 = get_chan_reestablish_msgs!( nodes[ 0 ] , nodes[ 1 ] ) ;
60736098 assert_eq!( reestablish_1. len( ) , 1 ) ;
6074- let reestablish_2 = nodes[ 1 ] . node. peer_connected( & nodes[ 0 ] . node. get_our_node_id( ) ) ;
6099+ nodes[ 1 ] . node. peer_connected( & nodes[ 0 ] . node. get_our_node_id( ) ) ;
6100+ let reestablish_2 = get_chan_reestablish_msgs!( nodes[ 1 ] , nodes[ 0 ] ) ;
60756101 assert_eq!( reestablish_2. len( ) , 1 ) ;
60766102
60776103 nodes[ 0 ] . node. handle_channel_reestablish( & nodes[ 1 ] . node. get_our_node_id( ) , & reestablish_2[ 0 ] ) . unwrap( ) ;
@@ -6089,9 +6115,11 @@ mod tests {
60896115 assert ! ( nodes[ 0 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
60906116 assert ! ( nodes[ 0 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
60916117
6092- let reestablish_1 = nodes[ 0 ] . node . peer_connected ( & nodes[ 1 ] . node . get_our_node_id ( ) ) ;
6118+ nodes[ 0 ] . node . peer_connected ( & nodes[ 1 ] . node . get_our_node_id ( ) ) ;
6119+ let reestablish_1 = get_chan_reestablish_msgs ! ( nodes[ 0 ] , nodes[ 1 ] ) ;
60936120 assert_eq ! ( reestablish_1. len( ) , 1 ) ;
6094- let reestablish_2 = nodes[ 1 ] . node . peer_connected ( & nodes[ 0 ] . node . get_our_node_id ( ) ) ;
6121+ nodes[ 1 ] . node . peer_connected ( & nodes[ 0 ] . node . get_our_node_id ( ) ) ;
6122+ let reestablish_2 = get_chan_reestablish_msgs ! ( nodes[ 1 ] , nodes[ 0 ] ) ;
60956123 assert_eq ! ( reestablish_2. len( ) , 1 ) ;
60966124
60976125 nodes[ 0 ] . node . handle_channel_reestablish ( & nodes[ 1 ] . node . get_our_node_id ( ) , & reestablish_2[ 0 ] ) . unwrap ( ) ;
0 commit comments