@@ -250,7 +250,7 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
250250 disconnect_peers ( david, & [ bob, & nodes[ 4 ] , & nodes[ 5 ] ] ) ;
251251
252252 let tor = SocketAddress :: OnionV2 ( [ 255 , 254 , 253 , 252 , 251 , 250 , 249 , 248 , 247 , 246 , 38 , 7 ] ) ;
253- announce_node_address ( charlie, & [ alice, bob, david, & nodes[ 4 ] , & nodes[ 5 ] ] , tor) ;
253+ announce_node_address ( charlie, & [ alice, bob, david, & nodes[ 4 ] , & nodes[ 5 ] ] , tor. clone ( ) ) ;
254254
255255 let offer = bob. node
256256 . create_offer_builder ( "coffee" . to_string ( ) ) . unwrap ( )
@@ -259,8 +259,73 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
259259 assert_ne ! ( offer. signing_pubkey( ) , bob_id) ;
260260 assert ! ( !offer. paths( ) . is_empty( ) ) ;
261261 for path in offer. paths ( ) {
262+ assert_ne ! ( path. introduction_node_id, bob_id) ;
262263 assert_ne ! ( path. introduction_node_id, charlie_id) ;
263264 }
265+
266+ // Use a one-hop blinded path when Bob is announced and all his peers are Tor-only.
267+ announce_node_address ( & nodes[ 4 ] , & [ alice, bob, charlie, david, & nodes[ 5 ] ] , tor. clone ( ) ) ;
268+ announce_node_address ( & nodes[ 5 ] , & [ alice, bob, charlie, david, & nodes[ 4 ] ] , tor. clone ( ) ) ;
269+
270+ let offer = bob. node
271+ . create_offer_builder ( "coffee" . to_string ( ) ) . unwrap ( )
272+ . amount_msats ( 10_000_000 )
273+ . build ( ) . unwrap ( ) ;
274+ assert_ne ! ( offer. signing_pubkey( ) , bob_id) ;
275+ assert ! ( !offer. paths( ) . is_empty( ) ) ;
276+ for path in offer. paths ( ) {
277+ assert_eq ! ( path. introduction_node_id, bob_id) ;
278+ }
279+ }
280+
281+ /// Checks that blinded paths prefer an introduction node that is the most connected.
282+ #[ test]
283+ fn prefers_more_connected_nodes_in_blinded_paths ( ) {
284+ let mut accept_forward_cfg = test_default_channel_config ( ) ;
285+ accept_forward_cfg. accept_forwards_to_priv_channels = true ;
286+
287+ let mut features = channelmanager:: provided_init_features ( & accept_forward_cfg) ;
288+ features. set_onion_messages_optional ( ) ;
289+ features. set_route_blinding_optional ( ) ;
290+
291+ let chanmon_cfgs = create_chanmon_cfgs ( 6 ) ;
292+ let node_cfgs = create_node_cfgs ( 6 , & chanmon_cfgs) ;
293+
294+ * node_cfgs[ 1 ] . override_init_features . borrow_mut ( ) = Some ( features) ;
295+
296+ let node_chanmgrs = create_node_chanmgrs (
297+ 6 , & node_cfgs, & [ None , Some ( accept_forward_cfg) , None , None , None , None ]
298+ ) ;
299+ let nodes = create_network ( 6 , & node_cfgs, & node_chanmgrs) ;
300+
301+ create_unannounced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 10_000_000 , 1_000_000_000 ) ;
302+ create_unannounced_chan_between_nodes_with_value ( & nodes, 2 , 3 , 10_000_000 , 1_000_000_000 ) ;
303+ create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 10_000_000 , 1_000_000_000 ) ;
304+ create_announced_chan_between_nodes_with_value ( & nodes, 1 , 4 , 10_000_000 , 1_000_000_000 ) ;
305+ create_announced_chan_between_nodes_with_value ( & nodes, 1 , 5 , 10_000_000 , 1_000_000_000 ) ;
306+ create_announced_chan_between_nodes_with_value ( & nodes, 2 , 4 , 10_000_000 , 1_000_000_000 ) ;
307+ create_announced_chan_between_nodes_with_value ( & nodes, 2 , 5 , 10_000_000 , 1_000_000_000 ) ;
308+
309+ // Add extra channels so that more than one of Bob's peers have MIN_PEER_CHANNELS and one has
310+ // more than the others.
311+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 4 , 10_000_000 , 1_000_000_000 ) ;
312+ create_announced_chan_between_nodes_with_value ( & nodes, 3 , 4 , 10_000_000 , 1_000_000_000 ) ;
313+
314+ let ( alice, bob, charlie, david) = ( & nodes[ 0 ] , & nodes[ 1 ] , & nodes[ 2 ] , & nodes[ 3 ] ) ;
315+ let bob_id = bob. node . get_our_node_id ( ) ;
316+
317+ disconnect_peers ( alice, & [ charlie, david, & nodes[ 4 ] , & nodes[ 5 ] ] ) ;
318+ disconnect_peers ( david, & [ bob, & nodes[ 4 ] , & nodes[ 5 ] ] ) ;
319+
320+ let offer = bob. node
321+ . create_offer_builder ( "coffee" . to_string ( ) ) . unwrap ( )
322+ . amount_msats ( 10_000_000 )
323+ . build ( ) . unwrap ( ) ;
324+ assert_ne ! ( offer. signing_pubkey( ) , bob_id) ;
325+ assert ! ( !offer. paths( ) . is_empty( ) ) ;
326+ for path in offer. paths ( ) {
327+ assert_eq ! ( path. introduction_node_id, nodes[ 4 ] . node. get_our_node_id( ) ) ;
328+ }
264329}
265330
266331/// Checks that an offer can be paid through blinded paths and that ephemeral pubkeys are used
0 commit comments