@@ -53,13 +53,15 @@ pub fn find_path<L: Deref, GL: Deref>(
53
53
54
54
// Add our start and first-hops to `frontier`.
55
55
let start = NodeId :: from_pubkey ( & our_node_pubkey) ;
56
+ let mut valid_first_hops = HashSet :: new ( ) ;
56
57
let mut frontier = BinaryHeap :: new ( ) ;
57
58
frontier. push ( PathBuildingHop { cost : 0 , node_id : start, parent_node_id : start } ) ;
58
59
if let Some ( first_hops) = first_hops {
59
60
for hop in first_hops {
60
61
if !hop. counterparty . features . supports_onion_messages ( ) { continue ; }
61
62
let node_id = NodeId :: from_pubkey ( & hop. counterparty . node_id ) ;
62
63
frontier. push ( PathBuildingHop { cost : 1 , node_id, parent_node_id : start } ) ;
64
+ valid_first_hops. insert ( node_id) ;
63
65
}
64
66
}
65
67
@@ -75,7 +77,7 @@ pub fn find_path<L: Deref, GL: Deref>(
75
77
return Ok ( path)
76
78
}
77
79
if let Some ( node_info) = network_nodes. get ( & node_id) {
78
- if node_id == our_node_id {
80
+ if valid_first_hops . contains ( & node_id ) || node_id == our_node_id {
79
81
} else if let Some ( node_ann) = & node_info. announcement_info {
80
82
if !node_ann. features . supports_onion_messages ( ) || node_ann. features . requires_unknown_bits ( )
81
83
{ continue ; }
@@ -173,7 +175,7 @@ fn reverse_path(
173
175
#[ cfg( test) ]
174
176
mod tests {
175
177
use ln:: features:: { InitFeatures , NodeFeatures } ;
176
- use routing:: test_utils:: { add_or_update_node, build_graph_with_features, build_line_graph, get_nodes} ;
178
+ use routing:: test_utils:: { add_or_update_node, build_graph_with_features, build_line_graph, get_channel_details , get_nodes} ;
177
179
178
180
use sync:: Arc ;
179
181
@@ -246,6 +248,13 @@ mod tests {
246
248
// If all nodes require some features we don't understand, route should fail
247
249
let err = super :: find_path ( & our_id, & node_pks[ 2 ] , & network_graph, None , Arc :: clone ( & logger) ) . unwrap_err ( ) ;
248
250
assert_eq ! ( err, super :: Error :: PathNotFound ) ;
251
+
252
+ // If we specify a channel to node7, that overrides our local channel view and that gets used
253
+ let our_chans = vec ! [ get_channel_details( Some ( 42 ) , node_pks[ 7 ] . clone( ) , features, 250_000_000 ) ] ;
254
+ let path = super :: find_path ( & our_id, & node_pks[ 2 ] , & network_graph, Some ( & our_chans. iter ( ) . collect :: < Vec < _ > > ( ) ) , Arc :: clone ( & logger) ) . unwrap ( ) ;
255
+ assert_eq ! ( path. len( ) , 2 ) ;
256
+ assert_eq ! ( path[ 0 ] , node_pks[ 7 ] ) ;
257
+ assert_eq ! ( path[ 1 ] , node_pks[ 2 ] ) ;
249
258
}
250
259
251
260
#[ test]
@@ -263,5 +272,11 @@ mod tests {
263
272
assert_eq ! ( path[ 0 ] , node_pks[ 1 ] ) ;
264
273
assert_eq ! ( path[ 1 ] , node_pks[ 2 ] ) ;
265
274
assert_eq ! ( path[ 2 ] , node_pks[ 0 ] ) ;
275
+
276
+ // If we specify a channel to node1, that overrides our local channel view and that gets used
277
+ let our_chans = vec ! [ get_channel_details( Some ( 42 ) , node_pks[ 0 ] . clone( ) , features, 250_000_000 ) ] ;
278
+ let path = super :: find_path ( & our_id, & node_pks[ 0 ] , & network_graph, Some ( & our_chans. iter ( ) . collect :: < Vec < _ > > ( ) ) , Arc :: clone ( & logger) ) . unwrap ( ) ;
279
+ assert_eq ! ( path. len( ) , 1 ) ;
280
+ assert_eq ! ( path[ 0 ] , node_pks[ 0 ] ) ;
266
281
}
267
282
}
0 commit comments