Skip to content

Commit 0c87dda

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 9e2da63 commit 0c87dda

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

0 commit comments

Comments
 (0)