@@ -1566,11 +1566,9 @@ fn add_random_cltv_offset(route: &mut Route, payment_params: &PaymentParameters,
15661566
15671567 // Remember the last three nodes of the random walk and avoid looping back on them.
15681568 // Init with the last three nodes from the actual path, if possible.
1569- let last_id = NodeId :: from_pubkey ( & path. last ( ) . unwrap ( ) . pubkey ) ;
1570- let second_last_id = NodeId :: from_pubkey ( & path. get ( path. len ( ) . saturating_sub ( 2 ) ) . unwrap ( ) . pubkey ) ;
1571- let third_last_id = NodeId :: from_pubkey ( & path. get ( path. len ( ) . saturating_sub ( 3 ) ) . unwrap ( ) . pubkey ) ;
1572- let mut nodes_to_avoid: [ NodeId ; 3 ] = [ third_last_id, second_last_id, last_id] ;
1573- let mut nodes_ring_index = 0 ;
1569+ let mut nodes_to_avoid: [ NodeId ; 3 ] = [ NodeId :: from_pubkey ( & path. last ( ) . unwrap ( ) . pubkey ) ,
1570+ NodeId :: from_pubkey ( & path. get ( path. len ( ) . saturating_sub ( 2 ) ) . unwrap ( ) . pubkey ) ,
1571+ NodeId :: from_pubkey ( & path. get ( path. len ( ) . saturating_sub ( 3 ) ) . unwrap ( ) . pubkey ) ] ;
15741572
15751573 // Choose the last publicly known node as the starting point for the random walk.
15761574 let mut cur_hop: Option < NodeId > = None ;
@@ -1589,7 +1587,7 @@ fn add_random_cltv_offset(route: &mut Route, payment_params: &PaymentParameters,
15891587 prng. process_in_place ( & mut random_path_bytes) ;
15901588 let random_walk_length = usize:: from_be_bytes ( random_path_bytes) . wrapping_rem ( 3 ) . wrapping_add ( 1 ) ;
15911589
1592- for _random_hop in 0 ..random_walk_length {
1590+ for random_hop in 0 ..random_walk_length {
15931591 // If we don't find a suitable offset in the public network graph, we default to
15941592 // MEDIAN_HOP_CLTV_EXPIRY_DELTA.
15951593 let mut random_hop_offset = MEDIAN_HOP_CLTV_EXPIRY_DELTA ;
@@ -1604,8 +1602,7 @@ fn add_random_cltv_offset(route: &mut Route, payment_params: &PaymentParameters,
16041602 . and_then ( |id| network_channels. get ( id) ) {
16051603 random_channel. as_directed_from ( & cur_node_id) . map ( |( dir_info, next_id) | {
16061604 if !nodes_to_avoid. iter ( ) . any ( |x| x == next_id) {
1607- nodes_to_avoid[ nodes_ring_index] = * next_id;
1608- nodes_ring_index = ( nodes_ring_index + 1 ) % 3 ;
1605+ nodes_to_avoid[ random_hop] = * next_id;
16091606 dir_info. direction ( ) . map ( |channel_update_info| {
16101607 random_hop_offset = channel_update_info. cltv_expiry_delta . into ( ) ;
16111608 cur_hop = Some ( * next_id) ;
0 commit comments