Skip to content

Commit 9d3fdbc

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 b581ee6 commit 9d3fdbc

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
@@ -864,6 +864,14 @@ impl<G: Deref<Target = NetworkGraph>, L: Deref, T: Time> Score for Probabilistic
864864
fn channel_penalty_msat(
865865
&self, short_channel_id: u64, source: &NodeId, target: &NodeId, usage: ChannelUsage
866866
) -> u64 {
867+
if let EffectiveCapacity::ExactLiquidity { liquidity_msat } = usage.effective_capacity {
868+
if usage.amount_msat > liquidity_msat {
869+
return u64::max_value();
870+
} else {
871+
return self.params.base_penalty_msat;
872+
};
873+
}
874+
867875
let liquidity_offset_half_life = self.params.liquidity_offset_half_life;
868876
let amount_msat = usage.amount_msat;
869877
let capacity_msat = usage.effective_capacity.as_msat()
@@ -2678,4 +2686,28 @@ mod tests {
26782686
let usage = ChannelUsage { inflight_htlc_msat: 251, ..usage };
26792687
assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage), u64::max_value());
26802688
}
2689+
2690+
#[test]
2691+
fn removes_uncertainity_when_exact_liquidity_known() {
2692+
let network_graph = network_graph();
2693+
let logger = TestLogger::new();
2694+
let params = ProbabilisticScoringParameters::default();
2695+
let scorer = ProbabilisticScorer::new(params, &network_graph, &logger);
2696+
let source = source_node_id();
2697+
let target = target_node_id();
2698+
2699+
let base_penalty_msat = params.base_penalty_msat;
2700+
let usage = ChannelUsage {
2701+
amount_msat: 750,
2702+
inflight_htlc_msat: 0,
2703+
effective_capacity: EffectiveCapacity::ExactLiquidity { liquidity_msat: 1_000 },
2704+
};
2705+
assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage), base_penalty_msat);
2706+
2707+
let usage = ChannelUsage { amount_msat: 1_000, ..usage };
2708+
assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage), base_penalty_msat);
2709+
2710+
let usage = ChannelUsage { amount_msat: 1_001, ..usage };
2711+
assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage), u64::max_value());
2712+
}
26812713
}

0 commit comments

Comments
 (0)