Provide simple interface to query est. liquidity
authorElias Rohrer <ero@tnull.de>
Sat, 18 Jun 2022 12:40:36 +0000 (14:40 +0200)
committerElias Rohrer <ero@tnull.de>
Sat, 18 Jun 2022 12:56:34 +0000 (14:56 +0200)
lightning/src/routing/scoring.rs

index bfcefc96f5b21b56a3d205d501948a7c9651a686..f7fe5863838f2aefbab77e173fe7fe4ae72c4c0d 100644 (file)
@@ -434,6 +434,23 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
                        }
                }
        }
+
+       /// Query the estimated minimum and maximum liquidity available for sending a payment over the
+       /// channel with `scid` towards the given `target` node.
+       pub fn estimated_channel_liquidity_range(&self, scid: u64, target: &NodeId) -> Option<(u64, u64)> {
+               let graph = self.network_graph.read_only();
+
+               if let Some(chan) = graph.channels().get(&scid) {
+                       if let Some(liq) = self.channel_liquidities.get(&scid) {
+                               if let Some((directed_info, source)) = chan.as_directed_to(target) {
+                                       let amt = directed_info.effective_capacity().as_msat();
+                                       let dir_liq = liq.as_directed(source, target, amt, self.params.liquidity_offset_half_life);
+                                       return Some((dir_liq.min_liquidity_msat(), dir_liq.max_liquidity_msat()));
+                               }
+                       }
+               }
+               None
+       }
 }
 
 impl ProbabilisticScoringParameters {