@@ -306,12 +306,7 @@ impl RoutingMessageHandler for Router {
306
306
& msgs:: HTLCFailChannelUpdate :: ChannelClosed { ref short_channel_id } => {
307
307
let mut network = self . network_map . write ( ) . unwrap ( ) ;
308
308
if let Some ( chan) = network. channels . remove ( short_channel_id) {
309
- network. nodes . get_mut ( & chan. one_to_two . src_node_id ) . unwrap ( ) . channels . retain ( |chan_id| {
310
- chan_id != NetworkMap :: get_short_id ( chan_id)
311
- } ) ;
312
- network. nodes . get_mut ( & chan. two_to_one . src_node_id ) . unwrap ( ) . channels . retain ( |chan_id| {
313
- chan_id != NetworkMap :: get_short_id ( chan_id)
314
- } ) ;
309
+ Self :: remove_channel_in_nodes ( & mut network. nodes , & chan, * short_channel_id) ;
315
310
}
316
311
} ,
317
312
}
@@ -462,6 +457,25 @@ impl Router {
462
457
unimplemented ! ( ) ;
463
458
}
464
459
460
+ fn remove_channel_in_nodes ( nodes : & mut HashMap < PublicKey , NodeInfo > , chan : & ChannelInfo , short_channel_id : u64 ) {
461
+ macro_rules! remove_from_node {
462
+ ( $node_id: expr) => {
463
+ if let Entry :: Occupied ( mut entry) = nodes. entry( $node_id) {
464
+ entry. get_mut( ) . channels. retain( |chan_id| {
465
+ short_channel_id != * NetworkMap :: get_short_id( chan_id)
466
+ } ) ;
467
+ if entry. get( ) . channels. is_empty( ) {
468
+ entry. remove_entry( ) ;
469
+ }
470
+ } else {
471
+ panic!( "Had channel that pointed to unknown node (ie inconsistent network map)!" ) ;
472
+ }
473
+ }
474
+ }
475
+ remove_from_node ! ( chan. one_to_two. src_node_id) ;
476
+ remove_from_node ! ( chan. two_to_one. src_node_id) ;
477
+ }
478
+
465
479
/// Gets a route from us to the given target node.
466
480
/// Extra routing hops between known nodes and the target will be used if they are included in
467
481
/// last_hops.
0 commit comments