From 8d5f7c87cb818784ced06ee73b022f28d432f777 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Tue, 20 Dec 2022 18:18:17 -0500 Subject: [PATCH 1/3] Make add_new_pending_payment private to module And expose it in testing only, for safety --- lightning/src/ln/channelmanager.rs | 2 +- lightning/src/ln/outbound_payment.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 026f5a32bca..f31ec7f07a4 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -2386,7 +2386,7 @@ impl ChannelManager, payment_id: PaymentId, route: &Route) -> Result, PaymentSendFailure> { let best_block_height = self.best_block.read().unwrap().height(); - self.pending_outbound_payments.add_new_pending_payment(payment_hash, payment_secret, payment_id, route, &self.keys_manager, best_block_height) + self.pending_outbound_payments.test_add_new_pending_payment(payment_hash, payment_secret, payment_id, route, &self.keys_manager, best_block_height) } diff --git a/lightning/src/ln/outbound_payment.rs b/lightning/src/ln/outbound_payment.rs index e66f0bc25b9..08aeae5c58b 100644 --- a/lightning/src/ln/outbound_payment.rs +++ b/lightning/src/ln/outbound_payment.rs @@ -403,7 +403,15 @@ impl OutboundPayments { } } - pub(super) fn add_new_pending_payment( + #[cfg(test)] + pub(super) fn test_add_new_pending_payment( + &self, payment_hash: PaymentHash, payment_secret: Option, payment_id: PaymentId, + route: &Route, keys_manager: &K, best_block_height: u32 + ) -> Result, PaymentSendFailure> where K::Target: KeysInterface { + self.add_new_pending_payment(payment_hash, payment_secret, payment_id, route, keys_manager, best_block_height) + } + + fn add_new_pending_payment( &self, payment_hash: PaymentHash, payment_secret: Option, payment_id: PaymentId, route: &Route, keys_manager: &K, best_block_height: u32 ) -> Result, PaymentSendFailure> where K::Target: KeysInterface { From 60492d769a31e72fe9c6bc40701b132f94633c60 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Tue, 20 Dec 2022 18:19:22 -0500 Subject: [PATCH 2/3] Fix cfg(test) indentation --- lightning/src/ln/outbound_payment.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lightning/src/ln/outbound_payment.rs b/lightning/src/ln/outbound_payment.rs index 08aeae5c58b..6da14388ad8 100644 --- a/lightning/src/ln/outbound_payment.rs +++ b/lightning/src/ln/outbound_payment.rs @@ -720,9 +720,9 @@ impl OutboundPayments { log_trace!(logger, "Failing outbound payment HTLC with payment_hash {}", log_bytes!(payment_hash.0)); let path_failure = { - #[cfg(test)] + #[cfg(test)] let (network_update, short_channel_id, payment_retryable, onion_error_code, onion_error_data) = onion_error.decode_onion_failure(secp_ctx, logger, &source); - #[cfg(not(test))] + #[cfg(not(test))] let (network_update, short_channel_id, payment_retryable, _, _) = onion_error.decode_onion_failure(secp_ctx, logger, &source); if payment_is_probe(payment_hash, &payment_id, probing_cookie_secret) { From cc60fd601f2e7a5783ba8004439dd6853cd1bae7 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Tue, 20 Dec 2022 18:20:53 -0500 Subject: [PATCH 3/3] outbound_payment: put method signature closing paren on next line in long method signatures --- lightning/src/ln/outbound_payment.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lightning/src/ln/outbound_payment.rs b/lightning/src/ln/outbound_payment.rs index 6da14388ad8..2f6431665b7 100644 --- a/lightning/src/ln/outbound_payment.rs +++ b/lightning/src/ln/outbound_payment.rs @@ -447,7 +447,8 @@ impl OutboundPayments { &self, route: &Route, payment_hash: PaymentHash, payment_secret: &Option, keysend_preimage: Option, payment_id: PaymentId, recv_value_msat: Option, onion_session_privs: Vec<[u8; 32]>, keys_manager: &K, best_block_height: u32, - send_payment_along_path: F) -> Result<(), PaymentSendFailure> + send_payment_along_path: F + ) -> Result<(), PaymentSendFailure> where K::Target: KeysInterface, F: Fn(&Vec, &Option, &PaymentHash, &Option, u64, @@ -556,7 +557,8 @@ impl OutboundPayments { &self, route: &Route, payment_hash: PaymentHash, payment_secret: &Option, keysend_preimage: Option, payment_id: PaymentId, recv_value_msat: Option, onion_session_privs: Vec<[u8; 32]>, keys_manager: &K, best_block_height: u32, - send_payment_along_path: F) -> Result<(), PaymentSendFailure> + send_payment_along_path: F + ) -> Result<(), PaymentSendFailure> where K::Target: KeysInterface, F: Fn(&Vec, &Option, &PaymentHash, &Option, u64, @@ -569,8 +571,8 @@ impl OutboundPayments { pub(super) fn claim_htlc( &self, payment_id: PaymentId, payment_preimage: PaymentPreimage, session_priv: SecretKey, - path: Vec, from_onchain: bool, pending_events: &Mutex>, logger: &L) - where L::Target: Logger { + path: Vec, from_onchain: bool, pending_events: &Mutex>, logger: &L + ) where L::Target: Logger { let mut session_priv_bytes = [0; 32]; session_priv_bytes.copy_from_slice(&session_priv[..]); let mut outbounds = self.pending_outbound_payments.lock().unwrap(); @@ -679,8 +681,8 @@ impl OutboundPayments { &self, source: &HTLCSource, payment_hash: &PaymentHash, onion_error: &HTLCFailReason, path: &Vec, session_priv: &SecretKey, payment_id: &PaymentId, payment_params: &Option, probing_cookie_secret: [u8; 32], - secp_ctx: &Secp256k1, pending_events: &Mutex>, logger: &L) - where L::Target: Logger { + secp_ctx: &Secp256k1, pending_events: &Mutex>, logger: &L + ) where L::Target: Logger { let mut session_priv_bytes = [0; 32]; session_priv_bytes.copy_from_slice(&session_priv[..]); let mut outbounds = self.pending_outbound_payments.lock().unwrap();