@@ -2676,9 +2676,10 @@ impl ChannelMessageHandler for ChannelManager {
2676
2676
}
2677
2677
}
2678
2678
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 ;
2682
2683
channel_state. by_id . retain ( |_, chan| {
2683
2684
if chan. get_their_node_id ( ) == * their_node_id {
2684
2685
if !chan. have_received_message ( ) {
@@ -2688,13 +2689,15 @@ impl ChannelMessageHandler for ChannelManager {
2688
2689
// drop it.
2689
2690
false
2690
2691
} 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
+ } ) ;
2692
2696
true
2693
2697
}
2694
2698
} else { true }
2695
2699
} ) ;
2696
2700
//TODO: Also re-broadcast announcement_signatures
2697
- res
2698
2701
}
2699
2702
2700
2703
fn handle_error ( & self , their_node_id : & PublicKey , msg : & msgs:: ErrorMessage ) {
@@ -5197,6 +5200,23 @@ mod tests {
5197
5200
assert_eq ! ( channel_state. short_to_id. len( ) , 0 ) ;
5198
5201
}
5199
5202
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
+
5200
5220
macro_rules! handle_chan_reestablish_msgs {
5201
5221
( $src_node: expr, $dst_node: expr) => {
5202
5222
{
@@ -5255,8 +5275,10 @@ mod tests {
5255
5275
/// pending_htlc_adds includes both the holding cell and in-flight update_add_htlcs, whereas
5256
5276
/// for claims/fails they are separated out.
5257
5277
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) ;
5260
5282
5261
5283
let mut resp_1 = Vec :: new ( ) ;
5262
5284
for msg in reestablish_1 {
@@ -5754,9 +5776,11 @@ mod tests {
5754
5776
nodes[ 0 ] . node . peer_disconnected ( & nodes[ 1 ] . node . get_our_node_id ( ) , false ) ;
5755
5777
nodes[ 1 ] . node . peer_disconnected ( & nodes[ 0 ] . node . get_our_node_id ( ) , false ) ;
5756
5778
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 ] ) ;
5758
5781
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 ] ) ;
5760
5784
assert_eq ! ( reestablish_2. len( ) , 1 ) ;
5761
5785
5762
5786
nodes[ 0 ] . node . handle_channel_reestablish ( & nodes[ 1 ] . node . get_our_node_id ( ) , & reestablish_2[ 0 ] ) . unwrap ( ) ;
@@ -6042,9 +6066,11 @@ mod tests {
6042
6066
nodes[ 0 ] . node. peer_disconnected( & nodes[ 1 ] . node. get_our_node_id( ) , false ) ;
6043
6067
nodes[ 1 ] . node. peer_disconnected( & nodes[ 0 ] . node. get_our_node_id( ) , false ) ;
6044
6068
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 ] ) ;
6046
6071
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 ] ) ;
6048
6074
assert_eq!( reestablish_2. len( ) , 1 ) ;
6049
6075
6050
6076
nodes[ 0 ] . node. handle_channel_reestablish( & nodes[ 1 ] . node. get_our_node_id( ) , & reestablish_2[ 0 ] ) . unwrap( ) ;
@@ -6062,9 +6088,11 @@ mod tests {
6062
6088
assert ! ( nodes[ 0 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
6063
6089
assert ! ( nodes[ 0 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
6064
6090
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 ] ) ;
6066
6093
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 ] ) ;
6068
6096
assert_eq ! ( reestablish_2. len( ) , 1 ) ;
6069
6097
6070
6098
nodes[ 0 ] . node . handle_channel_reestablish ( & nodes[ 1 ] . node . get_our_node_id ( ) , & reestablish_2[ 0 ] ) . unwrap ( ) ;
0 commit comments