From: Matt Corallo Date: Thu, 28 Oct 2021 15:39:01 +0000 (+0000) Subject: WTF is an HRTB X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=refs%2Fheads%2F1144-magic;p=rust-lightning WTF is an HRTB --- diff --git a/lightning-invoice/src/payment.rs b/lightning-invoice/src/payment.rs index fe6a25f1a..66a54d34f 100644 --- a/lightning-invoice/src/payment.rs +++ b/lightning-invoice/src/payment.rs @@ -131,11 +131,11 @@ use std::sync::Mutex; use std::time::{Duration, SystemTime}; /// A utility for paying [`Invoice]`s. -pub struct InvoicePayer<'a: 'b, 'b, P: Deref, R, S, L: Deref, E> +pub struct InvoicePayer where P::Target: Payer, R: Router, - S: routing::LockableScore<'a, 'b>, + S: for <'b> routing::LockableScore<'b>, L::Target: Logger, E: EventHandler, { @@ -146,7 +146,6 @@ where event_handler: E, payment_cache: Mutex>, retry_attempts: RetryAttempts, - phantom: std::marker::PhantomData<(&'a (), &'b ())>, } /// A trait defining behavior of an [`Invoice`] payer. @@ -190,11 +189,11 @@ pub enum PaymentError { Sending(PaymentSendFailure), } -impl<'a: 'b, 'b, P: Deref, R, S, L: Deref, E> InvoicePayer<'a, 'b, P, R, S, L, E> +impl InvoicePayer where P::Target: Payer, R: Router, - S: routing::LockableScore<'a, 'b>, + S: for <'b> routing::LockableScore<'b>, L::Target: Logger, E: EventHandler, { @@ -213,7 +212,6 @@ where event_handler, payment_cache: Mutex::new(HashMap::new()), retry_attempts, - phantom: std::marker::PhantomData, } } @@ -307,11 +305,11 @@ fn has_expired(params: &RouteParameters) -> bool { Invoice::is_expired_from_epoch(&SystemTime::UNIX_EPOCH, expiry_time) } -impl<'a: 'b, 'b, P: Deref, R, S, L: Deref, E> EventHandler for InvoicePayer<'a, 'b, P, R, S, L, E> +impl EventHandler for InvoicePayer where P::Target: Payer, R: Router, - S: routing::LockableScore<'a, 'b>, + S: for <'b> routing::LockableScore<'b>, L::Target: Logger, E: EventHandler, { diff --git a/lightning/src/routing/mod.rs b/lightning/src/routing/mod.rs index 4c5469c5f..faee78540 100644 --- a/lightning/src/routing/mod.rs +++ b/lightning/src/routing/mod.rs @@ -32,16 +32,17 @@ pub trait Score { fn payment_path_failed(&mut self, path: &Vec, short_channel_id: u64); } -pub trait LockableScore<'a: 'b, 'b> { - type Locked: Score; - - fn lock(&'a self) -> Self::Locked; +/// +pub trait LockableScore<'b> { + /// + type Locked: Score + 'b; + /// + fn lock(&'b self) -> Self::Locked; } -impl<'a: 'b, 'b, S: 'b + Score, T: Deref>> LockableScore<'a, 'b> for T { +impl<'b, S: Score + 'b, T: Deref>> LockableScore<'b> for T { type Locked = MutexGuard<'b, S>; - - fn lock(&'a self) -> Self::Locked { + fn lock(&'b self) -> MutexGuard<'b, S> { self.deref().lock().unwrap() } }