Skip to content

[0.0.105] (Bindings Only) Concretize LockableScore as MultiThreadedLockableScore #1338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions lightning-invoice/src/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -160,16 +160,15 @@ use std::time::SystemTime;
/// See [module-level documentation] for details.
///
/// [module-level documentation]: crate::payment
pub struct InvoicePayer<P: Deref, R, S: Deref, L: Deref, E: EventHandler>
pub struct InvoicePayer<P: Deref, S: Score, R: Deref, SR: Deref<Target = MultiThreadedLockableScore<S>>, L: Deref, E: EventHandler>
where
P::Target: Payer,
R: for <'a> Router<<<S as Deref>::Target as LockableScore<'a>>::Locked>,
S::Target: for <'a> LockableScore<'a>,
R::Target: Router<S>,
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.
Expand Down Expand Up @@ -230,19 +229,18 @@ pub enum PaymentError {
Sending(PaymentSendFailure),
}

impl<P: Deref, R, S: Deref, L: Deref, E: EventHandler> InvoicePayer<P, R, S, L, E>
impl<P: Deref, S: Score, R: Deref, SR: Deref<Target = MultiThreadedLockableScore<S>>, L: Deref, E: EventHandler> InvoicePayer<P, S, R, SR, L, E>
where
P::Target: Payer,
R: for <'a> Router<<<S as Deref>::Target as LockableScore<'a>>::Locked>,
S::Target: for <'a> LockableScore<'a>,
R::Target: Router<S>,
L::Target: Logger,
{
/// Creates an invoice payer that retries failed payment paths.
///
/// 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,
Expand Down Expand Up @@ -468,11 +466,10 @@ fn has_expired(route_params: &RouteParameters) -> bool {
} else { false }
}

impl<P: Deref, R, S: Deref, L: Deref, E: EventHandler> EventHandler for InvoicePayer<P, R, S, L, E>
impl<P: Deref, S: Score, R: Deref, SR: Deref<Target = MultiThreadedLockableScore<S>>, L: Deref, E: EventHandler> EventHandler for InvoicePayer<P, S, R, SR, L, E>
where
P::Target: Payer,
R: for <'a> Router<<<S as Deref>::Target as LockableScore<'a>>::Locked>,
S::Target: for <'a> LockableScore<'a>,
R::Target: Router<S>,
L::Target: Logger,
{
fn handle_event(&self, event: &Event) {
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/routing/network_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,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)
Expand Down
11 changes: 6 additions & 5 deletions lightning/src/routing/scoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,10 @@ impl Score for FixedPenaltyScorer {
since = "0.0.105",
note = "ProbabilisticScorer should be used instead of Scorer.",
)]
pub type Scorer = ScorerUsingTime::<ConfiguredTime>;

#[cfg(not(feature = "no-std"))]
type ConfiguredTime = std::time::Instant;
pub type Scorer = ScorerUsingTime::<std::time::Instant>;
#[cfg(feature = "no-std")]
type ConfiguredTime = time::Eternity;
pub type Scorer = ScorerUsingTime::<time::Eternity>;

// 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
Expand Down Expand Up @@ -487,7 +485,10 @@ impl<T: Time> Readable for ChannelFailure<T> {
/// behavior.
///
/// [1]: https://arxiv.org/abs/2107.05322
pub type ProbabilisticScorer<G> = ProbabilisticScorerUsingTime::<G, ConfiguredTime>;
#[cfg(not(feature = "no-std"))]
pub type ProbabilisticScorer<G> = ProbabilisticScorerUsingTime::<G, std::time::Instant>;
#[cfg(feature = "no-std")]
pub type ProbabilisticScorer<G> = ProbabilisticScorerUsingTime::<G, time::Eternity>;

/// Probabilistic [`Score`] implementation.
///
Expand Down