Skip to content

Commit 4d33002

Browse files
Take in-flight HTLCs by reference in Router::find_route
Useful in upcoming work when for payment retries.
1 parent 195eb0a commit 4d33002

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

fuzz/src/chanmon_consistency.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ struct FuzzRouter {}
9090
impl Router for FuzzRouter {
9191
fn find_route(
9292
&self, _payer: &PublicKey, _params: &RouteParameters, _first_hops: Option<&[&ChannelDetails]>,
93-
_inflight_htlcs: InFlightHtlcs
93+
_inflight_htlcs: &InFlightHtlcs
9494
) -> Result<Route, msgs::LightningError> {
9595
Err(msgs::LightningError {
9696
err: String::from("Not implemented"),

fuzz/src/full_stack.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ struct FuzzRouter {}
132132
impl Router for FuzzRouter {
133133
fn find_route(
134134
&self, _payer: &PublicKey, _params: &RouteParameters, _first_hops: Option<&[&ChannelDetails]>,
135-
_inflight_htlcs: InFlightHtlcs
135+
_inflight_htlcs: &InFlightHtlcs
136136
) -> Result<Route, msgs::LightningError> {
137137
Err(msgs::LightningError {
138138
err: String::from("Not implemented"),

lightning-invoice/src/payment.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
//! # impl Router for FakeRouter {
7777
//! # fn find_route(
7878
//! # &self, payer: &PublicKey, params: &RouteParameters,
79-
//! # first_hops: Option<&[&ChannelDetails]>, _inflight_htlcs: InFlightHtlcs
79+
//! # first_hops: Option<&[&ChannelDetails]>, _inflight_htlcs: &InFlightHtlcs
8080
//! # ) -> Result<Route, LightningError> { unimplemented!() }
8181
//! # fn notify_payment_path_failed(&self, path: &[&RouteHop], short_channel_id: u64) { unimplemented!() }
8282
//! # fn notify_payment_path_successful(&self, path: &[&RouteHop]) { unimplemented!() }
@@ -510,7 +510,7 @@ where
510510
let first_hops = self.payer.first_hops();
511511
let inflight_htlcs = self.payer.inflight_htlcs();
512512
let route = self.router.find_route(
513-
&payer, &params, Some(&first_hops.iter().collect::<Vec<_>>()), inflight_htlcs
513+
&payer, &params, Some(&first_hops.iter().collect::<Vec<_>>()), &inflight_htlcs
514514
).map_err(|e| PaymentError::Routing(e))?;
515515

516516
match send_payment(&route) {
@@ -578,7 +578,7 @@ where
578578
let inflight_htlcs = self.payer.inflight_htlcs();
579579

580580
let route = self.router.find_route(
581-
&payer, &params, Some(&first_hops.iter().collect::<Vec<_>>()), inflight_htlcs
581+
&payer, &params, Some(&first_hops.iter().collect::<Vec<_>>()), &inflight_htlcs
582582
);
583583

584584
if route.is_err() {
@@ -1670,7 +1670,7 @@ mod tests {
16701670
impl Router for TestRouter {
16711671
fn find_route(
16721672
&self, payer: &PublicKey, route_params: &RouteParameters,
1673-
_first_hops: Option<&[&ChannelDetails]>, inflight_htlcs: InFlightHtlcs
1673+
_first_hops: Option<&[&ChannelDetails]>, inflight_htlcs: &InFlightHtlcs
16741674
) -> Result<Route, LightningError> {
16751675
// Simulate calling the Scorer just as you would in find_route
16761676
let route = Self::route_for_value(route_params.final_value_msat);
@@ -1723,7 +1723,7 @@ mod tests {
17231723
impl Router for FailingRouter {
17241724
fn find_route(
17251725
&self, _payer: &PublicKey, _params: &RouteParameters, _first_hops: Option<&[&ChannelDetails]>,
1726-
_inflight_htlcs: InFlightHtlcs,
1726+
_inflight_htlcs: &InFlightHtlcs,
17271727
) -> Result<Route, LightningError> {
17281728
Err(LightningError { err: String::new(), action: ErrorAction::IgnoreError })
17291729
}
@@ -2011,7 +2011,7 @@ mod tests {
20112011
impl Router for ManualRouter {
20122012
fn find_route(
20132013
&self, _payer: &PublicKey, _params: &RouteParameters, _first_hops: Option<&[&ChannelDetails]>,
2014-
_inflight_htlcs: InFlightHtlcs
2014+
_inflight_htlcs: &InFlightHtlcs
20152015
) -> Result<Route, LightningError> {
20162016
self.0.borrow_mut().pop_front().unwrap()
20172017
}

lightning/src/routing/router.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, S: Deref> Router for DefaultR
6161
{
6262
fn find_route(
6363
&self, payer: &PublicKey, params: &RouteParameters, first_hops: Option<&[&ChannelDetails]>,
64-
inflight_htlcs: InFlightHtlcs
64+
inflight_htlcs: &InFlightHtlcs
6565
) -> Result<Route, LightningError> {
6666
let random_seed_bytes = {
6767
let mut locked_random_seed_bytes = self.random_seed_bytes.lock().unwrap();
@@ -98,13 +98,13 @@ pub trait Router {
9898
/// Finds a [`Route`] between `payer` and `payee` for a payment with the given values.
9999
fn find_route(
100100
&self, payer: &PublicKey, route_params: &RouteParameters,
101-
first_hops: Option<&[&ChannelDetails]>, inflight_htlcs: InFlightHtlcs
101+
first_hops: Option<&[&ChannelDetails]>, inflight_htlcs: &InFlightHtlcs
102102
) -> Result<Route, LightningError>;
103103
/// Finds a [`Route`] between `payer` and `payee` for a payment with the given values. Includes
104104
/// `PaymentHash` and `PaymentId` to be able to correlate the request with a specific payment.
105105
fn find_route_with_id(
106106
&self, payer: &PublicKey, route_params: &RouteParameters,
107-
first_hops: Option<&[&ChannelDetails]>, inflight_htlcs: InFlightHtlcs,
107+
first_hops: Option<&[&ChannelDetails]>, inflight_htlcs: &InFlightHtlcs,
108108
_payment_hash: PaymentHash, _payment_id: PaymentId
109109
) -> Result<Route, LightningError> {
110110
self.find_route(payer, route_params, first_hops, inflight_htlcs)
@@ -128,12 +128,12 @@ pub trait Router {
128128
pub struct ScorerAccountingForInFlightHtlcs<'a, S: Score> {
129129
scorer: &'a mut S,
130130
// Maps a channel's short channel id and its direction to the liquidity used up.
131-
inflight_htlcs: InFlightHtlcs,
131+
inflight_htlcs: &'a InFlightHtlcs,
132132
}
133133

134134
impl<'a, S: Score> ScorerAccountingForInFlightHtlcs<'a, S> {
135135
/// Initialize a new `ScorerAccountingForInFlightHtlcs`.
136-
pub fn new(scorer: &'a mut S, inflight_htlcs: InFlightHtlcs) -> Self {
136+
pub fn new(scorer: &'a mut S, inflight_htlcs: &'a InFlightHtlcs) -> Self {
137137
ScorerAccountingForInFlightHtlcs {
138138
scorer,
139139
inflight_htlcs

lightning/src/util/test_utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ impl<'a> TestRouter<'a> {
8686
impl<'a> Router for TestRouter<'a> {
8787
fn find_route(
8888
&self, payer: &PublicKey, params: &RouteParameters, first_hops: Option<&[&channelmanager::ChannelDetails]>,
89-
inflight_htlcs: InFlightHtlcs
89+
inflight_htlcs: &InFlightHtlcs
9090
) -> Result<Route, msgs::LightningError> {
9191
let logger = TestLogger::new();
9292
find_route(
9393
payer, params, &self.network_graph, first_hops, &logger,
94-
&ScorerAccountingForInFlightHtlcs::new(&mut TestScorer::with_penalty(0), inflight_htlcs),
94+
&ScorerAccountingForInFlightHtlcs::new(&mut TestScorer::with_penalty(0), &inflight_htlcs),
9595
&[42; 32]
9696
)
9797
}

0 commit comments

Comments
 (0)