Skip to content

Commit 4ca1a31

Browse files
f move payment_path* methods back to InvoicePayer
1 parent 8b4fed2 commit 4ca1a31

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

lightning-invoice/src/payment.rs

Lines changed: 20 additions & 16 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, ProbingRouter};
47+
//! # use lightning_invoice::payment::{InvoicePayer, Payer, Retry, ScoringRouter};
4848
//! # use secp256k1::PublicKey;
4949
//! # use std::cell::RefCell;
5050
//! # use std::ops::Deref;
@@ -76,11 +76,10 @@
7676
//! # &self, payer: &PublicKey, params: &RouteParameters,
7777
//! # first_hops: Option<&[&ChannelDetails]>, _inflight_htlcs: InFlightHtlcs
7878
//! # ) -> Result<Route, LightningError> { unimplemented!() }
79-
//! #
79+
//! # }
80+
//! # impl ScoringRouter for FakeRouter {
8081
//! # fn notify_payment_path_failed(&self, path: &[&RouteHop], short_channel_id: u64) { unimplemented!() }
8182
//! # fn notify_payment_path_successful(&self, path: &[&RouteHop]) { unimplemented!() }
82-
//! # }
83-
//! # impl ProbingRouter for FakeRouter {
8483
//! # fn notify_payment_probe_successful(&self, path: &[&RouteHop]) { unimplemented!() }
8584
//! # fn notify_payment_probe_failed(&self, path: &[&RouteHop], short_channel_id: u64) { unimplemented!() }
8685
//! # }
@@ -177,7 +176,7 @@ use crate::time_utils;
177176
type ConfiguredTime = time_utils::Eternity;
178177

179178
/// (C-not exported) generally all users should use the [`InvoicePayer`] type alias.
180-
pub struct InvoicePayerUsingTime<P: Deref, R: ProbingRouter, L: Deref, E: EventHandler, T: Time>
179+
pub struct InvoicePayerUsingTime<P: Deref, R: ScoringRouter, L: Deref, E: EventHandler, T: Time>
181180
where
182181
P::Target: Payer,
183182
L::Target: Logger,
@@ -266,10 +265,15 @@ pub trait Payer {
266265
fn abandon_payment(&self, payment_id: PaymentId);
267266
}
268267

269-
/// A trait defining behavior for a [`Router`] implementation that also supports probing.
268+
/// A trait defining behavior for a [`Router`] implementation that also supports probing
269+
/// and scoring based on payment success data.
270270
///
271271
/// [`Router`]: lightning::ln::channelmanager::Router
272-
pub trait ProbingRouter: Router {
272+
pub trait ScoringRouter: Router {
273+
/// Lets the router know that payment through a specific path has failed.
274+
fn notify_payment_path_failed(&self, path: &[&RouteHop], short_channel_id: u64);
275+
/// Lets the router know that payment through a specific path was successful.
276+
fn notify_payment_path_successful(&self, path: &[&RouteHop]);
273277
/// Lets the router know that a payment probe was successful.
274278
fn notify_payment_probe_successful(&self, path: &[&RouteHop]);
275279
/// Lets the router know that a payment probe failed.
@@ -315,7 +319,7 @@ pub enum PaymentError {
315319
Sending(PaymentSendFailure),
316320
}
317321

318-
impl<P: Deref, R: ProbingRouter, L: Deref, E: EventHandler, T: Time> InvoicePayerUsingTime<P, R, L, E, T>
322+
impl<P: Deref, R: ScoringRouter, L: Deref, E: EventHandler, T: Time> InvoicePayerUsingTime<P, R, L, E, T>
319323
where
320324
P::Target: Payer,
321325
L::Target: Logger,
@@ -649,7 +653,7 @@ fn has_expired(route_params: &RouteParameters) -> bool {
649653
} else { false }
650654
}
651655

652-
impl<P: Deref, R: ProbingRouter, L: Deref, E: EventHandler, T: Time> EventHandler for InvoicePayerUsingTime<P, R, L, E, T>
656+
impl<P: Deref, R: ScoringRouter, L: Deref, E: EventHandler, T: Time> EventHandler for InvoicePayerUsingTime<P, R, L, E, T>
653657
where
654658
P::Target: Payer,
655659
L::Target: Logger,
@@ -1809,17 +1813,17 @@ mod tests {
18091813
payment_params: Some(route_params.payment_params.clone()), ..Self::route_for_value(route_params.final_value_msat)
18101814
})
18111815
}
1816+
}
18121817

1818+
impl ScoringRouter for TestRouter {
18131819
fn notify_payment_path_failed(&self, path: &[&RouteHop], short_channel_id: u64) {
18141820
self.scorer.lock().payment_path_failed(path, short_channel_id);
18151821
}
18161822

18171823
fn notify_payment_path_successful(&self, path: &[&RouteHop]) {
18181824
self.scorer.lock().payment_path_successful(path);
18191825
}
1820-
}
18211826

1822-
impl ProbingRouter for TestRouter {
18231827
fn notify_payment_probe_successful(&self, path: &[&RouteHop]) {
18241828
self.scorer.lock().probe_successful(path);
18251829
}
@@ -1838,13 +1842,13 @@ mod tests {
18381842
) -> Result<Route, LightningError> {
18391843
Err(LightningError { err: String::new(), action: ErrorAction::IgnoreError })
18401844
}
1845+
}
18411846

1847+
impl ScoringRouter for FailingRouter {
18421848
fn notify_payment_path_failed(&self, _path: &[&RouteHop], _short_channel_id: u64) {}
18431849

18441850
fn notify_payment_path_successful(&self, _path: &[&RouteHop]) {}
1845-
}
18461851

1847-
impl ProbingRouter for FailingRouter {
18481852
fn notify_payment_probe_successful(&self, _path: &[&RouteHop]) {}
18491853

18501854
fn notify_payment_probe_failed(&self, _path: &[&RouteHop], _short_channel_id: u64) {}
@@ -2102,12 +2106,12 @@ mod tests {
21022106
) -> Result<Route, LightningError> {
21032107
self.0.borrow_mut().pop_front().unwrap()
21042108
}
2105-
2109+
}
2110+
impl ScoringRouter for ManualRouter {
21062111
fn notify_payment_path_failed(&self, _path: &[&RouteHop], _short_channel_id: u64) {}
21072112

21082113
fn notify_payment_path_successful(&self, _path: &[&RouteHop]) {}
2109-
}
2110-
impl ProbingRouter for ManualRouter {
2114+
21112115
fn notify_payment_probe_successful(&self, _path: &[&RouteHop]) {}
21122116

21132117
fn notify_payment_probe_failed(&self, _path: &[&RouteHop], _short_channel_id: u64) {}

lightning-invoice/src/utils.rs

Lines changed: 6 additions & 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, ProbingRouter};
4+
use crate::payment::{Payer, ScoringRouter};
55

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

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+
{
571576
fn notify_payment_path_failed(&self, path: &[&RouteHop], short_channel_id: u64) {
572577
self.scorer.lock().payment_path_failed(path, short_channel_id);
573578
}
574579

575580
fn notify_payment_path_successful(&self, path: &[&RouteHop]) {
576581
self.scorer.lock().payment_path_successful(path);
577582
}
578-
}
579583

580-
impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, S: Deref> ProbingRouter for DefaultRouter<G, L, S> where
581-
L::Target: Logger,
582-
S::Target: for <'a> LockableScore<'a>,
583-
{
584584
fn notify_payment_probe_successful(&self, path: &[&RouteHop]) {
585585
self.scorer.lock().probe_successful(path);
586586
}

lightning/src/ln/channelmanager.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,6 @@ pub trait Router {
113113
&self, payer: &PublicKey, route_params: &RouteParameters,
114114
first_hops: Option<&[&ChannelDetails]>, inflight_htlcs: InFlightHtlcs
115115
) -> Result<Route, LightningError>;
116-
/// Lets the router know that payment through a specific path has failed.
117-
fn notify_payment_path_failed(&self, path: &[&RouteHop], short_channel_id: u64);
118-
/// Lets the router know that payment through a specific path was successful.
119-
fn notify_payment_path_successful(&self, path: &[&RouteHop]);
120116
}
121117

122118
// We hold various information about HTLC relay in the HTLC objects in Channel itself:

0 commit comments

Comments
 (0)