@@ -3538,3 +3538,61 @@ mod tests {
35383538			Some ( 0.0 ) ) ; 
35393539	} 
35403540} 
3541+ 
3542+ #[ cfg( ldk_bench) ]  
3543+ pub  mod  benches { 
3544+ 	use  super :: * ; 
3545+ 	use  criterion:: Criterion ; 
3546+ 	use  crate :: routing:: router:: { bench_utils,  RouteHop } ; 
3547+ 	use  crate :: util:: test_utils:: TestLogger ; 
3548+ 	use  crate :: ln:: features:: { ChannelFeatures ,  NodeFeatures } ; 
3549+ 
3550+ 	pub  fn  decay_100k_channel_bounds ( bench :  & mut  Criterion )  { 
3551+ 		let  logger = TestLogger :: new ( ) ; 
3552+ 		let  network_graph = bench_utils:: read_network_graph ( & logger) . unwrap ( ) ; 
3553+ 		let  mut  scorer = ProbabilisticScorer :: new ( Default :: default ( ) ,  & network_graph,  & logger) ; 
3554+ 		// Score a number of random channels 
3555+ 		let  mut  seed:  u64  = 0xdeadbeef ; 
3556+ 		for  _ in  0 ..100_000  { 
3557+ 			seed = seed. overflowing_mul ( 6364136223846793005 ) . 0 . overflowing_add ( 1 ) . 0 ; 
3558+ 			let  ( victim,  victim_dst,  amt)  = { 
3559+ 				let  rong = network_graph. read_only ( ) ; 
3560+ 				let  channels = rong. channels ( ) ; 
3561+ 				let  chan = channels. unordered_iter ( ) 
3562+ 					. skip ( ( seed as  usize )  % channels. len ( ) ) 
3563+ 					. next ( ) . unwrap ( ) ; 
3564+ 				seed = seed. overflowing_mul ( 6364136223846793005 ) . 0 . overflowing_add ( 1 ) . 0 ; 
3565+ 				let  amt = seed % chan. 1 . capacity_sats . map ( |c| c *  1000 ) 
3566+ 					. or ( chan. 1 . one_to_two . as_ref ( ) . map ( |info| info. htlc_maximum_msat ) ) 
3567+ 					. or ( chan. 1 . two_to_one . as_ref ( ) . map ( |info| info. htlc_maximum_msat ) ) 
3568+ 					. unwrap_or ( 1_000_000_000 ) . saturating_add ( 1 ) ; 
3569+ 				( * chan. 0 ,  chan. 1 . node_two ,  amt) 
3570+ 			} ; 
3571+ 			let  path = Path  { 
3572+ 				hops :  vec ! [ RouteHop  { 
3573+ 					pubkey:  victim_dst. as_pubkey( ) . unwrap( ) , 
3574+ 					node_features:  NodeFeatures :: empty( ) , 
3575+ 					short_channel_id:  victim, 
3576+ 					channel_features:  ChannelFeatures :: empty( ) , 
3577+ 					fee_msat:  amt, 
3578+ 					cltv_expiry_delta:  42 , 
3579+ 					maybe_announced_channel:  true , 
3580+ 				} ] , 
3581+ 				blinded_tail :  None 
3582+ 			} ; 
3583+ 			seed = seed. overflowing_mul ( 6364136223846793005 ) . 0 . overflowing_add ( 1 ) . 0 ; 
3584+ 			if  seed % 1  == 0  { 
3585+ 				scorer. probe_failed ( & path,  victim,  Duration :: ZERO ) ; 
3586+ 			}  else  { 
3587+ 				scorer. probe_successful ( & path,  Duration :: ZERO ) ; 
3588+ 			} 
3589+ 		} 
3590+ 		let  mut  cur_time = Duration :: ZERO ; 
3591+ 			cur_time += Duration :: from_millis ( 1 ) ; 
3592+ 			scorer. decay_liquidity_certainty ( cur_time) ; 
3593+ 		bench. bench_function ( "decay_100k_channel_bounds" ,  |b| b. iter ( || { 
3594+ 			cur_time += Duration :: from_millis ( 1 ) ; 
3595+ 			scorer. decay_liquidity_certainty ( cur_time) ; 
3596+ 		} ) ) ; 
3597+ 	} 
3598+ } 
0 commit comments