@@ -477,6 +477,19 @@ where L::Target: Logger {
477
477
channel_liquidities : HashMap < u64 , ChannelLiquidity > ,
478
478
}
479
479
480
+ pub struct ChannelLiquidities ( HashMap < u64 , ChannelLiquidity > ) ;
481
+
482
+ impl Readable for ChannelLiquidities {
483
+ #[ inline]
484
+ fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
485
+ let mut channel_liquidities = new_hash_map ( ) ;
486
+ read_tlv_fields ! ( r, {
487
+ ( 0 , channel_liquidities, required) ,
488
+ } ) ;
489
+ Ok ( ChannelLiquidities ( channel_liquidities) )
490
+ }
491
+ }
492
+
480
493
/// Parameters for configuring [`ProbabilisticScorer`].
481
494
///
482
495
/// Used to configure base, liquidity, and amount penalties, the sum of which comprises the channel
@@ -804,7 +817,7 @@ impl ProbabilisticScoringDecayParameters {
804
817
/// first node in the ordering of the channel's counterparties. Thus, swapping the two liquidity
805
818
/// offset fields gives the opposite direction.
806
819
#[ repr( C ) ] // Force the fields in memory to be in the order we specify
807
- struct ChannelLiquidity {
820
+ pub struct ChannelLiquidity {
808
821
/// Lower channel liquidity bound in terms of an offset from zero.
809
822
min_liquidity_offset_msat : u64 ,
810
823
@@ -814,7 +827,7 @@ struct ChannelLiquidity {
814
827
liquidity_history : HistoricalLiquidityTracker ,
815
828
816
829
/// Time when either liquidity bound was last modified as an offset since the unix epoch.
817
- last_updated : Duration ,
830
+ pub last_updated : Duration ,
818
831
819
832
/// Time when the historical liquidity bounds were last modified as an offset against the unix
820
833
/// epoch.
@@ -853,6 +866,21 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref> ProbabilisticScorer<G, L> whe
853
866
}
854
867
}
855
868
869
+ /// Merge external channel liquidity data into the internal state.
870
+ pub fn merge ( & mut self , other : ChannelLiquidities ) {
871
+
872
+ let channel_liquidities = & mut self . channel_liquidities ;
873
+
874
+ for ( id, item) in other. 0 {
875
+ match channel_liquidities. get_mut ( & id) {
876
+ None => { channel_liquidities. insert ( id, item) ; } ,
877
+ Some ( current) => {
878
+ current. merge ( & item) ;
879
+ }
880
+ }
881
+ }
882
+ }
883
+
856
884
#[ cfg( test) ]
857
885
fn with_channel ( mut self , short_channel_id : u64 , liquidity : ChannelLiquidity ) -> Self {
858
886
assert ! ( self . channel_liquidities. insert( short_channel_id, liquidity) . is_none( ) ) ;
@@ -1074,6 +1102,12 @@ impl ChannelLiquidity {
1074
1102
}
1075
1103
}
1076
1104
1105
+ fn merge ( & mut self , other : & Self ) {
1106
+ self . liquidity_history . merge ( & other. liquidity_history ) ;
1107
+
1108
+ // TODO: Merge other fields.
1109
+ }
1110
+
1077
1111
/// Returns a view of the channel liquidity directed from `source` to `target` assuming
1078
1112
/// `capacity_msat`.
1079
1113
fn as_directed (
@@ -1805,6 +1839,13 @@ mod bucketed_history {
1805
1839
self . buckets [ bucket] = self . buckets [ bucket] . saturating_add ( BUCKET_FIXED_POINT_ONE ) ;
1806
1840
}
1807
1841
}
1842
+
1843
+ /// Returns the average of the buckets between the two trackers.
1844
+ pub ( crate ) fn merge ( & mut self , other : & Self ) -> ( ) {
1845
+ for ( index, bucket) in self . buckets . iter_mut ( ) . enumerate ( ) {
1846
+ * bucket = ( * bucket + other. buckets [ index] ) / 2 ;
1847
+ }
1848
+ }
1808
1849
}
1809
1850
1810
1851
impl_writeable_tlv_based ! ( HistoricalBucketRangeTracker , { ( 0 , buckets, required) } ) ;
@@ -1901,6 +1942,12 @@ mod bucketed_history {
1901
1942
-> DirectedHistoricalLiquidityTracker < & ' a mut HistoricalLiquidityTracker > {
1902
1943
DirectedHistoricalLiquidityTracker { source_less_than_target, tracker : self }
1903
1944
}
1945
+
1946
+ pub fn merge ( & mut self , other : & Self ) {
1947
+ self . min_liquidity_offset_history . merge ( & other. min_liquidity_offset_history ) ;
1948
+ self . max_liquidity_offset_history . merge ( & other. max_liquidity_offset_history ) ;
1949
+ self . recalculate_valid_point_count ( ) ;
1950
+ }
1904
1951
}
1905
1952
1906
1953
/// A set of buckets representing the history of where we've seen the minimum- and maximum-
0 commit comments