@@ -5032,13 +5032,14 @@ mod benches {
50325032 }
50335033
50345034 fn generate_routes < S : Score > (
5035- bench : & mut Bencher , graph : & NetworkGraph , scorer : S , features : InvoiceFeatures
5035+ bench : & mut Bencher , graph : & NetworkGraph , mut scorer : S , features : InvoiceFeatures
50365036 ) {
50375037 let nodes = graph. read_only ( ) . nodes ( ) . clone ( ) ;
50385038 let payer = payer_pubkey ( ) ;
50395039
50405040 // First, get 100 (source, destination) pairs for which route-getting actually succeeds...
5041- let mut path_endpoints = Vec :: new ( ) ;
5041+ let mut routes = Vec :: new ( ) ;
5042+ let mut route_endpoints = Vec :: new ( ) ;
50425043 let mut seed: usize = 0xdeadbeef ;
50435044 ' load_endpoints: for _ in 0 ..100 {
50445045 loop {
@@ -5049,17 +5050,33 @@ mod benches {
50495050 let params = PaymentParameters :: from_node_id ( dst) . with_features ( features. clone ( ) ) ;
50505051 let first_hop = first_hop ( src) ;
50515052 let amt = seed as u64 % 1_000_000 ;
5052- if get_route ( & payer, & params, & graph, Some ( & [ & first_hop] ) , amt, 42 , & DummyLogger { } , & scorer) . is_ok ( ) {
5053- path_endpoints. push ( ( first_hop, params, amt) ) ;
5053+ if let Ok ( route) = get_route ( & payer, & params, & graph, Some ( & [ & first_hop] ) , amt, 42 , & DummyLogger { } , & scorer) {
5054+ routes. push ( route) ;
5055+ route_endpoints. push ( ( first_hop, params, amt) ) ;
50545056 continue ' load_endpoints;
50555057 }
50565058 }
50575059 }
50585060
5061+ // ...and seed the scorer with success and failure data...
5062+ for route in routes {
5063+ let amount = route. get_total_amount ( ) ;
5064+ if amount < 250_000 {
5065+ for path in route. paths {
5066+ scorer. payment_path_successful ( & path. iter ( ) . collect :: < Vec < _ > > ( ) ) ;
5067+ }
5068+ } else if amount > 750_000 {
5069+ for path in route. paths {
5070+ let short_channel_id = path[ path. len ( ) / 2 ] . short_channel_id ;
5071+ scorer. payment_path_failed ( & path. iter ( ) . collect :: < Vec < _ > > ( ) , short_channel_id) ;
5072+ }
5073+ }
5074+ }
5075+
50595076 // ...then benchmark finding paths between the nodes we learned.
50605077 let mut idx = 0 ;
50615078 bench. iter ( || {
5062- let ( first_hop, params, amt) = & path_endpoints [ idx % path_endpoints . len ( ) ] ;
5079+ let ( first_hop, params, amt) = & route_endpoints [ idx % route_endpoints . len ( ) ] ;
50635080 assert ! ( get_route( & payer, params, & graph, Some ( & [ first_hop] ) , * amt, 42 , & DummyLogger { } , & scorer) . is_ok( ) ) ;
50645081 idx += 1 ;
50655082 } ) ;
0 commit comments