@@ -2676,9 +2676,10 @@ impl ChannelMessageHandler for ChannelManager {
26762676 }
26772677 }
26782678
2679- fn peer_connected ( & self , their_node_id : & PublicKey ) -> Vec < msgs:: ChannelReestablish > {
2680- let mut res = Vec :: new ( ) ;
2681- let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
2679+ fn peer_connected ( & self , their_node_id : & PublicKey ) {
2680+ let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
2681+ let channel_state = channel_state_lock. borrow_parts ( ) ;
2682+ let pending_msg_events = channel_state. pending_msg_events ;
26822683 channel_state. by_id . retain ( |_, chan| {
26832684 if chan. get_their_node_id ( ) == * their_node_id {
26842685 if !chan. have_received_message ( ) {
@@ -2688,13 +2689,15 @@ impl ChannelMessageHandler for ChannelManager {
26882689 // drop it.
26892690 false
26902691 } else {
2691- res. push ( chan. get_channel_reestablish ( ) ) ;
2692+ pending_msg_events. push ( events:: MessageSendEvent :: SendChannelReestablish {
2693+ node_id : chan. get_their_node_id ( ) ,
2694+ msg : chan. get_channel_reestablish ( ) ,
2695+ } ) ;
26922696 true
26932697 }
26942698 } else { true }
26952699 } ) ;
26962700 //TODO: Also re-broadcast announcement_signatures
2697- res
26982701 }
26992702
27002703 fn handle_error ( & self , their_node_id : & PublicKey , msg : & msgs:: ErrorMessage ) {
@@ -5197,6 +5200,23 @@ mod tests {
51975200 assert_eq ! ( channel_state. short_to_id. len( ) , 0 ) ;
51985201 }
51995202
5203+ macro_rules! get_chan_reestablish_msgs {
5204+ ( $src_node: expr, $dst_node: expr) => {
5205+ {
5206+ let mut res = Vec :: with_capacity( 1 ) ;
5207+ for msg in $src_node. node. get_and_clear_pending_msg_events( ) {
5208+ if let MessageSendEvent :: SendChannelReestablish { ref node_id, ref msg } = msg {
5209+ assert_eq!( * node_id, $dst_node. node. get_our_node_id( ) ) ;
5210+ res. push( msg. clone( ) ) ;
5211+ } else {
5212+ panic!( "Unexpected event" )
5213+ }
5214+ }
5215+ res
5216+ }
5217+ }
5218+ }
5219+
52005220 macro_rules! handle_chan_reestablish_msgs {
52015221 ( $src_node: expr, $dst_node: expr) => {
52025222 {
@@ -5255,8 +5275,10 @@ mod tests {
52555275 /// pending_htlc_adds includes both the holding cell and in-flight update_add_htlcs, whereas
52565276 /// for claims/fails they are separated out.
52575277 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 ) ) {
5258- let reestablish_1 = node_a. node . peer_connected ( & node_b. node . get_our_node_id ( ) ) ;
5259- let reestablish_2 = node_b. node . peer_connected ( & node_a. node . get_our_node_id ( ) ) ;
5278+ node_a. node . peer_connected ( & node_b. node . get_our_node_id ( ) ) ;
5279+ let reestablish_1 = get_chan_reestablish_msgs ! ( node_a, node_b) ;
5280+ node_b. node . peer_connected ( & node_a. node . get_our_node_id ( ) ) ;
5281+ let reestablish_2 = get_chan_reestablish_msgs ! ( node_b, node_a) ;
52605282
52615283 let mut resp_1 = Vec :: new ( ) ;
52625284 for msg in reestablish_1 {
@@ -5754,9 +5776,11 @@ mod tests {
57545776 nodes[ 0 ] . node . peer_disconnected ( & nodes[ 1 ] . node . get_our_node_id ( ) , false ) ;
57555777 nodes[ 1 ] . node . peer_disconnected ( & nodes[ 0 ] . node . get_our_node_id ( ) , false ) ;
57565778
5757- let reestablish_1 = nodes[ 0 ] . node . peer_connected ( & nodes[ 1 ] . node . get_our_node_id ( ) ) ;
5779+ nodes[ 0 ] . node . peer_connected ( & nodes[ 1 ] . node . get_our_node_id ( ) ) ;
5780+ let reestablish_1 = get_chan_reestablish_msgs ! ( nodes[ 0 ] , nodes[ 1 ] ) ;
57585781 assert_eq ! ( reestablish_1. len( ) , 1 ) ;
5759- let reestablish_2 = nodes[ 1 ] . node . peer_connected ( & nodes[ 0 ] . node . get_our_node_id ( ) ) ;
5782+ nodes[ 1 ] . node . peer_connected ( & nodes[ 0 ] . node . get_our_node_id ( ) ) ;
5783+ let reestablish_2 = get_chan_reestablish_msgs ! ( nodes[ 1 ] , nodes[ 0 ] ) ;
57605784 assert_eq ! ( reestablish_2. len( ) , 1 ) ;
57615785
57625786 nodes[ 0 ] . node . handle_channel_reestablish ( & nodes[ 1 ] . node . get_our_node_id ( ) , & reestablish_2[ 0 ] ) . unwrap ( ) ;
@@ -6042,9 +6066,11 @@ mod tests {
60426066 nodes[ 0 ] . node. peer_disconnected( & nodes[ 1 ] . node. get_our_node_id( ) , false ) ;
60436067 nodes[ 1 ] . node. peer_disconnected( & nodes[ 0 ] . node. get_our_node_id( ) , false ) ;
60446068
6045- let reestablish_1 = nodes[ 0 ] . node. peer_connected( & nodes[ 1 ] . node. get_our_node_id( ) ) ;
6069+ nodes[ 0 ] . node. peer_connected( & nodes[ 1 ] . node. get_our_node_id( ) ) ;
6070+ let reestablish_1 = get_chan_reestablish_msgs!( nodes[ 0 ] , nodes[ 1 ] ) ;
60466071 assert_eq!( reestablish_1. len( ) , 1 ) ;
6047- let reestablish_2 = nodes[ 1 ] . node. peer_connected( & nodes[ 0 ] . node. get_our_node_id( ) ) ;
6072+ nodes[ 1 ] . node. peer_connected( & nodes[ 0 ] . node. get_our_node_id( ) ) ;
6073+ let reestablish_2 = get_chan_reestablish_msgs!( nodes[ 1 ] , nodes[ 0 ] ) ;
60486074 assert_eq!( reestablish_2. len( ) , 1 ) ;
60496075
60506076 nodes[ 0 ] . node. handle_channel_reestablish( & nodes[ 1 ] . node. get_our_node_id( ) , & reestablish_2[ 0 ] ) . unwrap( ) ;
@@ -6062,9 +6088,11 @@ mod tests {
60626088 assert ! ( nodes[ 0 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
60636089 assert ! ( nodes[ 0 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
60646090
6065- let reestablish_1 = nodes[ 0 ] . node . peer_connected ( & nodes[ 1 ] . node . get_our_node_id ( ) ) ;
6091+ nodes[ 0 ] . node . peer_connected ( & nodes[ 1 ] . node . get_our_node_id ( ) ) ;
6092+ let reestablish_1 = get_chan_reestablish_msgs ! ( nodes[ 0 ] , nodes[ 1 ] ) ;
60666093 assert_eq ! ( reestablish_1. len( ) , 1 ) ;
6067- let reestablish_2 = nodes[ 1 ] . node . peer_connected ( & nodes[ 0 ] . node . get_our_node_id ( ) ) ;
6094+ nodes[ 1 ] . node . peer_connected ( & nodes[ 0 ] . node . get_our_node_id ( ) ) ;
6095+ let reestablish_2 = get_chan_reestablish_msgs ! ( nodes[ 1 ] , nodes[ 0 ] ) ;
60686096 assert_eq ! ( reestablish_2. len( ) , 1 ) ;
60696097
60706098 nodes[ 0 ] . node . handle_channel_reestablish ( & nodes[ 1 ] . node . get_our_node_id ( ) , & reestablish_2[ 0 ] ) . unwrap ( ) ;
0 commit comments