From 717365fbf94ffd03ba9c5a0b0a6dbfb1e459be0d Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Sat, 18 Jun 2022 14:40:36 +0200 Subject: [PATCH] Provide simple interface to query est. liquidity --- lightning/src/routing/scoring.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lightning/src/routing/scoring.rs b/lightning/src/routing/scoring.rs index bfcefc96f..f7fe58638 100644 --- a/lightning/src/routing/scoring.rs +++ b/lightning/src/routing/scoring.rs @@ -434,6 +434,23 @@ impl>, 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 { -- 2.39.5