@@ -484,7 +484,34 @@ impl ChannelLiquidities {
484
484
Self ( new_hash_map ( ) )
485
485
}
486
486
487
- fn merge ( & mut self , other : Self ) {
487
+ fn time_passed ( & mut self , duration_since_epoch : Duration , decay_params : ProbabilisticScoringDecayParameters ) {
488
+ self . 0 . retain ( |_scid, liquidity| {
489
+ liquidity. min_liquidity_offset_msat =
490
+ liquidity. decayed_offset ( liquidity. min_liquidity_offset_msat , duration_since_epoch, decay_params) ;
491
+ liquidity. max_liquidity_offset_msat =
492
+ liquidity. decayed_offset ( liquidity. max_liquidity_offset_msat , duration_since_epoch, decay_params) ;
493
+ liquidity. last_updated = duration_since_epoch;
494
+
495
+ // TODO: Call decay multiple times.
496
+ let elapsed_time =
497
+ duration_since_epoch. saturating_sub ( liquidity. offset_history_last_updated ) ;
498
+ if elapsed_time > decay_params. historical_no_updates_half_life {
499
+ let half_life = decay_params. historical_no_updates_half_life . as_secs_f64 ( ) ;
500
+ if half_life != 0.0 {
501
+ liquidity. liquidity_history . decay_buckets ( elapsed_time. as_secs_f64 ( ) / half_life) ;
502
+ liquidity. offset_history_last_updated = duration_since_epoch;
503
+ }
504
+ }
505
+ liquidity. min_liquidity_offset_msat != 0 || liquidity. max_liquidity_offset_msat != 0 ||
506
+ liquidity. liquidity_history . has_datapoints ( )
507
+ } ) ;
508
+ }
509
+
510
+ fn merge ( & mut self , mut other : Self , duration_since_epoch : Duration , decay_params : ProbabilisticScoringDecayParameters ) {
511
+ // Decay both set of scores to make them comparable.
512
+ self . time_passed ( duration_since_epoch, decay_params) ;
513
+ other. time_passed ( duration_since_epoch, decay_params) ;
514
+
488
515
for ( id, item) in other. 0 {
489
516
match self . 0 . get_mut ( & id) {
490
517
None => { self . 0 . insert ( id, item) ; } ,
@@ -899,8 +926,8 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref> ProbabilisticScorer<G, L> whe
899
926
}
900
927
901
928
/// Merge external channel liquidity data into the internal state.
902
- pub fn merge ( & mut self , other : ChannelLiquidities ) {
903
- self . channel_liquidities . merge ( other) ;
929
+ pub fn merge ( & mut self , other : ChannelLiquidities , duration_since_epoch : Duration ) {
930
+ self . channel_liquidities . merge ( other, duration_since_epoch , self . decay_params ) ;
904
931
}
905
932
906
933
#[ cfg( test) ]
@@ -1125,9 +1152,12 @@ impl ChannelLiquidity {
1125
1152
}
1126
1153
1127
1154
fn merge ( & mut self , other : & Self ) {
1128
- self . liquidity_history . merge ( & other. liquidity_history ) ;
1155
+ // Take average for min/max liquidity offsets.
1156
+ self . min_liquidity_offset_msat = ( self . min_liquidity_offset_msat + other. min_liquidity_offset_msat ) / 2 ;
1157
+ self . max_liquidity_offset_msat = ( self . max_liquidity_offset_msat + other. max_liquidity_offset_msat ) / 2 ;
1129
1158
1130
- // TODO: Merge other fields.
1159
+ // Merge historical liquidity data.
1160
+ self . liquidity_history . merge ( & other. liquidity_history ) ;
1131
1161
}
1132
1162
1133
1163
/// Returns a view of the channel liquidity directed from `source` to `target` assuming
@@ -1659,26 +1689,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref> ScoreUpdate for Probabilistic
1659
1689
}
1660
1690
1661
1691
fn time_passed ( & mut self , duration_since_epoch : Duration ) {
1662
- let decay_params = self . decay_params ;
1663
- self . channel_liquidities . retain ( |_scid, liquidity| {
1664
- liquidity. min_liquidity_offset_msat =
1665
- liquidity. decayed_offset ( liquidity. min_liquidity_offset_msat , duration_since_epoch, decay_params) ;
1666
- liquidity. max_liquidity_offset_msat =
1667
- liquidity. decayed_offset ( liquidity. max_liquidity_offset_msat , duration_since_epoch, decay_params) ;
1668
- liquidity. last_updated = duration_since_epoch;
1669
-
1670
- let elapsed_time =
1671
- duration_since_epoch. saturating_sub ( liquidity. offset_history_last_updated ) ;
1672
- if elapsed_time > decay_params. historical_no_updates_half_life {
1673
- let half_life = decay_params. historical_no_updates_half_life . as_secs_f64 ( ) ;
1674
- if half_life != 0.0 {
1675
- liquidity. liquidity_history . decay_buckets ( elapsed_time. as_secs_f64 ( ) / half_life) ;
1676
- liquidity. offset_history_last_updated = duration_since_epoch;
1677
- }
1678
- }
1679
- liquidity. min_liquidity_offset_msat != 0 || liquidity. max_liquidity_offset_msat != 0 ||
1680
- liquidity. liquidity_history . has_datapoints ( )
1681
- } ) ;
1692
+ self . channel_liquidities . time_passed ( duration_since_epoch, self . decay_params ) ;
1682
1693
}
1683
1694
}
1684
1695
0 commit comments