Skip to content

Commit fe29ac2

Browse files
Remove unnecessary router reference
When parameterizing a method by a router that's behind a Deref, there's no need to pass in &Deref (a reference to a reference). This helps us a bit in upcoming commits because we're adding a wrapper to ChannelManager's internal Router, so without this change we'd need to pass in &&self.router to all of these methods.
1 parent 3926df0 commit fe29ac2

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4664,7 +4664,7 @@ where
46644664
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
46654665
self.pending_outbound_payments
46664666
.send_payment(payment_hash, recipient_onion, payment_id, retry_strategy, route_params,
4667-
&self.router, self.list_usable_channels(), || self.compute_inflight_htlcs(),
4667+
&*self.router, self.list_usable_channels(), || self.compute_inflight_htlcs(),
46684668
&self.entropy_source, &self.node_signer, best_block_height, &self.logger,
46694669
&self.pending_events, |args| self.send_payment_along_path(args))
46704670
}
@@ -4741,7 +4741,7 @@ where
47414741
let features = self.bolt12_invoice_features();
47424742
self.pending_outbound_payments
47434743
.send_payment_for_bolt12_invoice(
4744-
invoice, payment_id, &self.router, self.list_usable_channels(), features,
4744+
invoice, payment_id, &*self.router, self.list_usable_channels(), features,
47454745
|| self.compute_inflight_htlcs(), &self.entropy_source, &self.node_signer, &self,
47464746
&self.secp_ctx, best_block_height, &self.logger, &self.pending_events,
47474747
|args| self.send_payment_along_path(args)
@@ -4816,7 +4816,7 @@ where
48164816
let mut res = Ok(());
48174817
PersistenceNotifierGuard::optionally_notify(self, || {
48184818
let outbound_pmts_res = self.pending_outbound_payments.send_payment_for_static_invoice(
4819-
payment_id, &self.router, self.list_usable_channels(), || self.compute_inflight_htlcs(),
4819+
payment_id, &*self.router, self.list_usable_channels(), || self.compute_inflight_htlcs(),
48204820
&self.entropy_source, &self.node_signer, &self, &self.secp_ctx, best_block_height,
48214821
&self.logger, &self.pending_events, |args| self.send_payment_along_path(args)
48224822
);
@@ -4892,7 +4892,7 @@ where
48924892
let best_block_height = self.best_block.read().unwrap().height;
48934893
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
48944894
self.pending_outbound_payments.send_spontaneous_payment(payment_preimage, recipient_onion,
4895-
payment_id, retry_strategy, route_params, &self.router, self.list_usable_channels(),
4895+
payment_id, retry_strategy, route_params, &*self.router, self.list_usable_channels(),
48964896
|| self.compute_inflight_htlcs(), &self.entropy_source, &self.node_signer, best_block_height,
48974897
&self.logger, &self.pending_events, |args| self.send_payment_along_path(args))
48984898
}
@@ -6271,7 +6271,7 @@ where
62716271
}
62726272

62736273
let best_block_height = self.best_block.read().unwrap().height;
6274-
self.pending_outbound_payments.check_retry_payments(&self.router, || self.list_usable_channels(),
6274+
self.pending_outbound_payments.check_retry_payments(&*self.router, || self.list_usable_channels(),
62756275
|| self.compute_inflight_htlcs(), &self.entropy_source, &self.node_signer, best_block_height,
62766276
&self.pending_events, &self.logger, |args| self.send_payment_along_path(args));
62776277

lightning/src/ln/outbound_payment.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ impl OutboundPayments {
780780

781781
pub(super) fn send_payment<R: Deref, ES: Deref, NS: Deref, IH, SP, L: Deref>(
782782
&self, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields, payment_id: PaymentId,
783-
retry_strategy: Retry, route_params: RouteParameters, router: &R,
783+
retry_strategy: Retry, route_params: RouteParameters, router: R,
784784
first_hops: Vec<ChannelDetails>, compute_inflight_htlcs: IH, entropy_source: &ES,
785785
node_signer: &NS, best_block_height: u32, logger: &L,
786786
pending_events: &Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>, send_payment_along_path: SP,
@@ -817,7 +817,7 @@ impl OutboundPayments {
817817

818818
pub(super) fn send_spontaneous_payment<R: Deref, ES: Deref, NS: Deref, IH, SP, L: Deref>(
819819
&self, payment_preimage: Option<PaymentPreimage>, recipient_onion: RecipientOnionFields,
820-
payment_id: PaymentId, retry_strategy: Retry, route_params: RouteParameters, router: &R,
820+
payment_id: PaymentId, retry_strategy: Retry, route_params: RouteParameters, router: R,
821821
first_hops: Vec<ChannelDetails>, inflight_htlcs: IH, entropy_source: &ES,
822822
node_signer: &NS, best_block_height: u32, logger: &L,
823823
pending_events: &Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>, send_payment_along_path: SP
@@ -842,7 +842,7 @@ impl OutboundPayments {
842842
pub(super) fn send_payment_for_bolt12_invoice<
843843
R: Deref, ES: Deref, NS: Deref, NL: Deref, IH, SP, L: Deref
844844
>(
845-
&self, invoice: &Bolt12Invoice, payment_id: PaymentId, router: &R,
845+
&self, invoice: &Bolt12Invoice, payment_id: PaymentId, router: R,
846846
first_hops: Vec<ChannelDetails>, features: Bolt12InvoiceFeatures, inflight_htlcs: IH,
847847
entropy_source: &ES, node_signer: &NS, node_id_lookup: &NL,
848848
secp_ctx: &Secp256k1<secp256k1::All>, best_block_height: u32, logger: &L,
@@ -904,7 +904,7 @@ impl OutboundPayments {
904904
>(
905905
&self, payment_id: PaymentId, payment_hash: PaymentHash,
906906
keysend_preimage: Option<PaymentPreimage>, invoice_request: Option<&InvoiceRequest>,
907-
mut route_params: RouteParameters, retry_strategy: Retry, router: &R,
907+
mut route_params: RouteParameters, retry_strategy: Retry, router: R,
908908
first_hops: Vec<ChannelDetails>, inflight_htlcs: IH, entropy_source: &ES, node_signer: &NS,
909909
node_id_lookup: &NL, secp_ctx: &Secp256k1<secp256k1::All>, best_block_height: u32, logger: &L,
910910
pending_events: &Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>,
@@ -944,8 +944,8 @@ impl OutboundPayments {
944944
};
945945
let route = match self.find_initial_route(
946946
payment_id, payment_hash, &recipient_onion, keysend_preimage, invoice_request,
947-
&mut route_params, router, &first_hops, &inflight_htlcs, node_signer, best_block_height,
948-
logger,
947+
&mut route_params, router.deref(), &first_hops, &inflight_htlcs, node_signer,
948+
best_block_height, logger,
949949
) {
950950
Ok(route) => route,
951951
Err(e) => {
@@ -1092,7 +1092,7 @@ impl OutboundPayments {
10921092
pub(super) fn send_payment_for_static_invoice<
10931093
R: Deref, ES: Deref, NS: Deref, NL: Deref, IH, SP, L: Deref
10941094
>(
1095-
&self, payment_id: PaymentId, router: &R, first_hops: Vec<ChannelDetails>, inflight_htlcs: IH,
1095+
&self, payment_id: PaymentId, router: R, first_hops: Vec<ChannelDetails>, inflight_htlcs: IH,
10961096
entropy_source: &ES, node_signer: &NS, node_id_lookup: &NL,
10971097
secp_ctx: &Secp256k1<secp256k1::All>, best_block_height: u32, logger: &L,
10981098
pending_events: &Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>,
@@ -1129,7 +1129,7 @@ impl OutboundPayments {
11291129
}
11301130

11311131
pub(super) fn check_retry_payments<R: Deref, ES: Deref, NS: Deref, SP, IH, FH, L: Deref>(
1132-
&self, router: &R, first_hops: FH, inflight_htlcs: IH, entropy_source: &ES, node_signer: &NS,
1132+
&self, router: R, first_hops: FH, inflight_htlcs: IH, entropy_source: &ES, node_signer: &NS,
11331133
best_block_height: u32,
11341134
pending_events: &Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>, logger: &L,
11351135
send_payment_along_path: SP,
@@ -1163,7 +1163,7 @@ impl OutboundPayments {
11631163
}
11641164
core::mem::drop(outbounds);
11651165
if let Some((payment_hash, payment_id, route_params)) = retry_id_route_params {
1166-
self.find_route_and_send_payment(payment_hash, payment_id, route_params, router, first_hops(), &inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, &send_payment_along_path)
1166+
self.find_route_and_send_payment(payment_hash, payment_id, route_params, router.deref(), first_hops(), &inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, &send_payment_along_path)
11671167
} else { break }
11681168
}
11691169

@@ -1195,7 +1195,7 @@ impl OutboundPayments {
11951195
fn find_initial_route<R: Deref, NS: Deref, IH, L: Deref>(
11961196
&self, payment_id: PaymentId, payment_hash: PaymentHash, recipient_onion: &RecipientOnionFields,
11971197
keysend_preimage: Option<PaymentPreimage>, invoice_request: Option<&InvoiceRequest>,
1198-
route_params: &mut RouteParameters, router: &R, first_hops: &Vec<ChannelDetails>,
1198+
route_params: &mut RouteParameters, router: R, first_hops: &Vec<ChannelDetails>,
11991199
inflight_htlcs: &IH, node_signer: &NS, best_block_height: u32, logger: &L,
12001200
) -> Result<Route, RetryableSendFailure>
12011201
where
@@ -1249,7 +1249,7 @@ impl OutboundPayments {
12491249
fn send_payment_internal<R: Deref, NS: Deref, ES: Deref, IH, SP, L: Deref>(
12501250
&self, payment_id: PaymentId, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields,
12511251
keysend_preimage: Option<PaymentPreimage>, retry_strategy: Retry, mut route_params: RouteParameters,
1252-
router: &R, first_hops: Vec<ChannelDetails>, inflight_htlcs: IH, entropy_source: &ES,
1252+
router: R, first_hops: Vec<ChannelDetails>, inflight_htlcs: IH, entropy_source: &ES,
12531253
node_signer: &NS, best_block_height: u32, logger: &L,
12541254
pending_events: &Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>, send_payment_along_path: SP,
12551255
) -> Result<(), RetryableSendFailure>
@@ -1262,8 +1262,8 @@ impl OutboundPayments {
12621262
SP: Fn(SendAlongPathArgs) -> Result<(), APIError>,
12631263
{
12641264
let route = self.find_initial_route(
1265-
payment_id, payment_hash, &recipient_onion, keysend_preimage, None, &mut route_params, router,
1266-
&first_hops, &inflight_htlcs, node_signer, best_block_height, logger,
1265+
payment_id, payment_hash, &recipient_onion, keysend_preimage, None, &mut route_params,
1266+
router.deref(), &first_hops, &inflight_htlcs, node_signer, best_block_height, logger,
12671267
)?;
12681268

12691269
let onion_session_privs = self.add_new_pending_payment(payment_hash,
@@ -1292,7 +1292,7 @@ impl OutboundPayments {
12921292

12931293
fn find_route_and_send_payment<R: Deref, NS: Deref, ES: Deref, IH, SP, L: Deref>(
12941294
&self, payment_hash: PaymentHash, payment_id: PaymentId, route_params: RouteParameters,
1295-
router: &R, first_hops: Vec<ChannelDetails>, inflight_htlcs: &IH, entropy_source: &ES,
1295+
router: R, first_hops: Vec<ChannelDetails>, inflight_htlcs: &IH, entropy_source: &ES,
12961296
node_signer: &NS, best_block_height: u32, logger: &L,
12971297
pending_events: &Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>, send_payment_along_path: &SP,
12981298
)
@@ -1451,7 +1451,7 @@ impl OutboundPayments {
14511451

14521452
fn handle_pay_route_err<R: Deref, NS: Deref, ES: Deref, IH, SP, L: Deref>(
14531453
&self, err: PaymentSendFailure, payment_id: PaymentId, payment_hash: PaymentHash, route: Route,
1454-
mut route_params: RouteParameters, onion_session_privs: Vec<[u8; 32]>, router: &R,
1454+
mut route_params: RouteParameters, onion_session_privs: Vec<[u8; 32]>, router: R,
14551455
first_hops: Vec<ChannelDetails>, inflight_htlcs: &IH, entropy_source: &ES, node_signer: &NS,
14561456
best_block_height: u32, logger: &L,
14571457
pending_events: &Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>,
@@ -2505,7 +2505,7 @@ mod tests {
25052505
Some(Retry::Attempts(1)), Some(expired_route_params.payment_params.clone()),
25062506
&&keys_manager, 0).unwrap();
25072507
outbound_payments.find_route_and_send_payment(
2508-
PaymentHash([0; 32]), PaymentId([0; 32]), expired_route_params, &&router, vec![],
2508+
PaymentHash([0; 32]), PaymentId([0; 32]), expired_route_params, &router, vec![],
25092509
&|| InFlightHtlcs::new(), &&keys_manager, &&keys_manager, 0, &&logger, &pending_events,
25102510
&|_| Ok(()));
25112511
let events = pending_events.lock().unwrap();
@@ -2516,7 +2516,7 @@ mod tests {
25162516
} else {
25172517
let err = outbound_payments.send_payment(
25182518
PaymentHash([0; 32]), RecipientOnionFields::spontaneous_empty(), PaymentId([0; 32]),
2519-
Retry::Attempts(0), expired_route_params, &&router, vec![], || InFlightHtlcs::new(),
2519+
Retry::Attempts(0), expired_route_params, &router, vec![], || InFlightHtlcs::new(),
25202520
&&keys_manager, &&keys_manager, 0, &&logger, &pending_events, |_| Ok(())).unwrap_err();
25212521
if let RetryableSendFailure::PaymentExpired = err { } else { panic!("Unexpected error"); }
25222522
}
@@ -2549,7 +2549,7 @@ mod tests {
25492549
Some(Retry::Attempts(1)), Some(route_params.payment_params.clone()),
25502550
&&keys_manager, 0).unwrap();
25512551
outbound_payments.find_route_and_send_payment(
2552-
PaymentHash([0; 32]), PaymentId([0; 32]), route_params, &&router, vec![],
2552+
PaymentHash([0; 32]), PaymentId([0; 32]), route_params, &router, vec![],
25532553
&|| InFlightHtlcs::new(), &&keys_manager, &&keys_manager, 0, &&logger, &pending_events,
25542554
&|_| Ok(()));
25552555
let events = pending_events.lock().unwrap();
@@ -2558,7 +2558,7 @@ mod tests {
25582558
} else {
25592559
let err = outbound_payments.send_payment(
25602560
PaymentHash([0; 32]), RecipientOnionFields::spontaneous_empty(), PaymentId([0; 32]),
2561-
Retry::Attempts(0), route_params, &&router, vec![], || InFlightHtlcs::new(),
2561+
Retry::Attempts(0), route_params, &router, vec![], || InFlightHtlcs::new(),
25622562
&&keys_manager, &&keys_manager, 0, &&logger, &pending_events, |_| Ok(())).unwrap_err();
25632563
if let RetryableSendFailure::RouteNotFound = err {
25642564
} else { panic!("Unexpected error"); }
@@ -2606,7 +2606,7 @@ mod tests {
26062606
let pending_events = Mutex::new(VecDeque::new());
26072607
outbound_payments.send_payment(
26082608
PaymentHash([0; 32]), RecipientOnionFields::spontaneous_empty(), PaymentId([0; 32]),
2609-
Retry::Attempts(0), route_params.clone(), &&router, vec![], || InFlightHtlcs::new(),
2609+
Retry::Attempts(0), route_params.clone(), &router, vec![], || InFlightHtlcs::new(),
26102610
&&keys_manager, &&keys_manager, 0, &&logger, &pending_events,
26112611
|_| Err(APIError::ChannelUnavailable { err: "test".to_owned() })).unwrap();
26122612
let mut events = pending_events.lock().unwrap();
@@ -2624,15 +2624,15 @@ mod tests {
26242624
// Ensure that a MonitorUpdateInProgress "error" will not result in a PaymentPathFailed event.
26252625
outbound_payments.send_payment(
26262626
PaymentHash([0; 32]), RecipientOnionFields::spontaneous_empty(), PaymentId([0; 32]),
2627-
Retry::Attempts(0), route_params.clone(), &&router, vec![], || InFlightHtlcs::new(),
2627+
Retry::Attempts(0), route_params.clone(), &router, vec![], || InFlightHtlcs::new(),
26282628
&&keys_manager, &&keys_manager, 0, &&logger, &pending_events,
26292629
|_| Err(APIError::MonitorUpdateInProgress)).unwrap();
26302630
assert_eq!(pending_events.lock().unwrap().len(), 0);
26312631

26322632
// Ensure that any other error will result in a PaymentPathFailed event but no blamed scid.
26332633
outbound_payments.send_payment(
26342634
PaymentHash([0; 32]), RecipientOnionFields::spontaneous_empty(), PaymentId([1; 32]),
2635-
Retry::Attempts(0), route_params.clone(), &&router, vec![], || InFlightHtlcs::new(),
2635+
Retry::Attempts(0), route_params.clone(), &router, vec![], || InFlightHtlcs::new(),
26362636
&&keys_manager, &&keys_manager, 0, &&logger, &pending_events,
26372637
|_| Err(APIError::APIMisuseError { err: "test".to_owned() })).unwrap();
26382638
let events = pending_events.lock().unwrap();
@@ -2818,7 +2818,7 @@ mod tests {
28182818

28192819
assert_eq!(
28202820
outbound_payments.send_payment_for_bolt12_invoice(
2821-
&invoice, payment_id, &&router, vec![], Bolt12InvoiceFeatures::empty(),
2821+
&invoice, payment_id, &router, vec![], Bolt12InvoiceFeatures::empty(),
28222822
|| InFlightHtlcs::new(), &&keys_manager, &&keys_manager, &EmptyNodeIdLookUp {},
28232823
&secp_ctx, 0, &&logger, &pending_events, |_| panic!()
28242824
),
@@ -2880,7 +2880,7 @@ mod tests {
28802880

28812881
assert_eq!(
28822882
outbound_payments.send_payment_for_bolt12_invoice(
2883-
&invoice, payment_id, &&router, vec![], Bolt12InvoiceFeatures::empty(),
2883+
&invoice, payment_id, &router, vec![], Bolt12InvoiceFeatures::empty(),
28842884
|| InFlightHtlcs::new(), &&keys_manager, &&keys_manager, &EmptyNodeIdLookUp {},
28852885
&secp_ctx, 0, &&logger, &pending_events, |_| panic!()
28862886
),
@@ -2955,7 +2955,7 @@ mod tests {
29552955
assert!(!outbound_payments.has_pending_payments());
29562956
assert_eq!(
29572957
outbound_payments.send_payment_for_bolt12_invoice(
2958-
&invoice, payment_id, &&router, vec![], Bolt12InvoiceFeatures::empty(),
2958+
&invoice, payment_id, &router, vec![], Bolt12InvoiceFeatures::empty(),
29592959
|| InFlightHtlcs::new(), &&keys_manager, &&keys_manager, &EmptyNodeIdLookUp {},
29602960
&secp_ctx, 0, &&logger, &pending_events, |_| panic!()
29612961
),
@@ -2973,7 +2973,7 @@ mod tests {
29732973

29742974
assert_eq!(
29752975
outbound_payments.send_payment_for_bolt12_invoice(
2976-
&invoice, payment_id, &&router, vec![], Bolt12InvoiceFeatures::empty(),
2976+
&invoice, payment_id, &router, vec![], Bolt12InvoiceFeatures::empty(),
29772977
|| InFlightHtlcs::new(), &&keys_manager, &&keys_manager, &EmptyNodeIdLookUp {},
29782978
&secp_ctx, 0, &&logger, &pending_events, |_| Ok(())
29792979
),
@@ -2984,7 +2984,7 @@ mod tests {
29842984

29852985
assert_eq!(
29862986
outbound_payments.send_payment_for_bolt12_invoice(
2987-
&invoice, payment_id, &&router, vec![], Bolt12InvoiceFeatures::empty(),
2987+
&invoice, payment_id, &router, vec![], Bolt12InvoiceFeatures::empty(),
29882988
|| InFlightHtlcs::new(), &&keys_manager, &&keys_manager, &EmptyNodeIdLookUp {},
29892989
&secp_ctx, 0, &&logger, &pending_events, |_| panic!()
29902990
),

0 commit comments

Comments
 (0)