@@ -40,13 +40,15 @@ pub fn find_path<L: Deref, GL: Deref>(
40
40
41
41
// Add our start and first-hops to `frontier`.
42
42
let start = NodeId :: from_pubkey ( & our_node_pubkey) ;
43
+ let mut valid_first_hops = HashSet :: new ( ) ;
43
44
let mut frontier = BinaryHeap :: new ( ) ;
44
45
frontier. push ( PathBuildingHop { cost : 0 , node_id : start, parent_node_id : start } ) ;
45
46
if let Some ( first_hops) = first_hops {
46
47
for hop in first_hops {
47
48
if !hop. counterparty . features . supports_onion_messages ( ) { continue ; }
48
49
let node_id = NodeId :: from_pubkey ( & hop. counterparty . node_id ) ;
49
50
frontier. push ( PathBuildingHop { cost : 1 , node_id, parent_node_id : start } ) ;
51
+ valid_first_hops. insert ( node_id) ;
50
52
}
51
53
}
52
54
@@ -60,7 +62,7 @@ pub fn find_path<L: Deref, GL: Deref>(
60
62
return Ok ( reverse_path ( visited, our_node_id, dest_node_id, logger) ?)
61
63
}
62
64
if let Some ( node_info) = network_nodes. get ( & node_id) {
63
- if node_id == our_node_id {
65
+ if valid_first_hops . contains ( & node_id ) || node_id == our_node_id {
64
66
} else if let Some ( node_ann) = & node_info. announcement_info {
65
67
if !node_ann. features . supports_onion_messages ( ) || node_ann. features . requires_unknown_bits ( )
66
68
{ continue ; }
@@ -146,7 +148,7 @@ fn reverse_path<L: Deref>(
146
148
#[ cfg( test) ]
147
149
mod tests {
148
150
use ln:: features:: { InitFeatures , NodeFeatures } ;
149
- use routing:: test_utils:: { add_or_update_node, build_graph_with_features, build_line_graph, get_nodes} ;
151
+ use routing:: test_utils:: { add_or_update_node, build_graph_with_features, build_line_graph, get_channel_details , get_nodes} ;
150
152
151
153
use sync:: Arc ;
152
154
@@ -219,6 +221,13 @@ mod tests {
219
221
// If all nodes require some features we don't understand, route should fail
220
222
let err = super :: find_path ( & our_id, & node_pks[ 2 ] , & network_graph, None , Arc :: clone ( & logger) ) . unwrap_err ( ) ;
221
223
assert_eq ! ( err, super :: Error :: PathNotFound ) ;
224
+
225
+ // If we specify a channel to node7, that overrides our local channel view and that gets used
226
+ let our_chans = vec ! [ get_channel_details( Some ( 42 ) , node_pks[ 7 ] . clone( ) , features, 250_000_000 ) ] ;
227
+ let path = super :: find_path ( & our_id, & node_pks[ 2 ] , & network_graph, Some ( & our_chans. iter ( ) . collect :: < Vec < _ > > ( ) ) , Arc :: clone ( & logger) ) . unwrap ( ) ;
228
+ assert_eq ! ( path. len( ) , 2 ) ;
229
+ assert_eq ! ( path[ 0 ] , node_pks[ 7 ] ) ;
230
+ assert_eq ! ( path[ 1 ] , node_pks[ 2 ] ) ;
222
231
}
223
232
224
233
#[ test]
@@ -236,6 +245,12 @@ mod tests {
236
245
assert_eq ! ( path[ 0 ] , node_pks[ 1 ] ) ;
237
246
assert_eq ! ( path[ 1 ] , node_pks[ 2 ] ) ;
238
247
assert_eq ! ( path[ 2 ] , node_pks[ 0 ] ) ;
248
+
249
+ // If we specify a channel to node1, that overrides our local channel view and that gets used
250
+ let our_chans = vec ! [ get_channel_details( Some ( 42 ) , node_pks[ 0 ] . clone( ) , features, 250_000_000 ) ] ;
251
+ let path = super :: find_path ( & our_id, & node_pks[ 0 ] , & network_graph, Some ( & our_chans. iter ( ) . collect :: < Vec < _ > > ( ) ) , Arc :: clone ( & logger) ) . unwrap ( ) ;
252
+ assert_eq ! ( path. len( ) , 1 ) ;
253
+ assert_eq ! ( path[ 0 ] , node_pks[ 0 ] ) ;
239
254
}
240
255
}
241
256
0 commit comments