Skip to content

Commit 63c65d4

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 7269fa2 commit 63c65d4

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;
@@ -77,8 +77,6 @@
7777
//! # &self, payer: &PublicKey, params: &RouteParameters,
7878
//! # first_hops: Option<&[&ChannelDetails]>, _inflight_htlcs: InFlightHtlcs
7979
//! # ) -> Result<Route, LightningError> { unimplemented!() }
80-
//! # }
81-
//! # impl ScoringRouter for FakeRouter {
8280
//! # fn notify_payment_path_failed(&self, path: &[&RouteHop], short_channel_id: u64) { unimplemented!() }
8381
//! # fn notify_payment_path_successful(&self, path: &[&RouteHop]) { unimplemented!() }
8482
//! # fn notify_payment_probe_successful(&self, path: &[&RouteHop]) { unimplemented!() }
@@ -187,7 +185,7 @@ mod sealed {
187185
/// (C-not exported) generally all users should use the [`InvoicePayer`] type alias.
188186
pub struct InvoicePayerUsingTime<
189187
P: Deref,
190-
R: ScoringRouter,
188+
R: Router,
191189
L: Deref,
192190
E: sealed::BaseEventHandler,
193191
T: Time
@@ -292,30 +290,6 @@ pub trait Payer {
292290
fn abandon_payment(&self, payment_id: PaymentId);
293291
}
294292

295-
/// A trait defining behavior for a [`Router`] implementation that also supports scoring channels
296-
/// based on payment and probe success/failure.
297-
///
298-
/// [`Router`]: lightning::routing::router::Router
299-
pub trait ScoringRouter: Router {
300-
/// Finds a [`Route`] between `payer` and `payee` for a payment with the given values. Includes
301-
/// `PaymentHash` and `PaymentId` to be able to correlate the request with a specific payment.
302-
fn find_route_with_id(
303-
&self, payer: &PublicKey, route_params: &RouteParameters,
304-
first_hops: Option<&[&ChannelDetails]>, inflight_htlcs: InFlightHtlcs,
305-
_payment_hash: PaymentHash, _payment_id: PaymentId
306-
) -> Result<Route, LightningError> {
307-
self.find_route(payer, route_params, first_hops, inflight_htlcs)
308-
}
309-
/// Lets the router know that payment through a specific path has failed.
310-
fn notify_payment_path_failed(&self, path: &[&RouteHop], short_channel_id: u64);
311-
/// Lets the router know that payment through a specific path was successful.
312-
fn notify_payment_path_successful(&self, path: &[&RouteHop]);
313-
/// Lets the router know that a payment probe was successful.
314-
fn notify_payment_probe_successful(&self, path: &[&RouteHop]);
315-
/// Lets the router know that a payment probe failed.
316-
fn notify_payment_probe_failed(&self, path: &[&RouteHop], short_channel_id: u64);
317-
}
318-
319293
/// Strategies available to retry payment path failures for an [`Invoice`].
320294
///
321295
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
@@ -355,7 +329,7 @@ pub enum PaymentError {
355329
Sending(PaymentSendFailure),
356330
}
357331

358-
impl<P: Deref, R: ScoringRouter, L: Deref, E: sealed::BaseEventHandler, T: Time>
332+
impl<P: Deref, R: Router, L: Deref, E: sealed::BaseEventHandler, T: Time>
359333
InvoicePayerUsingTime<P, R, L, E, T>
360334
where
361335
P::Target: Payer,
@@ -763,7 +737,7 @@ fn has_expired(route_params: &RouteParameters) -> bool {
763737
} else { false }
764738
}
765739

766-
impl<P: Deref, R: ScoringRouter, L: Deref, E: sealed::BaseEventHandler, T: Time>
740+
impl<P: Deref, R: Router, L: Deref, E: sealed::BaseEventHandler, T: Time>
767741
InvoicePayerUsingTime<P, R, L, E, T>
768742
where
769743
P::Target: Payer,
@@ -840,7 +814,7 @@ where
840814
}
841815
}
842816

843-
impl<P: Deref, R: ScoringRouter, L: Deref, E: EventHandler, T: Time>
817+
impl<P: Deref, R: Router, L: Deref, E: EventHandler, T: Time>
844818
EventHandler for InvoicePayerUsingTime<P, R, L, E, T>
845819
where
846820
P::Target: Payer,
@@ -854,7 +828,7 @@ where
854828
}
855829
}
856830

857-
impl<P: Deref, R: ScoringRouter, L: Deref, T: Time, F: Future, H: Fn(Event) -> F>
831+
impl<P: Deref, R: Router, L: Deref, T: Time, F: Future, H: Fn(Event) -> F>
858832
InvoicePayerUsingTime<P, R, L, H, T>
859833
where
860834
P::Target: Payer,
@@ -1956,9 +1930,7 @@ mod tests {
19561930
payment_params: Some(route_params.payment_params.clone()), ..Self::route_for_value(route_params.final_value_msat)
19571931
})
19581932
}
1959-
}
19601933

1961-
impl ScoringRouter for TestRouter {
19621934
fn notify_payment_path_failed(&self, path: &[&RouteHop], short_channel_id: u64) {
19631935
self.scorer.lock().payment_path_failed(path, short_channel_id);
19641936
}
@@ -1985,9 +1957,7 @@ mod tests {
19851957
) -> Result<Route, LightningError> {
19861958
Err(LightningError { err: String::new(), action: ErrorAction::IgnoreError })
19871959
}
1988-
}
19891960

1990-
impl ScoringRouter for FailingRouter {
19911961
fn notify_payment_path_failed(&self, _path: &[&RouteHop], _short_channel_id: u64) {}
19921962

19931963
fn notify_payment_path_successful(&self, _path: &[&RouteHop]) {}
@@ -2249,8 +2219,7 @@ mod tests {
22492219
) -> Result<Route, LightningError> {
22502220
self.0.borrow_mut().pop_front().unwrap()
22512221
}
2252-
}
2253-
impl ScoringRouter for ManualRouter {
2222+
22542223
fn notify_payment_path_failed(&self, _path: &[&RouteHop], _short_channel_id: u64) {}
22552224

22562225
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 map with liquidity value (in msat) keyed by a short channel id and the direction the HTLC

0 commit comments

Comments
 (0)