@@ -225,7 +225,7 @@ struct NodeMapping {
225
225
alias_node_map : HashMap < String , NodeInfo > ,
226
226
}
227
227
228
- pub async fn create_simulation_with_network < P : for < ' a > PathFinder < ' a > + Clone + ' static > (
228
+ pub async fn create_simulation_with_network < P : PathFinder + Clone + ' static > (
229
229
cli : & Cli ,
230
230
sim_params : & SimParams ,
231
231
tasks : TaskTracker ,
@@ -278,7 +278,6 @@ pub async fn create_simulation_with_network<P: for<'a> PathFinder<'a> + Clone +
278
278
. map_err ( |e| SimulationError :: SimulatedNetworkError ( format ! ( "{:?}" , e) ) ) ?,
279
279
) ;
280
280
281
- // Pass the pathfinder to ln_node_from_graph
282
281
let nodes = ln_node_from_graph ( simulation_graph. clone ( ) , routing_graph, pathfinder) . await ;
283
282
let validated_activities =
284
283
get_validated_activities ( & nodes, nodes_info, sim_params. activity . clone ( ) ) . await ?;
@@ -621,7 +620,7 @@ mod tests {
621
620
( secret_key, public_key)
622
621
}
623
622
624
- /// Helper function to create simulated channels for testing
623
+ /// Helper function to create simulated channels for testing.
625
624
fn create_simulated_channels ( num_channels : usize , capacity_msat : u64 ) -> Vec < SimulatedChannel > {
626
625
let mut channels = Vec :: new ( ) ;
627
626
for i in 0 ..num_channels {
@@ -657,66 +656,67 @@ mod tests {
657
656
channels
658
657
}
659
658
660
- /// A pathfinder that always fails to find a path
659
+ /// A pathfinder that always fails to find a path.
661
660
#[ derive( Clone ) ]
662
661
pub struct AlwaysFailPathFinder ;
663
662
664
- impl < ' a > PathFinder < ' a > for AlwaysFailPathFinder {
663
+ impl PathFinder for AlwaysFailPathFinder {
665
664
fn find_route (
666
665
& self ,
667
666
_source : & PublicKey ,
668
667
_dest : PublicKey ,
669
668
_amount_msat : u64 ,
670
- _pathfinding_graph : & NetworkGraph < & ' a WrappedLog > ,
671
- _scorer : & ProbabilisticScorer < Arc < NetworkGraph < & ' a WrappedLog > > , & ' a WrappedLog > ,
669
+ _pathfinding_graph : & NetworkGraph < & ' static WrappedLog > ,
672
670
) -> Result < Route , SimulationError > {
673
671
Err ( SimulationError :: SimulatedNetworkError (
674
672
"No route found" . to_string ( ) ,
675
673
) )
676
674
}
677
675
}
678
676
679
- /// A pathfinder that only returns single-hop paths
677
+ /// A pathfinder that only returns single-hop paths.
680
678
#[ derive( Clone ) ]
681
679
pub struct SingleHopOnlyPathFinder ;
682
680
683
- impl < ' a > PathFinder < ' a > for SingleHopOnlyPathFinder {
681
+ impl PathFinder for SingleHopOnlyPathFinder {
684
682
fn find_route (
685
683
& self ,
686
684
source : & PublicKey ,
687
685
dest : PublicKey ,
688
686
amount_msat : u64 ,
689
- pathfinding_graph : & NetworkGraph < & ' a WrappedLog > ,
690
- scorer : & ProbabilisticScorer < Arc < NetworkGraph < & ' a WrappedLog > > , & ' a WrappedLog > ,
687
+ pathfinding_graph : & NetworkGraph < & ' static WrappedLog > ,
691
688
) -> Result < Route , SimulationError > {
692
- // Try to find a direct route only (single hop)
693
- let route_params = RouteParameters {
694
- payment_params : PaymentParameters :: from_node_id ( dest, 0 )
695
- . with_max_total_cltv_expiry_delta ( u32:: MAX )
696
- . with_max_path_count ( 1 )
697
- . with_max_channel_saturation_power_of_half ( 1 ) ,
698
- final_value_msat : amount_msat,
699
- max_total_routing_fee_msat : None ,
700
- } ;
701
-
702
- // Try to find a route - if it fails or has more than one hop, return an error
689
+ let scorer = ProbabilisticScorer :: new (
690
+ ProbabilisticScoringDecayParameters :: default ( ) ,
691
+ pathfinding_graph,
692
+ & WrappedLog { } ,
693
+ ) ;
694
+
695
+ // Try to find a route - if it fails or has more than one hop, return an error.
703
696
match find_route (
704
697
source,
705
- & route_params,
698
+ & RouteParameters {
699
+ payment_params : PaymentParameters :: from_node_id ( dest, 0 )
700
+ . with_max_total_cltv_expiry_delta ( u32:: MAX )
701
+ . with_max_path_count ( 1 )
702
+ . with_max_channel_saturation_power_of_half ( 1 ) ,
703
+ final_value_msat : amount_msat,
704
+ max_total_routing_fee_msat : None ,
705
+ } ,
706
706
pathfinding_graph,
707
707
None ,
708
708
& WrappedLog { } ,
709
- scorer,
709
+ & scorer,
710
710
& Default :: default ( ) ,
711
711
& [ 0 ; 32 ] ,
712
712
) {
713
713
Ok ( route) => {
714
- // Check if the route has exactly one hop
714
+ // Only allow single- hop routes.
715
715
if route. paths . len ( ) == 1 && route. paths [ 0 ] . hops . len ( ) == 1 {
716
716
Ok ( route)
717
717
} else {
718
718
Err ( SimulationError :: SimulatedNetworkError (
719
- "No direct route found " . to_string ( ) ,
719
+ "Only single-hop routes allowed " . to_string ( ) ,
720
720
) )
721
721
}
722
722
} ,
@@ -735,15 +735,9 @@ mod tests {
735
735
let source = channels[ 0 ] . get_node_1_pubkey ( ) ;
736
736
let dest = channels[ 2 ] . get_node_2_pubkey ( ) ;
737
737
738
- let scorer = ProbabilisticScorer :: new (
739
- ProbabilisticScoringDecayParameters :: default ( ) ,
740
- routing_graph. clone ( ) ,
741
- & WrappedLog { } ,
742
- ) ;
743
-
744
- let result = pathfinder. find_route ( & source, dest, 100_000 , & routing_graph, & scorer) ;
738
+ let result = pathfinder. find_route ( & source, dest, 100_000 , & routing_graph) ;
745
739
746
- // Should always fail
740
+ // Should always fail.
747
741
assert ! ( result. is_err( ) ) ;
748
742
}
749
743
@@ -756,31 +750,24 @@ mod tests {
756
750
let pathfinder = SingleHopOnlyPathFinder ;
757
751
let source = channels[ 0 ] . get_node_1_pubkey ( ) ;
758
752
759
- let scorer = ProbabilisticScorer :: new (
760
- ProbabilisticScoringDecayParameters :: default ( ) ,
761
- routing_graph. clone ( ) ,
762
- & WrappedLog { } ,
763
- ) ;
764
-
765
- // Test direct connection (should work)
753
+ // Test direct connection (should work).
766
754
let direct_dest = channels[ 0 ] . get_node_2_pubkey ( ) ;
767
- let result = pathfinder. find_route ( & source, direct_dest, 100_000 , & routing_graph, & scorer ) ;
755
+ let result = pathfinder. find_route ( & source, direct_dest, 100_000 , & routing_graph) ;
768
756
769
757
if result. is_ok ( ) {
770
758
let route = result. unwrap ( ) ;
771
759
assert_eq ! ( route. paths[ 0 ] . hops. len( ) , 1 ) ; // Only one hop
772
760
}
773
761
774
- // Test indirect connection (should fail)
762
+ // Test indirect connection (should fail).
775
763
let indirect_dest = channels[ 2 ] . get_node_2_pubkey ( ) ;
776
- let _result =
777
- pathfinder. find_route ( & source, indirect_dest, 100_000 , & routing_graph, & scorer) ;
764
+ let _result = pathfinder. find_route ( & source, indirect_dest, 100_000 , & routing_graph) ;
778
765
779
- // May fail because no direct route exists
766
+ // May fail because no direct route exists.
780
767
// (depends on your test network topology)
781
768
}
782
769
783
- /// Test that different pathfinders produce different behavior in payments
770
+ /// Test that different pathfinders produce different behavior in payments.
784
771
#[ tokio:: test]
785
772
async fn test_pathfinder_affects_payment_behavior ( ) {
786
773
let channels = create_simulated_channels ( 3 , 1_000_000_000 ) ;
@@ -798,7 +785,7 @@ mod tests {
798
785
let routing_graph =
799
786
Arc :: new ( populate_network_graph ( channels. clone ( ) , Arc :: new ( SystemClock { } ) ) . unwrap ( ) ) ;
800
787
801
- // Create nodes with different pathfinders
788
+ // Create nodes with different pathfinders.
802
789
let nodes_default = ln_node_from_graph (
803
790
sim_graph. clone ( ) ,
804
791
routing_graph. clone ( ) ,
@@ -813,7 +800,7 @@ mod tests {
813
800
)
814
801
. await ;
815
802
816
- // Both should create the same structure
803
+ // Both should create the same structure.
817
804
assert_eq ! ( nodes_default. len( ) , nodes_fail. len( ) ) ;
818
805
}
819
806
}
0 commit comments