Skip to content

Commit 4715d90

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 197cbc4 commit 4715d90

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
@@ -903,6 +903,14 @@ impl<G: Deref<Target = NetworkGraph>, L: Deref, T: Time> Score for Probabilistic
903903
fn channel_penalty_msat(
904904
&self, short_channel_id: u64, source: &NodeId, target: &NodeId, usage: ChannelUsage
905905
) -> u64 {
906+
if let EffectiveCapacity::ExactLiquidity { liquidity_msat } = usage.effective_capacity {
907+
if usage.amount_msat > liquidity_msat {
908+
return u64::max_value();
909+
} else {
910+
return self.params.base_penalty_msat;
911+
};
912+
}
913+
906914
let liquidity_offset_half_life = self.params.liquidity_offset_half_life;
907915
let amount_msat = usage.amount_msat;
908916
let capacity_msat = usage.effective_capacity.as_msat()
@@ -2574,4 +2582,28 @@ mod tests {
25742582
let usage = ChannelUsage { inflight_htlc_msat: 251, ..usage };
25752583
assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage), u64::max_value());
25762584
}
2585+
2586+
#[test]
2587+
fn removes_uncertainity_when_exact_liquidity_known() {
2588+
let network_graph = network_graph();
2589+
let logger = TestLogger::new();
2590+
let params = ProbabilisticScoringParameters::default();
2591+
let scorer = ProbabilisticScorer::new(params, &network_graph, &logger);
2592+
let source = source_node_id();
2593+
let target = target_node_id();
2594+
2595+
let base_penalty_msat = params.base_penalty_msat;
2596+
let usage = ChannelUsage {
2597+
amount_msat: 750,
2598+
inflight_htlc_msat: 0,
2599+
effective_capacity: EffectiveCapacity::ExactLiquidity { liquidity_msat: 1_000 },
2600+
};
2601+
assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage), base_penalty_msat);
2602+
2603+
let usage = ChannelUsage { amount_msat: 1_000, ..usage };
2604+
assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage), base_penalty_msat);
2605+
2606+
let usage = ChannelUsage { amount_msat: 1_001, ..usage };
2607+
assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage), u64::max_value());
2608+
}
25772609
}

0 commit comments

Comments
 (0)