Skip to content

Commit d53cb90

Browse files
committed
Pass InFlightHltcs to the scorer by ownership rather than ref
Given we build `InFlightHtlcs` per route-fetch call, there's no reason to pass them out by reference rather than simply giving the user the full object. This also allows them to tweak the in-flight set before fetching a route.
1 parent bbc15b9 commit d53cb90

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

lightning/src/ln/outbound_payment.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ impl OutboundPayments {
669669

670670
let route = router.find_route_with_id(
671671
&node_signer.get_node_id(Recipient::Node).unwrap(), &route_params,
672-
Some(&first_hops.iter().collect::<Vec<_>>()), &inflight_htlcs(),
672+
Some(&first_hops.iter().collect::<Vec<_>>()), inflight_htlcs(),
673673
payment_hash, payment_id,
674674
).map_err(|_| RetryableSendFailure::RouteNotFound)?;
675675

@@ -712,7 +712,7 @@ impl OutboundPayments {
712712

713713
let route = match router.find_route_with_id(
714714
&node_signer.get_node_id(Recipient::Node).unwrap(), &route_params,
715-
Some(&first_hops.iter().collect::<Vec<_>>()), &inflight_htlcs(),
715+
Some(&first_hops.iter().collect::<Vec<_>>()), inflight_htlcs(),
716716
payment_hash, payment_id,
717717
) {
718718
Ok(route) => route,

lightning/src/routing/router.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl< G: Deref<Target = NetworkGraph<L>>, L: Deref, S: Deref, SP: Sized, Sc: Sco
6464
payer: &PublicKey,
6565
params: &RouteParameters,
6666
first_hops: Option<&[&ChannelDetails]>,
67-
inflight_htlcs: &InFlightHtlcs
67+
inflight_htlcs: InFlightHtlcs
6868
) -> Result<Route, LightningError> {
6969
let random_seed_bytes = {
7070
let mut locked_random_seed_bytes = self.random_seed_bytes.lock().unwrap();
@@ -73,7 +73,7 @@ impl< G: Deref<Target = NetworkGraph<L>>, L: Deref, S: Deref, SP: Sized, Sc: Sco
7373
};
7474
find_route(
7575
payer, params, &self.network_graph, first_hops, &*self.logger,
76-
&ScorerAccountingForInFlightHtlcs::new(self.scorer.lock().deref_mut(), inflight_htlcs),
76+
&ScorerAccountingForInFlightHtlcs::new(self.scorer.lock().deref_mut(), &inflight_htlcs),
7777
&self.score_params,
7878
&random_seed_bytes
7979
)
@@ -85,13 +85,13 @@ pub trait Router {
8585
/// Finds a [`Route`] between `payer` and `payee` for a payment with the given values.
8686
fn find_route(
8787
&self, payer: &PublicKey, route_params: &RouteParameters,
88-
first_hops: Option<&[&ChannelDetails]>, inflight_htlcs: &InFlightHtlcs
88+
first_hops: Option<&[&ChannelDetails]>, inflight_htlcs: InFlightHtlcs
8989
) -> Result<Route, LightningError>;
9090
/// Finds a [`Route`] between `payer` and `payee` for a payment with the given values. Includes
9191
/// `PaymentHash` and `PaymentId` to be able to correlate the request with a specific payment.
9292
fn find_route_with_id(
9393
&self, payer: &PublicKey, route_params: &RouteParameters,
94-
first_hops: Option<&[&ChannelDetails]>, inflight_htlcs: &InFlightHtlcs,
94+
first_hops: Option<&[&ChannelDetails]>, inflight_htlcs: InFlightHtlcs,
9595
_payment_hash: PaymentHash, _payment_id: PaymentId
9696
) -> Result<Route, LightningError> {
9797
self.find_route(payer, route_params, first_hops, inflight_htlcs)
@@ -112,7 +112,7 @@ pub struct ScorerAccountingForInFlightHtlcs<'a, S: Score<ScoreParams = SP>, SP:
112112

113113
impl<'a, S: Score<ScoreParams = SP>, SP: Sized> ScorerAccountingForInFlightHtlcs<'a, S, SP> {
114114
/// Initialize a new `ScorerAccountingForInFlightHtlcs`.
115-
pub fn new(scorer: &'a mut S, inflight_htlcs: &'a InFlightHtlcs) -> Self {
115+
pub fn new(scorer: &'a mut S, inflight_htlcs: &'a InFlightHtlcs) -> Self {
116116
ScorerAccountingForInFlightHtlcs {
117117
scorer,
118118
inflight_htlcs

lightning/src/util/test_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ impl<'a> TestRouter<'a> {
112112
impl<'a> Router for TestRouter<'a> {
113113
fn find_route(
114114
&self, payer: &PublicKey, params: &RouteParameters, first_hops: Option<&[&channelmanager::ChannelDetails]>,
115-
inflight_htlcs: &InFlightHtlcs
115+
inflight_htlcs: InFlightHtlcs
116116
) -> Result<Route, msgs::LightningError> {
117117
if let Some((find_route_query, find_route_res)) = self.next_routes.lock().unwrap().pop_front() {
118118
assert_eq!(find_route_query, *params);
119119
if let Ok(ref route) = find_route_res {
120120
let mut binding = self.scorer.lock().unwrap();
121-
let scorer = ScorerAccountingForInFlightHtlcs::new(binding.deref_mut(), inflight_htlcs);
121+
let scorer = ScorerAccountingForInFlightHtlcs::new(binding.deref_mut(), &inflight_htlcs);
122122
for path in &route.paths {
123123
let mut aggregate_msat = 0u64;
124124
for (idx, hop) in path.hops.iter().rev().enumerate() {

0 commit comments

Comments
 (0)