@@ -929,7 +929,7 @@ mod tests {
929
929
use routing:: scoring:: Score ;
930
930
use routing:: network_graph:: { NetworkGraph , NodeId } ;
931
931
use routing:: router:: RouteHop ;
932
- use util:: ser:: { Readable , Writeable } ;
932
+ use util:: ser:: { Readable , ReadableArgs , Writeable } ;
933
933
934
934
use bitcoin:: blockdata:: constants:: genesis_block;
935
935
use bitcoin:: hashes:: Hash ;
@@ -1274,7 +1274,7 @@ mod tests {
1274
1274
// `ProbabilisticScorer` tests
1275
1275
1276
1276
/// A probabilistic scorer for testing with time that can be manually advanced.
1277
- type ProbabilisticScorer < G > = ProbabilisticScorerUsingTime :: < G , SinceEpoch > ;
1277
+ type ProbabilisticScorer < ' a > = ProbabilisticScorerUsingTime :: < & ' a NetworkGraph , SinceEpoch > ;
1278
1278
1279
1279
fn sender_privkey ( ) -> SecretKey {
1280
1280
SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( )
@@ -1821,5 +1821,65 @@ mod tests {
1821
1821
assert_eq ! ( scorer. channel_penalty_msat( 42 , 512 , 1_024 , & source, & target) , 280 ) ;
1822
1822
}
1823
1823
1824
- // TODO: Add test coverage for serialization
1824
+ #[ test]
1825
+ fn restores_persisted_liquidity_bounds ( ) {
1826
+ let network_graph = network_graph ( ) ;
1827
+ let params = ProbabilisticScoringParameters {
1828
+ liquidity_penalty_multiplier_msat : 1_000 ,
1829
+ liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1830
+ } ;
1831
+ let mut scorer = ProbabilisticScorer :: new ( params, & sender_pubkey ( ) , & network_graph) ;
1832
+ let source = source_node_id ( ) ;
1833
+ let target = target_node_id ( ) ;
1834
+
1835
+ scorer. payment_path_failed ( & payment_path_for_amount ( 500 ) . iter ( ) . collect :: < Vec < _ > > ( ) , 42 ) ;
1836
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , 2699 ) ;
1837
+
1838
+ SinceEpoch :: advance ( Duration :: from_secs ( 10 ) ) ;
1839
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , 475 ) ;
1840
+
1841
+ scorer. payment_path_failed ( & payment_path_for_amount ( 250 ) . iter ( ) . collect :: < Vec < _ > > ( ) , 43 ) ;
1842
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , 300 ) ;
1843
+
1844
+ let mut serialized_scorer = Vec :: new ( ) ;
1845
+ scorer. write ( & mut serialized_scorer) . unwrap ( ) ;
1846
+
1847
+ let mut serialized_scorer = io:: Cursor :: new ( & serialized_scorer) ;
1848
+ let args = ( & sender_pubkey ( ) , & network_graph) ;
1849
+ let deserialized_scorer =
1850
+ <ProbabilisticScorer >:: read ( & mut serialized_scorer, args) . unwrap ( ) ;
1851
+ assert_eq ! ( deserialized_scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , 300 ) ;
1852
+ }
1853
+
1854
+ #[ test]
1855
+ fn decays_persisted_liquidity_bounds ( ) {
1856
+ let network_graph = network_graph ( ) ;
1857
+ let params = ProbabilisticScoringParameters {
1858
+ liquidity_penalty_multiplier_msat : 1_000 ,
1859
+ liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1860
+ } ;
1861
+ let mut scorer = ProbabilisticScorer :: new ( params, & sender_pubkey ( ) , & network_graph) ;
1862
+ let source = source_node_id ( ) ;
1863
+ let target = target_node_id ( ) ;
1864
+
1865
+ scorer. payment_path_failed ( & payment_path_for_amount ( 500 ) . iter ( ) . collect :: < Vec < _ > > ( ) , 42 ) ;
1866
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , 2699 ) ;
1867
+
1868
+ let mut serialized_scorer = Vec :: new ( ) ;
1869
+ scorer. write ( & mut serialized_scorer) . unwrap ( ) ;
1870
+
1871
+ SinceEpoch :: advance ( Duration :: from_secs ( 10 ) ) ;
1872
+
1873
+ let mut serialized_scorer = io:: Cursor :: new ( & serialized_scorer) ;
1874
+ let args = ( & sender_pubkey ( ) , & network_graph) ;
1875
+ let deserialized_scorer =
1876
+ <ProbabilisticScorer >:: read ( & mut serialized_scorer, args) . unwrap ( ) ;
1877
+ assert_eq ! ( deserialized_scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , 475 ) ;
1878
+
1879
+ scorer. payment_path_failed ( & payment_path_for_amount ( 250 ) . iter ( ) . collect :: < Vec < _ > > ( ) , 43 ) ;
1880
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , 300 ) ;
1881
+
1882
+ SinceEpoch :: advance ( Duration :: from_secs ( 10 ) ) ;
1883
+ assert_eq ! ( deserialized_scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , 367 ) ;
1884
+ }
1825
1885
}
0 commit comments