Skip to content

Commit 76d77ce

Browse files
Move ScoringRouter methods to Router
This helps us prepare to move all payment retries into ChannelManager, which is needed for trampoline payments.
1 parent 2c57878 commit 76d77ce

File tree

3 files changed

+16
-44
lines changed

3 files changed

+16
-44
lines changed

lightning-invoice/src/payment.rs

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
//! # use lightning::util::logger::{Logger, Record};
4545
//! # use lightning::util::ser::{Writeable, Writer};
4646
//! # use lightning_invoice::Invoice;
47-
//! # use lightning_invoice::payment::{InvoicePayer, Payer, Retry, ScoringRouter};
47+
//! # use lightning_invoice::payment::{InvoicePayer, Payer, Retry};
4848
//! # use secp256k1::PublicKey;
4949
//! # use std::cell::RefCell;
5050
//! # use std::ops::Deref;
@@ -78,8 +78,6 @@
7878
//! # &self, payer: &PublicKey, params: &RouteParameters,
7979
//! # first_hops: Option<&[&ChannelDetails]>, _inflight_htlcs: InFlightHtlcs
8080
//! # ) -> Result<Route, LightningError> { unimplemented!() }
81-
//! # }
82-
//! # impl ScoringRouter for FakeRouter {
8381
//! # fn notify_payment_path_failed(&self, path: &[&RouteHop], short_channel_id: u64) { unimplemented!() }
8482
//! # fn notify_payment_path_successful(&self, path: &[&RouteHop]) { unimplemented!() }
8583
//! # fn notify_payment_probe_successful(&self, path: &[&RouteHop]) { unimplemented!() }
@@ -186,7 +184,7 @@ mod sealed {
186184
/// (C-not exported) generally all users should use the [`InvoicePayer`] type alias.
187185
pub struct InvoicePayerUsingTime<
188186
P: Deref,
189-
R: ScoringRouter,
187+
R: Router,
190188
L: Deref,
191189
E: sealed::BaseEventHandler,
192190
T: Time
@@ -279,30 +277,6 @@ pub trait Payer {
279277
fn inflight_htlcs(&self) -> InFlightHtlcs;
280278
}
281279

282-
/// A trait defining behavior for a [`Router`] implementation that also supports scoring channels
283-
/// based on payment and probe success/failure.
284-
///
285-
/// [`Router`]: lightning::routing::router::Router
286-
pub trait ScoringRouter: Router {
287-
/// Finds a [`Route`] between `payer` and `payee` for a payment with the given values. Includes
288-
/// `PaymentHash` and `PaymentId` to be able to correlate the request with a specific payment.
289-
fn find_route_with_id(
290-
&self, payer: &PublicKey, route_params: &RouteParameters,
291-
first_hops: Option<&[&ChannelDetails]>, inflight_htlcs: InFlightHtlcs,
292-
_payment_hash: PaymentHash, _payment_id: PaymentId
293-
) -> Result<Route, LightningError> {
294-
self.find_route(payer, route_params, first_hops, inflight_htlcs)
295-
}
296-
/// Lets the router know that payment through a specific path has failed.
297-
fn notify_payment_path_failed(&self, path: &[&RouteHop], short_channel_id: u64);
298-
/// Lets the router know that payment through a specific path was successful.
299-
fn notify_payment_path_successful(&self, path: &[&RouteHop]);
300-
/// Lets the router know that a payment probe was successful.
301-
fn notify_payment_probe_successful(&self, path: &[&RouteHop]);
302-
/// Lets the router know that a payment probe failed.
303-
fn notify_payment_probe_failed(&self, path: &[&RouteHop], short_channel_id: u64);
304-
}
305-
306280
/// Strategies available to retry payment path failures for an [`Invoice`].
307281
///
308282
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
@@ -342,7 +316,7 @@ pub enum PaymentError {
342316
Sending(PaymentSendFailure),
343317
}
344318

345-
impl<P: Deref, R: ScoringRouter, L: Deref, E: sealed::BaseEventHandler, T: Time>
319+
impl<P: Deref, R: Router, L: Deref, E: sealed::BaseEventHandler, T: Time>
346320
InvoicePayerUsingTime<P, R, L, E, T>
347321
where
348322
P::Target: Payer,
@@ -656,7 +630,7 @@ fn has_expired(route_params: &RouteParameters) -> bool {
656630
} else { false }
657631
}
658632

659-
impl<P: Deref, R: ScoringRouter, L: Deref, E: sealed::BaseEventHandler, T: Time>
633+
impl<P: Deref, R: Router, L: Deref, E: sealed::BaseEventHandler, T: Time>
660634
InvoicePayerUsingTime<P, R, L, E, T>
661635
where
662636
P::Target: Payer,
@@ -723,7 +697,7 @@ where
723697
}
724698
}
725699

726-
impl<P: Deref, R: ScoringRouter, L: Deref, E: EventHandler, T: Time>
700+
impl<P: Deref, R: Router, L: Deref, E: EventHandler, T: Time>
727701
EventHandler for InvoicePayerUsingTime<P, R, L, E, T>
728702
where
729703
P::Target: Payer,
@@ -737,7 +711,7 @@ where
737711
}
738712
}
739713

740-
impl<P: Deref, R: ScoringRouter, L: Deref, T: Time, F: Future, H: Fn(Event) -> F>
714+
impl<P: Deref, R: Router, L: Deref, T: Time, F: Future, H: Fn(Event) -> F>
741715
InvoicePayerUsingTime<P, R, L, H, T>
742716
where
743717
P::Target: Payer,
@@ -1726,9 +1700,7 @@ mod tests {
17261700
payment_params: Some(route_params.payment_params.clone()), ..Self::route_for_value(route_params.final_value_msat)
17271701
})
17281702
}
1729-
}
17301703

1731-
impl ScoringRouter for TestRouter {
17321704
fn notify_payment_path_failed(&self, path: &[&RouteHop], short_channel_id: u64) {
17331705
self.scorer.lock().payment_path_failed(path, short_channel_id);
17341706
}
@@ -1755,9 +1727,7 @@ mod tests {
17551727
) -> Result<Route, LightningError> {
17561728
Err(LightningError { err: String::new(), action: ErrorAction::IgnoreError })
17571729
}
1758-
}
17591730

1760-
impl ScoringRouter for FailingRouter {
17611731
fn notify_payment_path_failed(&self, _path: &[&RouteHop], _short_channel_id: u64) {}
17621732

17631733
fn notify_payment_path_successful(&self, _path: &[&RouteHop]) {}
@@ -2045,8 +2015,7 @@ mod tests {
20452015
) -> Result<Route, LightningError> {
20462016
self.0.borrow_mut().pop_front().unwrap()
20472017
}
2048-
}
2049-
impl ScoringRouter for ManualRouter {
2018+
20502019
fn notify_payment_path_failed(&self, _path: &[&RouteHop], _short_channel_id: u64) {}
20512020

20522021
fn notify_payment_path_successful(&self, _path: &[&RouteHop]) {}

lightning-invoice/src/utils.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Convenient utilities to create an invoice.
22
33
use crate::{CreationError, Currency, Invoice, InvoiceBuilder, SignOrCreationError};
4-
use crate::payment::{Payer, ScoringRouter};
4+
use crate::payment::Payer;
55

66
use crate::{prelude::*, Description, InvoiceDescription, Sha256};
77
use bech32::ToBase32;
@@ -567,12 +567,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, S: Deref> Router for DefaultR
567567
&random_seed_bytes
568568
)
569569
}
570-
}
571570

572-
impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, S: Deref> ScoringRouter for DefaultRouter<G, L, S> where
573-
L::Target: Logger,
574-
S::Target: for <'a> LockableScore<'a>,
575-
{
576571
fn notify_payment_path_failed(&self, path: &[&RouteHop], short_channel_id: u64) {
577572
self.scorer.lock().payment_path_failed(path, short_channel_id);
578573
}

lightning/src/routing/router.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ pub trait Router {
3636
&self, payer: &PublicKey, route_params: &RouteParameters,
3737
first_hops: Option<&[&ChannelDetails]>, inflight_htlcs: InFlightHtlcs
3838
) -> Result<Route, LightningError>;
39+
/// Lets the router know that payment through a specific path has failed.
40+
fn notify_payment_path_failed(&self, path: &[&RouteHop], short_channel_id: u64);
41+
/// Lets the router know that payment through a specific path was successful.
42+
fn notify_payment_path_successful(&self, path: &[&RouteHop]);
43+
/// Lets the router know that a payment probe was successful.
44+
fn notify_payment_probe_successful(&self, path: &[&RouteHop]);
45+
/// Lets the router know that a payment probe failed.
46+
fn notify_payment_probe_failed(&self, path: &[&RouteHop], short_channel_id: u64);
3947
}
4048

4149
/// A data structure for tracking in-flight HTLCs. May be used during pathfinding to account for

0 commit comments

Comments
 (0)