Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6f40f73

Browse files
committedFeb 10, 2025·
add scores getter on ProbabilisticScorer
Allows access to the scorer state. An example use case is an LSP exposing the global network view in its scorer over http to light clients.
1 parent 630246b commit 6f40f73

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
 

‎lightning/src/routing/scoring.rs

+36
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,11 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref> ProbabilisticScorer<G, L> whe
11481148
pub fn set_scores(&mut self, external_scores: ChannelLiquidities) {
11491149
_ = mem::replace(&mut self.channel_liquidities, external_scores);
11501150
}
1151+
1152+
/// Returns the current scores.
1153+
pub fn scores(&self) -> ChannelLiquidities {
1154+
self.channel_liquidities.clone()
1155+
}
11511156
}
11521157

11531158
impl ChannelLiquidity {
@@ -3943,6 +3948,37 @@ mod tests {
39433948
Some(0.0));
39443949
}
39453950

3951+
#[test]
3952+
fn get_scores() {
3953+
let logger = TestLogger::new();
3954+
let network_graph = network_graph(&logger);
3955+
let params = ProbabilisticScoringFeeParameters {
3956+
liquidity_penalty_multiplier_msat: 1_000,
3957+
..ProbabilisticScoringFeeParameters::zero_penalty()
3958+
};
3959+
let mut scorer = ProbabilisticScorer::new(ProbabilisticScoringDecayParameters::default(), &network_graph, &logger);
3960+
let source = source_node_id();
3961+
let usage = ChannelUsage {
3962+
amount_msat: 500,
3963+
inflight_htlc_msat: 0,
3964+
effective_capacity: EffectiveCapacity::Total { capacity_msat: 1_000, htlc_maximum_msat: 1_000 },
3965+
};
3966+
let successful_path = payment_path_for_amount(200);
3967+
let channel = &network_graph.read_only().channel(42).unwrap().to_owned();
3968+
let (info, _) = channel.as_directed_from(&source).unwrap();
3969+
let candidate = CandidateRouteHop::PublicHop(PublicHopCandidate {
3970+
info,
3971+
short_channel_id: 41,
3972+
});
3973+
3974+
scorer.payment_path_successful(&successful_path, Duration::ZERO);
3975+
assert_eq!(scorer.channel_penalty_msat(&candidate, usage, &params), 301);
3976+
3977+
// Get the scores and assert that both channels are present in the returned struct.
3978+
let scores = scorer.scores();
3979+
assert_eq!(scores.iter().count(), 2);
3980+
}
3981+
39463982
#[test]
39473983
fn combined_scorer() {
39483984
let logger = TestLogger::new();

0 commit comments

Comments
 (0)
Please sign in to comment.