@@ -474,11 +474,43 @@ where L::Target: Logger {
474
474
decay_params : ProbabilisticScoringDecayParameters ,
475
475
network_graph : G ,
476
476
logger : L ,
477
- channel_liquidities : HashMap < u64 , ChannelLiquidity > ,
477
+ channel_liquidities : ChannelLiquidities ,
478
478
}
479
-
479
+ /// ChannelLiquidities contains live and historical liquidity bounds for each channel.
480
480
pub struct ChannelLiquidities ( HashMap < u64 , ChannelLiquidity > ) ;
481
481
482
+ impl ChannelLiquidities {
483
+ fn new ( ) -> Self {
484
+ Self ( new_hash_map ( ) )
485
+ }
486
+
487
+ fn merge ( & mut self , other : Self ) {
488
+ for ( id, item) in other. 0 {
489
+ match self . 0 . get_mut ( & id) {
490
+ None => { self . 0 . insert ( id, item) ; } ,
491
+ Some ( current) => {
492
+ current. merge ( & item) ;
493
+ }
494
+ }
495
+ }
496
+ }
497
+ }
498
+
499
+ impl Deref for ChannelLiquidities {
500
+ type Target = HashMap < u64 , ChannelLiquidity > ;
501
+
502
+ fn deref ( & self ) -> & Self :: Target {
503
+ & self . 0
504
+ }
505
+ }
506
+
507
+
508
+ impl DerefMut for ChannelLiquidities {
509
+ fn deref_mut ( & mut self ) -> & mut Self :: Target {
510
+ & mut self . 0
511
+ }
512
+ }
513
+
482
514
impl Readable for ChannelLiquidities {
483
515
#[ inline]
484
516
fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
@@ -862,23 +894,13 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref> ProbabilisticScorer<G, L> whe
862
894
decay_params,
863
895
network_graph,
864
896
logger,
865
- channel_liquidities : new_hash_map ( ) ,
897
+ channel_liquidities : ChannelLiquidities :: new ( ) ,
866
898
}
867
899
}
868
900
869
901
/// Merge external channel liquidity data into the internal state.
870
902
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
- }
903
+ self . channel_liquidities . merge ( other) ;
882
904
}
883
905
884
906
#[ cfg( test) ]
@@ -2126,10 +2148,7 @@ ReadableArgs<(ProbabilisticScoringDecayParameters, G, L)> for ProbabilisticScore
2126
2148
r : & mut R , args : ( ProbabilisticScoringDecayParameters , G , L )
2127
2149
) -> Result < Self , DecodeError > {
2128
2150
let ( decay_params, network_graph, logger) = args;
2129
- let mut channel_liquidities = new_hash_map ( ) ;
2130
- read_tlv_fields ! ( r, {
2131
- ( 0 , channel_liquidities, required) ,
2132
- } ) ;
2151
+ let channel_liquidities = ChannelLiquidities :: read ( r) ?;
2133
2152
Ok ( Self {
2134
2153
decay_params,
2135
2154
network_graph,
0 commit comments