From: Matt Corallo <649246+TheBlueMatt@users.noreply.github.com> Date: Sun, 3 Apr 2022 21:57:19 +0000 (+0000) Subject: Merge pull request #1407 from jkczyz/0.0.106-bindings X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=0357f6a8c9ce3192fb457f4082b2becde7bc58c5;hp=0a0f87c00f3c5e30965751fb46502ebc1f110333;p=rust-lightning Merge pull request #1407 from jkczyz/0.0.106-bindings [0.0.106-bindings] Restrict ChannelInfo::as_directed_from visibility --- diff --git a/lightning-invoice/src/payment.rs b/lightning-invoice/src/payment.rs index 82c07199f..c9553711c 100644 --- a/lightning-invoice/src/payment.rs +++ b/lightning-invoice/src/payment.rs @@ -142,7 +142,7 @@ use crate::prelude::*; use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret}; use lightning::ln::channelmanager::{ChannelDetails, PaymentId, PaymentSendFailure}; use lightning::ln::msgs::LightningError; -use lightning::routing::scoring::{LockableScore, Score}; +use lightning::routing::scoring::{LockableScore, MultiThreadedLockableScore, Score}; use lightning::routing::router::{PaymentParameters, Route, RouteParameters}; use lightning::util::events::{Event, EventHandler}; use lightning::util::logger::Logger; @@ -160,16 +160,15 @@ use std::time::SystemTime; /// See [module-level documentation] for details. /// /// [module-level documentation]: crate::payment -pub struct InvoicePayer +pub struct InvoicePayer>, L: Deref, E: EventHandler> where P::Target: Payer, - R: for <'a> Router<<::Target as LockableScore<'a>>::Locked>, - S::Target: for <'a> LockableScore<'a>, + R::Target: Router, L::Target: Logger, { payer: P, router: R, - scorer: S, + scorer: SR, logger: L, event_handler: E, /// Caches the overall attempts at making a payment, which is updated prior to retrying. @@ -230,11 +229,10 @@ pub enum PaymentError { Sending(PaymentSendFailure), } -impl InvoicePayer +impl>, L: Deref, E: EventHandler> InvoicePayer where P::Target: Payer, - R: for <'a> Router<<::Target as LockableScore<'a>>::Locked>, - S::Target: for <'a> LockableScore<'a>, + R::Target: Router, L::Target: Logger, { /// Creates an invoice payer that retries failed payment paths. @@ -242,7 +240,7 @@ where /// Will forward any [`Event::PaymentPathFailed`] events to the decorated `event_handler` once /// `retry_attempts` has been exceeded for a given [`Invoice`]. pub fn new( - payer: P, router: R, scorer: S, logger: L, event_handler: E, retry_attempts: RetryAttempts + payer: P, router: R, scorer: SR, logger: L, event_handler: E, retry_attempts: RetryAttempts ) -> Self { Self { payer, @@ -468,11 +466,10 @@ fn has_expired(route_params: &RouteParameters) -> bool { } else { false } } -impl EventHandler for InvoicePayer +impl>, L: Deref, E: EventHandler> EventHandler for InvoicePayer where P::Target: Payer, - R: for <'a> Router<<::Target as LockableScore<'a>>::Locked>, - S::Target: for <'a> LockableScore<'a>, + R::Target: Router, L::Target: Logger, { fn handle_event(&self, event: &Event) { diff --git a/lightning/src/routing/network_graph.rs b/lightning/src/routing/network_graph.rs index 282c87051..1a658ee26 100644 --- a/lightning/src/routing/network_graph.rs +++ b/lightning/src/routing/network_graph.rs @@ -685,7 +685,7 @@ pub struct ChannelInfo { impl ChannelInfo { /// Returns a [`DirectedChannelInfo`] for the channel directed to the given `target` from a /// returned `source`, or `None` if `target` is not one of the channel's counterparties. - pub fn as_directed_to(&self, target: &NodeId) -> Option<(DirectedChannelInfo, &NodeId)> { + pub(crate) fn as_directed_to(&self, target: &NodeId) -> Option<(DirectedChannelInfo, &NodeId)> { let (direction, source) = { if target == &self.node_one { (self.two_to_one.as_ref(), &self.node_two) @@ -700,7 +700,7 @@ impl ChannelInfo { /// Returns a [`DirectedChannelInfo`] for the channel directed from the given `source` to a /// returned `target`, or `None` if `source` is not one of the channel's counterparties. - pub fn as_directed_from(&self, source: &NodeId) -> Option<(DirectedChannelInfo, &NodeId)> { + pub(crate) fn as_directed_from(&self, source: &NodeId) -> Option<(DirectedChannelInfo, &NodeId)> { let (direction, target) = { if source == &self.node_one { (self.one_to_two.as_ref(), &self.node_two) diff --git a/lightning/src/routing/scoring.rs b/lightning/src/routing/scoring.rs index b7aa996ce..335a6f1a2 100644 --- a/lightning/src/routing/scoring.rs +++ b/lightning/src/routing/scoring.rs @@ -230,6 +230,7 @@ impl ReadableArgs for FixedPenaltyScorer { } } +#[cfg(not(feature = "no-std"))] /// [`Score`] implementation that provides reasonable default behavior. /// /// Used to apply a fixed penalty to each channel, thus avoiding long paths when shorter paths with @@ -247,12 +248,22 @@ impl ReadableArgs for FixedPenaltyScorer { since = "0.0.105", note = "ProbabilisticScorer should be used instead of Scorer.", )] -pub type Scorer = ScorerUsingTime::; - -#[cfg(not(feature = "no-std"))] -type ConfiguredTime = std::time::Instant; +pub type Scorer = ScorerUsingTime::; #[cfg(feature = "no-std")] -type ConfiguredTime = time::Eternity; +/// [`Score`] implementation that provides reasonable default behavior. +/// +/// Used to apply a fixed penalty to each channel, thus avoiding long paths when shorter paths with +/// slightly higher fees are available. Will further penalize channels that fail to relay payments. +/// +/// See [module-level documentation] for usage and [`ScoringParameters`] for customization. +/// +/// # Note +/// +/// Mixing the `no-std` feature between serialization and deserialization results in undefined +/// behavior. +/// +/// [module-level documentation]: crate::routing::scoring +pub type Scorer = ScorerUsingTime::; // Note that ideally we'd hide ScorerUsingTime from public view by sealing it as well, but rustdoc // doesn't handle this well - instead exposing a `Scorer` which has no trait implementation(s) or @@ -481,6 +492,31 @@ impl Readable for ChannelFailure { } } +#[cfg(not(feature = "no-std"))] +/// [`Score`] implementation using channel success probability distributions. +/// +/// Based on *Optimally Reliable & Cheap Payment Flows on the Lightning Network* by Rene Pickhardt +/// and Stefan Richter [[1]]. Given the uncertainty of channel liquidity balances, probability +/// distributions are defined based on knowledge learned from successful and unsuccessful attempts. +/// Then the negative `log10` of the success probability is used to determine the cost of routing a +/// specific HTLC amount through a channel. +/// +/// Knowledge about channel liquidity balances takes the form of upper and lower bounds on the +/// possible liquidity. Certainty of the bounds is decreased over time using a decay function. See +/// [`ProbabilisticScoringParameters`] for details. +/// +/// Since the scorer aims to learn the current channel liquidity balances, it works best for nodes +/// with high payment volume or that actively probe the [`NetworkGraph`]. Nodes with low payment +/// volume are more likely to experience failed payment paths, which would need to be retried. +/// +/// # Note +/// +/// Mixing the `no-std` feature between serialization and deserialization results in undefined +/// behavior. +/// +/// [1]: https://arxiv.org/abs/2107.05322 +pub type ProbabilisticScorer = ProbabilisticScorerUsingTime::; +#[cfg(feature = "no-std")] /// [`Score`] implementation using channel success probability distributions. /// /// Based on *Optimally Reliable & Cheap Payment Flows on the Lightning Network* by Rene Pickhardt @@ -503,7 +539,7 @@ impl Readable for ChannelFailure { /// behavior. /// /// [1]: https://arxiv.org/abs/2107.05322 -pub type ProbabilisticScorer = ProbabilisticScorerUsingTime::; +pub type ProbabilisticScorer = ProbabilisticScorerUsingTime::; /// Probabilistic [`Score`] implementation. ///