@@ -82,15 +82,19 @@ pub fn find_path<L: Deref, GL: Deref>(
82
82
} else { continue ; }
83
83
for scid in & node_info. channels {
84
84
if let Some ( chan_info) = network_channels. get ( & scid) {
85
- if let Some ( ( _, successor) ) = chan_info. as_directed_from ( & node_id) {
86
- // We may push a given successor multiple times, but the heap should sort its best entry
87
- // to the top. We do this because there is no way to adjust the priority of an existing
88
- // entry in `BinaryHeap`.
89
- frontier. push ( PathBuildingHop {
90
- cost : cost + 1 ,
91
- node_id : * successor,
92
- parent_node_id : node_id,
93
- } ) ;
85
+ if let Some ( ( directed_channel, successor) ) = chan_info. as_directed_from ( & node_id) {
86
+ if let Some ( direction) = directed_channel. direction ( ) {
87
+ if direction. enabled {
88
+ // We may push a given successor multiple times, but the heap should sort its best
89
+ // entry to the top. We do this because there is no way to adjust the priority of an
90
+ // existing entry in `BinaryHeap`.
91
+ frontier. push ( PathBuildingHop {
92
+ cost : cost + 1 ,
93
+ node_id : * successor,
94
+ parent_node_id : node_id,
95
+ } ) ;
96
+ }
97
+ }
94
98
}
95
99
}
96
100
}
@@ -243,4 +247,21 @@ mod tests {
243
247
let err = super :: find_path ( & our_id, & node_pks[ 2 ] , & network_graph, None , Arc :: clone ( & logger) ) . unwrap_err ( ) ;
244
248
assert_eq ! ( err, super :: Error :: PathNotFound ) ;
245
249
}
250
+
251
+ #[ test]
252
+ fn disabled_channels_test ( ) {
253
+ // Check that we won't attempt to route over nodes where the channel is disabled from their
254
+ // direction (implying the peer is offline).
255
+ let mut features = InitFeatures :: empty ( ) ;
256
+ features. set_onion_messages_optional ( ) ;
257
+ let ( secp_ctx, network_graph, _, _, logger) = build_graph_with_features ( features. to_context ( ) ) ;
258
+ let ( _, our_id, _, node_pks) = get_nodes ( & secp_ctx) ;
259
+
260
+ // Route to 1 via 2 and 3 because our channel to 1 is disabled
261
+ let path = super :: find_path ( & our_id, & node_pks[ 0 ] , & network_graph, None , Arc :: clone ( & logger) ) . unwrap ( ) ;
262
+ assert_eq ! ( path. len( ) , 3 ) ;
263
+ assert_eq ! ( path[ 0 ] , node_pks[ 1 ] ) ;
264
+ assert_eq ! ( path[ 1 ] , node_pks[ 2 ] ) ;
265
+ assert_eq ! ( path[ 2 ] , node_pks[ 0 ] ) ;
266
+ }
246
267
}
0 commit comments