@@ -2703,9 +2703,10 @@ impl ChannelMessageHandler for ChannelManager {
2703
2703
}
2704
2704
}
2705
2705
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 ;
2709
2710
channel_state. by_id . retain ( |_, chan| {
2710
2711
if chan. get_their_node_id ( ) == * their_node_id {
2711
2712
if !chan. have_received_message ( ) {
@@ -2715,13 +2716,15 @@ impl ChannelMessageHandler for ChannelManager {
2715
2716
// drop it.
2716
2717
false
2717
2718
} 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
+ } ) ;
2719
2723
true
2720
2724
}
2721
2725
} else { true }
2722
2726
} ) ;
2723
2727
//TODO: Also re-broadcast announcement_signatures
2724
- res
2725
2728
}
2726
2729
2727
2730
fn handle_error ( & self , their_node_id : & PublicKey , msg : & msgs:: ErrorMessage ) {
@@ -5224,6 +5227,23 @@ mod tests {
5224
5227
assert_eq ! ( channel_state. short_to_id. len( ) , 0 ) ;
5225
5228
}
5226
5229
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
+
5227
5247
macro_rules! handle_chan_reestablish_msgs {
5228
5248
( $src_node: expr, $dst_node: expr) => {
5229
5249
{
@@ -5282,8 +5302,10 @@ mod tests {
5282
5302
/// pending_htlc_adds includes both the holding cell and in-flight update_add_htlcs, whereas
5283
5303
/// for claims/fails they are separated out.
5284
5304
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) ;
5287
5309
5288
5310
let mut resp_1 = Vec :: new ( ) ;
5289
5311
for msg in reestablish_1 {
@@ -5781,9 +5803,11 @@ mod tests {
5781
5803
nodes[ 0 ] . node . peer_disconnected ( & nodes[ 1 ] . node . get_our_node_id ( ) , false ) ;
5782
5804
nodes[ 1 ] . node . peer_disconnected ( & nodes[ 0 ] . node . get_our_node_id ( ) , false ) ;
5783
5805
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 ] ) ;
5785
5808
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 ] ) ;
5787
5811
assert_eq ! ( reestablish_2. len( ) , 1 ) ;
5788
5812
5789
5813
nodes[ 0 ] . node . handle_channel_reestablish ( & nodes[ 1 ] . node . get_our_node_id ( ) , & reestablish_2[ 0 ] ) . unwrap ( ) ;
@@ -6069,9 +6093,11 @@ mod tests {
6069
6093
nodes[ 0 ] . node. peer_disconnected( & nodes[ 1 ] . node. get_our_node_id( ) , false ) ;
6070
6094
nodes[ 1 ] . node. peer_disconnected( & nodes[ 0 ] . node. get_our_node_id( ) , false ) ;
6071
6095
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 ] ) ;
6073
6098
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 ] ) ;
6075
6101
assert_eq!( reestablish_2. len( ) , 1 ) ;
6076
6102
6077
6103
nodes[ 0 ] . node. handle_channel_reestablish( & nodes[ 1 ] . node. get_our_node_id( ) , & reestablish_2[ 0 ] ) . unwrap( ) ;
@@ -6089,9 +6115,11 @@ mod tests {
6089
6115
assert ! ( nodes[ 0 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
6090
6116
assert ! ( nodes[ 0 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
6091
6117
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 ] ) ;
6093
6120
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 ] ) ;
6095
6123
assert_eq ! ( reestablish_2. len( ) , 1 ) ;
6096
6124
6097
6125
nodes[ 0 ] . node . handle_channel_reestablish ( & nodes[ 1 ] . node . get_our_node_id ( ) , & reestablish_2[ 0 ] ) . unwrap ( ) ;
0 commit comments