@@ -316,12 +316,44 @@ impl ReadableArgs<u64> for FixedPenaltyScorer {
316
316
}
317
317
318
318
#[ cfg( not( feature = "no-std" ) ) ]
319
- type ConfiguredTime = std:: time:: Instant ;
320
- #[ cfg( feature = "no-std" ) ]
321
- use crate :: util:: time:: Eternity ;
319
+ /// [`Score`] implementation using channel success probability distributions.
320
+ ///
321
+ /// Channels are tracked with upper and lower liquidity bounds - when an HTLC fails at a channel,
322
+ /// we learn that the upper-bound on the available liquidity is lower than the amount of the HTLC.
323
+ /// When a payment is forwarded through a channel (but fails later in the route), we learn the
324
+ /// lower-bound on the channel's available liquidity must be at least the value of the HTLC.
325
+ ///
326
+ /// These bounds are then used to determine a success probability using the formula from
327
+ /// *Optimally Reliable & Cheap Payment Flows on the Lightning Network* by Rene Pickhardt
328
+ /// and Stefan Richter [[1]] (i.e. `(upper_bound - payment_amount) / (upper_bound - lower_bound)`).
329
+ ///
330
+ /// This probability is combined with the [`liquidity_penalty_multiplier_msat`] and
331
+ /// [`liquidity_penalty_amount_multiplier_msat`] parameters to calculate a concrete penalty in
332
+ /// milli-satoshis. The penalties, when added across all hops, have the property of being linear in
333
+ /// terms of the entire path's success probability. This allows the router to directly compare
334
+ /// penalties for different paths. See the documentation of those parameters for the exact formulas.
335
+ ///
336
+ /// The liquidity bounds are decayed by halving them every [`liquidity_offset_half_life`].
337
+ ///
338
+ /// Further, we track the history of our upper and lower liquidity bounds for each channel,
339
+ /// allowing us to assign a second penalty (using [`historical_liquidity_penalty_multiplier_msat`]
340
+ /// and [`historical_liquidity_penalty_amount_multiplier_msat`]) based on the same probability
341
+ /// formula, but using the history of a channel rather than our latest estimates for the liquidity
342
+ /// bounds.
343
+ ///
344
+ /// # Note
345
+ ///
346
+ /// Mixing the `no-std` feature between serialization and deserialization results in undefined
347
+ /// behavior.
348
+ ///
349
+ /// [1]: https://arxiv.org/abs/2107.05322
350
+ /// [`liquidity_penalty_multiplier_msat`]: ProbabilisticScoringParameters::liquidity_penalty_multiplier_msat
351
+ /// [`liquidity_penalty_amount_multiplier_msat`]: ProbabilisticScoringParameters::liquidity_penalty_amount_multiplier_msat
352
+ /// [`liquidity_offset_half_life`]: ProbabilisticScoringParameters::liquidity_offset_half_life
353
+ /// [`historical_liquidity_penalty_multiplier_msat`]: ProbabilisticScoringParameters::historical_liquidity_penalty_multiplier_msat
354
+ /// [`historical_liquidity_penalty_amount_multiplier_msat`]: ProbabilisticScoringParameters::historical_liquidity_penalty_amount_multiplier_msat
355
+ pub type ProbabilisticScorer < G , L > = ProbabilisticScorerUsingTime :: < G , L , std:: time:: Instant > ;
322
356
#[ cfg( feature = "no-std" ) ]
323
- type ConfiguredTime = Eternity ;
324
-
325
357
/// [`Score`] implementation using channel success probability distributions.
326
358
///
327
359
/// Channels are tracked with upper and lower liquidity bounds - when an HTLC fails at a channel,
@@ -358,7 +390,7 @@ type ConfiguredTime = Eternity;
358
390
/// [`liquidity_offset_half_life`]: ProbabilisticScoringParameters::liquidity_offset_half_life
359
391
/// [`historical_liquidity_penalty_multiplier_msat`]: ProbabilisticScoringParameters::historical_liquidity_penalty_multiplier_msat
360
392
/// [`historical_liquidity_penalty_amount_multiplier_msat`]: ProbabilisticScoringParameters::historical_liquidity_penalty_amount_multiplier_msat
361
- pub type ProbabilisticScorer < G , L > = ProbabilisticScorerUsingTime :: < G , L , ConfiguredTime > ;
393
+ pub type ProbabilisticScorer < G , L > = ProbabilisticScorerUsingTime :: < G , L , crate :: util :: time :: Eternity > ;
362
394
363
395
/// Probabilistic [`Score`] implementation.
364
396
///
0 commit comments