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