@@ -49,13 +49,15 @@ pub fn find_path<L: Deref, GL: Deref>(
49
49
50
50
// Add our start and first-hops to `frontier`.
51
51
let start = NodeId :: from_pubkey ( & our_node_pubkey) ;
52
+ let mut valid_first_hops = HashSet :: new ( ) ;
52
53
let mut frontier = BinaryHeap :: new ( ) ;
53
54
frontier. push ( PathBuildingHop { cost : 0 , node_id : start, parent_node_id : start } ) ;
54
55
if let Some ( first_hops) = first_hops {
55
56
for hop in first_hops {
56
57
if !hop. counterparty . features . supports_onion_messages ( ) { continue ; }
57
58
let node_id = NodeId :: from_pubkey ( & hop. counterparty . node_id ) ;
58
59
frontier. push ( PathBuildingHop { cost : 1 , node_id, parent_node_id : start } ) ;
60
+ valid_first_hops. insert ( node_id) ;
59
61
}
60
62
}
61
63
@@ -71,7 +73,7 @@ pub fn find_path<L: Deref, GL: Deref>(
71
73
return Ok ( path)
72
74
}
73
75
if let Some ( node_info) = network_nodes. get ( & node_id) {
74
- if node_id == our_node_id {
76
+ if valid_first_hops . contains ( & node_id ) || node_id == our_node_id {
75
77
} else if let Some ( node_ann) = & node_info. announcement_info {
76
78
if !node_ann. features . supports_onion_messages ( ) || node_ann. features . requires_unknown_bits ( )
77
79
{ continue ; }
@@ -166,7 +168,7 @@ fn reverse_path(
166
168
#[ cfg( test) ]
167
169
mod tests {
168
170
use ln:: features:: { InitFeatures , NodeFeatures } ;
169
- use routing:: test_utils:: { add_or_update_node, build_graph_with_features, build_line_graph, get_nodes} ;
171
+ use routing:: test_utils:: { add_or_update_node, build_graph_with_features, build_line_graph, get_channel_details , get_nodes} ;
170
172
171
173
use sync:: Arc ;
172
174
@@ -239,6 +241,13 @@ mod tests {
239
241
// If all nodes require some features we don't understand, route should fail
240
242
let err = super :: find_path ( & our_id, & node_pks[ 2 ] , & network_graph, None , Arc :: clone ( & logger) ) . unwrap_err ( ) ;
241
243
assert_eq ! ( err, super :: Error :: PathNotFound ) ;
244
+
245
+ // If we specify a channel to node7, that overrides our local channel view and that gets used
246
+ let our_chans = vec ! [ get_channel_details( Some ( 42 ) , node_pks[ 7 ] . clone( ) , features, 250_000_000 ) ] ;
247
+ let path = super :: find_path ( & our_id, & node_pks[ 2 ] , & network_graph, Some ( & our_chans. iter ( ) . collect :: < Vec < _ > > ( ) ) , Arc :: clone ( & logger) ) . unwrap ( ) ;
248
+ assert_eq ! ( path. len( ) , 2 ) ;
249
+ assert_eq ! ( path[ 0 ] , node_pks[ 7 ] ) ;
250
+ assert_eq ! ( path[ 1 ] , node_pks[ 2 ] ) ;
242
251
}
243
252
244
253
#[ test]
@@ -256,6 +265,12 @@ mod tests {
256
265
assert_eq ! ( path[ 0 ] , node_pks[ 1 ] ) ;
257
266
assert_eq ! ( path[ 1 ] , node_pks[ 2 ] ) ;
258
267
assert_eq ! ( path[ 2 ] , node_pks[ 0 ] ) ;
268
+
269
+ // If we specify a channel to node1, that overrides our local channel view and that gets used
270
+ let our_chans = vec ! [ get_channel_details( Some ( 42 ) , node_pks[ 0 ] . clone( ) , features, 250_000_000 ) ] ;
271
+ let path = super :: find_path ( & our_id, & node_pks[ 0 ] , & network_graph, Some ( & our_chans. iter ( ) . collect :: < Vec < _ > > ( ) ) , Arc :: clone ( & logger) ) . unwrap ( ) ;
272
+ assert_eq ! ( path. len( ) , 1 ) ;
273
+ assert_eq ! ( path[ 0 ] , node_pks[ 0 ] ) ;
259
274
}
260
275
}
261
276
0 commit comments