Skip to content

Commit 37f7be0

Browse files
committed
Score without uncertainty for exact liquidity
For direct channels, the channel liquidity is known with certainty. Use this knowledge in ProbabilisticScorer by either penalizing with the per-hop penalty or u64::max_value depending on the amount.
1 parent 78c19aa commit 37f7be0

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

lightning/src/routing/scoring.rs

+32
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,14 @@ impl<G: Deref<Target = NetworkGraph>, L: Deref, T: Time> Score for Probabilistic
899899
fn channel_penalty_msat(
900900
&self, short_channel_id: u64, source: &NodeId, target: &NodeId, usage: ChannelUsage
901901
) -> u64 {
902+
if let EffectiveCapacity::ExactLiquidity { liquidity_msat } = usage.effective_capacity {
903+
if usage.amount_msat > liquidity_msat {
904+
return u64::max_value();
905+
} else {
906+
return self.params.base_penalty_msat;
907+
};
908+
}
909+
902910
let liquidity_offset_half_life = self.params.liquidity_offset_half_life;
903911
let amount_msat = usage.amount_msat;
904912
let capacity_msat = usage.effective_capacity.as_msat()
@@ -2713,4 +2721,28 @@ mod tests {
27132721
let usage = ChannelUsage { inflight_htlc_msat: 251, ..usage };
27142722
assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage), u64::max_value());
27152723
}
2724+
2725+
#[test]
2726+
fn removes_uncertainity_when_exact_liquidity_known() {
2727+
let network_graph = network_graph();
2728+
let logger = TestLogger::new();
2729+
let params = ProbabilisticScoringParameters::default();
2730+
let scorer = ProbabilisticScorer::new(params, &network_graph, &logger);
2731+
let source = source_node_id();
2732+
let target = target_node_id();
2733+
2734+
let base_penalty_msat = params.base_penalty_msat;
2735+
let usage = ChannelUsage {
2736+
amount_msat: 750,
2737+
inflight_htlc_msat: 0,
2738+
effective_capacity: EffectiveCapacity::ExactLiquidity { liquidity_msat: 1_000 },
2739+
};
2740+
assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage), base_penalty_msat);
2741+
2742+
let usage = ChannelUsage { amount_msat: 1_000, ..usage };
2743+
assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage), base_penalty_msat);
2744+
2745+
let usage = ChannelUsage { amount_msat: 1_001, ..usage };
2746+
assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage), u64::max_value());
2747+
}
27162748
}

0 commit comments

Comments
 (0)