@@ -3748,3 +3748,61 @@ mod tests {
3748
3748
Some ( 0.0 ) ) ;
3749
3749
}
3750
3750
}
3751
+
3752
+ #[ cfg( ldk_bench) ]
3753
+ pub mod benches {
3754
+ use super :: * ;
3755
+ use criterion:: Criterion ;
3756
+ use crate :: routing:: router:: { bench_utils, RouteHop } ;
3757
+ use crate :: util:: test_utils:: TestLogger ;
3758
+ use crate :: ln:: features:: { ChannelFeatures , NodeFeatures } ;
3759
+
3760
+ pub fn decay_100k_channel_bounds ( bench : & mut Criterion ) {
3761
+ let logger = TestLogger :: new ( ) ;
3762
+ let network_graph = bench_utils:: read_network_graph ( & logger) . unwrap ( ) ;
3763
+ let mut scorer = ProbabilisticScorer :: new ( Default :: default ( ) , & network_graph, & logger) ;
3764
+ // Score a number of random channels
3765
+ let mut seed: u64 = 0xdeadbeef ;
3766
+ for _ in 0 ..100_000 {
3767
+ seed = seed. overflowing_mul ( 6364136223846793005 ) . 0 . overflowing_add ( 1 ) . 0 ;
3768
+ let ( victim, victim_dst, amt) = {
3769
+ let rong = network_graph. read_only ( ) ;
3770
+ let channels = rong. channels ( ) ;
3771
+ let chan = channels. unordered_iter ( )
3772
+ . skip ( ( seed as usize ) % channels. len ( ) )
3773
+ . next ( ) . unwrap ( ) ;
3774
+ seed = seed. overflowing_mul ( 6364136223846793005 ) . 0 . overflowing_add ( 1 ) . 0 ;
3775
+ let amt = seed % chan. 1 . capacity_sats . map ( |c| c * 1000 )
3776
+ . or ( chan. 1 . one_to_two . as_ref ( ) . map ( |info| info. htlc_maximum_msat ) )
3777
+ . or ( chan. 1 . two_to_one . as_ref ( ) . map ( |info| info. htlc_maximum_msat ) )
3778
+ . unwrap_or ( 1_000_000_000 ) . saturating_add ( 1 ) ;
3779
+ ( * chan. 0 , chan. 1 . node_two , amt)
3780
+ } ;
3781
+ let path = Path {
3782
+ hops : vec ! [ RouteHop {
3783
+ pubkey: victim_dst. as_pubkey( ) . unwrap( ) ,
3784
+ node_features: NodeFeatures :: empty( ) ,
3785
+ short_channel_id: victim,
3786
+ channel_features: ChannelFeatures :: empty( ) ,
3787
+ fee_msat: amt,
3788
+ cltv_expiry_delta: 42 ,
3789
+ maybe_announced_channel: true ,
3790
+ } ] ,
3791
+ blinded_tail : None
3792
+ } ;
3793
+ seed = seed. overflowing_mul ( 6364136223846793005 ) . 0 . overflowing_add ( 1 ) . 0 ;
3794
+ if seed % 1 == 0 {
3795
+ scorer. probe_failed ( & path, victim, Duration :: ZERO ) ;
3796
+ } else {
3797
+ scorer. probe_successful ( & path, Duration :: ZERO ) ;
3798
+ }
3799
+ }
3800
+ let mut cur_time = Duration :: ZERO ;
3801
+ cur_time += Duration :: from_millis ( 1 ) ;
3802
+ scorer. decay_liquidity_certainty ( cur_time) ;
3803
+ bench. bench_function ( "decay_100k_channel_bounds" , |b| b. iter ( || {
3804
+ cur_time += Duration :: from_millis ( 1 ) ;
3805
+ scorer. decay_liquidity_certainty ( cur_time) ;
3806
+ } ) ) ;
3807
+ }
3808
+ }
0 commit comments