Skip to content

Commit 5009528

Browse files
authored
Merge pull request #1338 from TheBlueMatt/2022-02-bindings-105
[0.0.105] (Bindings Only) Concretize LockableScore as MultiThreadedLockableScore
2 parents 6259e7a + 2d210c0 commit 5009528

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

lightning-invoice/src/payment.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ use crate::prelude::*;
142142
use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
143143
use lightning::ln::channelmanager::{ChannelDetails, PaymentId, PaymentSendFailure};
144144
use lightning::ln::msgs::LightningError;
145-
use lightning::routing::scoring::{LockableScore, Score};
145+
use lightning::routing::scoring::{LockableScore, MultiThreadedLockableScore, Score};
146146
use lightning::routing::router::{PaymentParameters, Route, RouteParameters};
147147
use lightning::util::events::{Event, EventHandler};
148148
use lightning::util::logger::Logger;
@@ -160,16 +160,15 @@ use std::time::SystemTime;
160160
/// See [module-level documentation] for details.
161161
///
162162
/// [module-level documentation]: crate::payment
163-
pub struct InvoicePayer<P: Deref, R, S: Deref, L: Deref, E: EventHandler>
163+
pub struct InvoicePayer<P: Deref, S: Score, R: Deref, SR: Deref<Target = MultiThreadedLockableScore<S>>, L: Deref, E: EventHandler>
164164
where
165165
P::Target: Payer,
166-
R: for <'a> Router<<<S as Deref>::Target as LockableScore<'a>>::Locked>,
167-
S::Target: for <'a> LockableScore<'a>,
166+
R::Target: Router<S>,
168167
L::Target: Logger,
169168
{
170169
payer: P,
171170
router: R,
172-
scorer: S,
171+
scorer: SR,
173172
logger: L,
174173
event_handler: E,
175174
/// Caches the overall attempts at making a payment, which is updated prior to retrying.
@@ -230,19 +229,18 @@ pub enum PaymentError {
230229
Sending(PaymentSendFailure),
231230
}
232231

233-
impl<P: Deref, R, S: Deref, L: Deref, E: EventHandler> InvoicePayer<P, R, S, L, E>
232+
impl<P: Deref, S: Score, R: Deref, SR: Deref<Target = MultiThreadedLockableScore<S>>, L: Deref, E: EventHandler> InvoicePayer<P, S, R, SR, L, E>
234233
where
235234
P::Target: Payer,
236-
R: for <'a> Router<<<S as Deref>::Target as LockableScore<'a>>::Locked>,
237-
S::Target: for <'a> LockableScore<'a>,
235+
R::Target: Router<S>,
238236
L::Target: Logger,
239237
{
240238
/// Creates an invoice payer that retries failed payment paths.
241239
///
242240
/// Will forward any [`Event::PaymentPathFailed`] events to the decorated `event_handler` once
243241
/// `retry_attempts` has been exceeded for a given [`Invoice`].
244242
pub fn new(
245-
payer: P, router: R, scorer: S, logger: L, event_handler: E, retry_attempts: RetryAttempts
243+
payer: P, router: R, scorer: SR, logger: L, event_handler: E, retry_attempts: RetryAttempts
246244
) -> Self {
247245
Self {
248246
payer,
@@ -468,11 +466,10 @@ fn has_expired(route_params: &RouteParameters) -> bool {
468466
} else { false }
469467
}
470468

471-
impl<P: Deref, R, S: Deref, L: Deref, E: EventHandler> EventHandler for InvoicePayer<P, R, S, L, E>
469+
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>
472470
where
473471
P::Target: Payer,
474-
R: for <'a> Router<<<S as Deref>::Target as LockableScore<'a>>::Locked>,
475-
S::Target: for <'a> LockableScore<'a>,
472+
R::Target: Router<S>,
476473
L::Target: Logger,
477474
{
478475
fn handle_event(&self, event: &Event) {

lightning/src/routing/network_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ pub struct ChannelInfo {
662662
impl ChannelInfo {
663663
/// Returns a [`DirectedChannelInfo`] for the channel directed to the given `target` from a
664664
/// returned `source`, or `None` if `target` is not one of the channel's counterparties.
665-
pub fn as_directed_to(&self, target: &NodeId) -> Option<(DirectedChannelInfo, &NodeId)> {
665+
pub(crate) fn as_directed_to(&self, target: &NodeId) -> Option<(DirectedChannelInfo, &NodeId)> {
666666
let (direction, source) = {
667667
if target == &self.node_one {
668668
(self.two_to_one.as_ref(), &self.node_two)

lightning/src/routing/scoring.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,10 @@ impl Score for FixedPenaltyScorer {
232232
since = "0.0.105",
233233
note = "ProbabilisticScorer should be used instead of Scorer.",
234234
)]
235-
pub type Scorer = ScorerUsingTime::<ConfiguredTime>;
236-
237235
#[cfg(not(feature = "no-std"))]
238-
type ConfiguredTime = std::time::Instant;
236+
pub type Scorer = ScorerUsingTime::<std::time::Instant>;
239237
#[cfg(feature = "no-std")]
240-
type ConfiguredTime = time::Eternity;
238+
pub type Scorer = ScorerUsingTime::<time::Eternity>;
241239

242240
// Note that ideally we'd hide ScorerUsingTime from public view by sealing it as well, but rustdoc
243241
// doesn't handle this well - instead exposing a `Scorer` which has no trait implementation(s) or
@@ -487,7 +485,10 @@ impl<T: Time> Readable for ChannelFailure<T> {
487485
/// behavior.
488486
///
489487
/// [1]: https://arxiv.org/abs/2107.05322
490-
pub type ProbabilisticScorer<G> = ProbabilisticScorerUsingTime::<G, ConfiguredTime>;
488+
#[cfg(not(feature = "no-std"))]
489+
pub type ProbabilisticScorer<G> = ProbabilisticScorerUsingTime::<G, std::time::Instant>;
490+
#[cfg(feature = "no-std")]
491+
pub type ProbabilisticScorer<G> = ProbabilisticScorerUsingTime::<G, time::Eternity>;
491492

492493
/// Probabilistic [`Score`] implementation.
493494
///

0 commit comments

Comments
 (0)