@@ -946,7 +946,7 @@ mod tests {
946
946
use routing:: scoring:: Score ;
947
947
use routing:: network_graph:: { NetworkGraph , NodeId } ;
948
948
use routing:: router:: RouteHop ;
949
- use util:: ser:: { Readable , Writeable } ;
949
+ use util:: ser:: { Readable , ReadableArgs , Writeable } ;
950
950
951
951
use bitcoin:: blockdata:: constants:: genesis_block;
952
952
use bitcoin:: hashes:: Hash ;
@@ -1291,7 +1291,7 @@ mod tests {
1291
1291
// `ProbabilisticScorer` tests
1292
1292
1293
1293
/// A probabilistic scorer for testing with time that can be manually advanced.
1294
- type ProbabilisticScorer < G > = ProbabilisticScorerUsingTime :: < G , SinceEpoch > ;
1294
+ type ProbabilisticScorer < ' a > = ProbabilisticScorerUsingTime :: < & ' a NetworkGraph , SinceEpoch > ;
1295
1295
1296
1296
fn sender_privkey ( ) -> SecretKey {
1297
1297
SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( )
@@ -1838,5 +1838,63 @@ mod tests {
1838
1838
assert_eq ! ( scorer. channel_penalty_msat( 42 , 512 , 1_024 , & source, & target) , 280 ) ;
1839
1839
}
1840
1840
1841
- // TODO: Add test coverage for serialization
1841
+ #[ test]
1842
+ fn restores_persisted_liquidity_bounds ( ) {
1843
+ let network_graph = network_graph ( ) ;
1844
+ let params = ProbabilisticScoringParameters {
1845
+ liquidity_penalty_multiplier_msat : 1_000 ,
1846
+ liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1847
+ } ;
1848
+ let mut scorer = ProbabilisticScorer :: new ( params, sender_pubkey ( ) , & network_graph) ;
1849
+ let source = source_node_id ( ) ;
1850
+ let target = target_node_id ( ) ;
1851
+
1852
+ scorer. payment_path_failed ( & payment_path_for_amount ( 500 ) . iter ( ) . collect :: < Vec < _ > > ( ) , 42 ) ;
1853
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , 2699 ) ;
1854
+
1855
+ SinceEpoch :: advance ( Duration :: from_secs ( 10 ) ) ;
1856
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , 475 ) ;
1857
+
1858
+ scorer. payment_path_failed ( & payment_path_for_amount ( 250 ) . iter ( ) . collect :: < Vec < _ > > ( ) , 43 ) ;
1859
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , 300 ) ;
1860
+
1861
+ let mut serialized_scorer = Vec :: new ( ) ;
1862
+ scorer. write ( & mut serialized_scorer) . unwrap ( ) ;
1863
+
1864
+ let mut serialized_scorer = io:: Cursor :: new ( & serialized_scorer) ;
1865
+ let deserialized_scorer =
1866
+ <ProbabilisticScorer >:: read ( & mut serialized_scorer, & network_graph) . unwrap ( ) ;
1867
+ assert_eq ! ( deserialized_scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , 300 ) ;
1868
+ }
1869
+
1870
+ #[ test]
1871
+ fn decays_persisted_liquidity_bounds ( ) {
1872
+ let network_graph = network_graph ( ) ;
1873
+ let params = ProbabilisticScoringParameters {
1874
+ liquidity_penalty_multiplier_msat : 1_000 ,
1875
+ liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1876
+ } ;
1877
+ let mut scorer = ProbabilisticScorer :: new ( params, sender_pubkey ( ) , & network_graph) ;
1878
+ let source = source_node_id ( ) ;
1879
+ let target = target_node_id ( ) ;
1880
+
1881
+ scorer. payment_path_failed ( & payment_path_for_amount ( 500 ) . iter ( ) . collect :: < Vec < _ > > ( ) , 42 ) ;
1882
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , 2699 ) ;
1883
+
1884
+ let mut serialized_scorer = Vec :: new ( ) ;
1885
+ scorer. write ( & mut serialized_scorer) . unwrap ( ) ;
1886
+
1887
+ SinceEpoch :: advance ( Duration :: from_secs ( 10 ) ) ;
1888
+
1889
+ let mut serialized_scorer = io:: Cursor :: new ( & serialized_scorer) ;
1890
+ let deserialized_scorer =
1891
+ <ProbabilisticScorer >:: read ( & mut serialized_scorer, & network_graph) . unwrap ( ) ;
1892
+ assert_eq ! ( deserialized_scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , 475 ) ;
1893
+
1894
+ scorer. payment_path_failed ( & payment_path_for_amount ( 250 ) . iter ( ) . collect :: < Vec < _ > > ( ) , 43 ) ;
1895
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , 300 ) ;
1896
+
1897
+ SinceEpoch :: advance ( Duration :: from_secs ( 10 ) ) ;
1898
+ assert_eq ! ( deserialized_scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , 367 ) ;
1899
+ }
1842
1900
}
0 commit comments