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