Move send_payment_along_path to take args as struct

Cleans up and paves the way for additional arguments to be added more easily,
specifically an update_add_htlc's blinding point.
This commit is contained in:
Valentine Wallace 2023-06-22 15:40:24 -04:00
parent 15b1c9b837
commit 80f904c5eb
No known key found for this signature in database
GPG key ID: FD3E106A2CE099B4
2 changed files with 61 additions and 63 deletions

View file

@ -53,7 +53,7 @@ use crate::ln::onion_utils::HTLCFailReason;
use crate::ln::msgs::{ChannelMessageHandler, DecodeError, LightningError}; use crate::ln::msgs::{ChannelMessageHandler, DecodeError, LightningError};
#[cfg(test)] #[cfg(test)]
use crate::ln::outbound_payment; use crate::ln::outbound_payment;
use crate::ln::outbound_payment::{OutboundPayments, PaymentAttempts, PendingOutboundPayment}; use crate::ln::outbound_payment::{OutboundPayments, PaymentAttempts, PendingOutboundPayment, SendAlongPathArgs};
use crate::ln::wire::Encode; use crate::ln::wire::Encode;
use crate::sign::{EntropySource, KeysManager, NodeSigner, Recipient, SignerProvider, ChannelSigner, WriteableEcdsaChannelSigner}; use crate::sign::{EntropySource, KeysManager, NodeSigner, Recipient, SignerProvider, ChannelSigner, WriteableEcdsaChannelSigner};
use crate::util::config::{UserConfig, ChannelConfig, ChannelConfigUpdate}; use crate::util::config::{UserConfig, ChannelConfig, ChannelConfigUpdate};
@ -2992,10 +2992,17 @@ where
#[cfg(test)] #[cfg(test)]
pub(crate) fn test_send_payment_along_path(&self, path: &Path, payment_hash: &PaymentHash, recipient_onion: RecipientOnionFields, total_value: u64, cur_height: u32, payment_id: PaymentId, keysend_preimage: &Option<PaymentPreimage>, session_priv_bytes: [u8; 32]) -> Result<(), APIError> { pub(crate) fn test_send_payment_along_path(&self, path: &Path, payment_hash: &PaymentHash, recipient_onion: RecipientOnionFields, total_value: u64, cur_height: u32, payment_id: PaymentId, keysend_preimage: &Option<PaymentPreimage>, session_priv_bytes: [u8; 32]) -> Result<(), APIError> {
let _lck = self.total_consistency_lock.read().unwrap(); let _lck = self.total_consistency_lock.read().unwrap();
self.send_payment_along_path(path, payment_hash, recipient_onion, total_value, cur_height, payment_id, keysend_preimage, session_priv_bytes) self.send_payment_along_path(SendAlongPathArgs {
path, payment_hash, recipient_onion, total_value, cur_height, payment_id, keysend_preimage,
session_priv_bytes
})
} }
fn send_payment_along_path(&self, path: &Path, payment_hash: &PaymentHash, recipient_onion: RecipientOnionFields, total_value: u64, cur_height: u32, payment_id: PaymentId, keysend_preimage: &Option<PaymentPreimage>, session_priv_bytes: [u8; 32]) -> Result<(), APIError> { fn send_payment_along_path(&self, args: SendAlongPathArgs) -> Result<(), APIError> {
let SendAlongPathArgs {
path, payment_hash, recipient_onion, total_value, cur_height, payment_id, keysend_preimage,
session_priv_bytes
} = args;
// The top-level caller should hold the total_consistency_lock read lock. // The top-level caller should hold the total_consistency_lock read lock.
debug_assert!(self.total_consistency_lock.try_write().is_err()); debug_assert!(self.total_consistency_lock.try_write().is_err());
@ -3125,9 +3132,9 @@ where
let best_block_height = self.best_block.read().unwrap().height(); let best_block_height = self.best_block.read().unwrap().height();
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
self.pending_outbound_payments self.pending_outbound_payments
.send_payment_with_route(route, payment_hash, recipient_onion, payment_id, &self.entropy_source, &self.node_signer, best_block_height, .send_payment_with_route(route, payment_hash, recipient_onion, payment_id,
|path, payment_hash, recipient_onion, total_value, cur_height, payment_id, keysend_preimage, session_priv| &self.entropy_source, &self.node_signer, best_block_height,
self.send_payment_along_path(path, payment_hash, recipient_onion, total_value, cur_height, payment_id, keysend_preimage, session_priv)) |args| self.send_payment_along_path(args))
} }
/// Similar to [`ChannelManager::send_payment_with_route`], but will automatically find a route based on /// Similar to [`ChannelManager::send_payment_with_route`], but will automatically find a route based on
@ -3139,18 +3146,16 @@ where
.send_payment(payment_hash, recipient_onion, payment_id, retry_strategy, route_params, .send_payment(payment_hash, recipient_onion, payment_id, retry_strategy, route_params,
&self.router, self.list_usable_channels(), || self.compute_inflight_htlcs(), &self.router, self.list_usable_channels(), || self.compute_inflight_htlcs(),
&self.entropy_source, &self.node_signer, best_block_height, &self.logger, &self.entropy_source, &self.node_signer, best_block_height, &self.logger,
&self.pending_events, &self.pending_events, |args| self.send_payment_along_path(args))
|path, payment_hash, recipient_onion, total_value, cur_height, payment_id, keysend_preimage, session_priv|
self.send_payment_along_path(path, payment_hash, recipient_onion, total_value, cur_height, payment_id, keysend_preimage, session_priv))
} }
#[cfg(test)] #[cfg(test)]
pub(super) fn test_send_payment_internal(&self, route: &Route, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields, keysend_preimage: Option<PaymentPreimage>, payment_id: PaymentId, recv_value_msat: Option<u64>, onion_session_privs: Vec<[u8; 32]>) -> Result<(), PaymentSendFailure> { pub(super) fn test_send_payment_internal(&self, route: &Route, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields, keysend_preimage: Option<PaymentPreimage>, payment_id: PaymentId, recv_value_msat: Option<u64>, onion_session_privs: Vec<[u8; 32]>) -> Result<(), PaymentSendFailure> {
let best_block_height = self.best_block.read().unwrap().height(); let best_block_height = self.best_block.read().unwrap().height();
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
self.pending_outbound_payments.test_send_payment_internal(route, payment_hash, recipient_onion, keysend_preimage, payment_id, recv_value_msat, onion_session_privs, &self.node_signer, best_block_height, self.pending_outbound_payments.test_send_payment_internal(route, payment_hash, recipient_onion,
|path, payment_hash, recipient_onion, total_value, cur_height, payment_id, keysend_preimage, session_priv| keysend_preimage, payment_id, recv_value_msat, onion_session_privs, &self.node_signer,
self.send_payment_along_path(path, payment_hash, recipient_onion, total_value, cur_height, payment_id, keysend_preimage, session_priv)) best_block_height, |args| self.send_payment_along_path(args))
} }
#[cfg(test)] #[cfg(test)]
@ -3204,9 +3209,7 @@ where
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
self.pending_outbound_payments.send_spontaneous_payment_with_route( self.pending_outbound_payments.send_spontaneous_payment_with_route(
route, payment_preimage, recipient_onion, payment_id, &self.entropy_source, route, payment_preimage, recipient_onion, payment_id, &self.entropy_source,
&self.node_signer, best_block_height, &self.node_signer, best_block_height, |args| self.send_payment_along_path(args))
|path, payment_hash, recipient_onion, total_value, cur_height, payment_id, keysend_preimage, session_priv|
self.send_payment_along_path(path, payment_hash, recipient_onion, total_value, cur_height, payment_id, keysend_preimage, session_priv))
} }
/// Similar to [`ChannelManager::send_spontaneous_payment`], but will automatically find a route /// Similar to [`ChannelManager::send_spontaneous_payment`], but will automatically find a route
@ -3222,9 +3225,7 @@ where
self.pending_outbound_payments.send_spontaneous_payment(payment_preimage, recipient_onion, self.pending_outbound_payments.send_spontaneous_payment(payment_preimage, recipient_onion,
payment_id, retry_strategy, route_params, &self.router, self.list_usable_channels(), payment_id, retry_strategy, route_params, &self.router, self.list_usable_channels(),
|| self.compute_inflight_htlcs(), &self.entropy_source, &self.node_signer, best_block_height, || self.compute_inflight_htlcs(), &self.entropy_source, &self.node_signer, best_block_height,
&self.logger, &self.pending_events, &self.logger, &self.pending_events, |args| self.send_payment_along_path(args))
|path, payment_hash, recipient_onion, total_value, cur_height, payment_id, keysend_preimage, session_priv|
self.send_payment_along_path(path, payment_hash, recipient_onion, total_value, cur_height, payment_id, keysend_preimage, session_priv))
} }
/// Send a payment that is probing the given route for liquidity. We calculate the /// Send a payment that is probing the given route for liquidity. We calculate the
@ -3233,9 +3234,9 @@ where
pub fn send_probe(&self, path: Path) -> Result<(PaymentHash, PaymentId), PaymentSendFailure> { pub fn send_probe(&self, path: Path) -> Result<(PaymentHash, PaymentId), PaymentSendFailure> {
let best_block_height = self.best_block.read().unwrap().height(); let best_block_height = self.best_block.read().unwrap().height();
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
self.pending_outbound_payments.send_probe(path, self.probing_cookie_secret, &self.entropy_source, &self.node_signer, best_block_height, self.pending_outbound_payments.send_probe(path, self.probing_cookie_secret,
|path, payment_hash, recipient_onion, total_value, cur_height, payment_id, keysend_preimage, session_priv| &self.entropy_source, &self.node_signer, best_block_height,
self.send_payment_along_path(path, payment_hash, recipient_onion, total_value, cur_height, payment_id, keysend_preimage, session_priv)) |args| self.send_payment_along_path(args))
} }
/// Returns whether a payment with the given [`PaymentHash`] and [`PaymentId`] is, in fact, a /// Returns whether a payment with the given [`PaymentHash`] and [`PaymentId`] is, in fact, a
@ -4039,9 +4040,7 @@ where
let best_block_height = self.best_block.read().unwrap().height(); let best_block_height = self.best_block.read().unwrap().height();
self.pending_outbound_payments.check_retry_payments(&self.router, || self.list_usable_channels(), self.pending_outbound_payments.check_retry_payments(&self.router, || self.list_usable_channels(),
|| self.compute_inflight_htlcs(), &self.entropy_source, &self.node_signer, best_block_height, || self.compute_inflight_htlcs(), &self.entropy_source, &self.node_signer, best_block_height,
&self.pending_events, &self.logger, &self.pending_events, &self.logger, |args| self.send_payment_along_path(args));
|path, payment_hash, recipient_onion, total_value, cur_height, payment_id, keysend_preimage, session_priv|
self.send_payment_along_path(path, payment_hash, recipient_onion, total_value, cur_height, payment_id, keysend_preimage, session_priv));
for (htlc_source, payment_hash, failure_reason, destination) in failed_forwards.drain(..) { for (htlc_source, payment_hash, failure_reason, destination) in failed_forwards.drain(..) {
self.fail_htlc_backwards_internal(&htlc_source, &payment_hash, &failure_reason, destination); self.fail_htlc_backwards_internal(&htlc_source, &payment_hash, &failure_reason, destination);

View file

@ -473,6 +473,18 @@ impl RecipientOnionFields {
} }
} }
/// Arguments for [`super::channelmanager::ChannelManager::send_payment_along_path`].
pub(super) struct SendAlongPathArgs<'a> {
pub path: &'a Path,
pub payment_hash: &'a PaymentHash,
pub recipient_onion: RecipientOnionFields,
pub total_value: u64,
pub cur_height: u32,
pub payment_id: PaymentId,
pub keysend_preimage: &'a Option<PaymentPreimage>,
pub session_priv_bytes: [u8; 32],
}
pub(super) struct OutboundPayments { pub(super) struct OutboundPayments {
pub(super) pending_outbound_payments: Mutex<HashMap<PaymentId, PendingOutboundPayment>>, pub(super) pending_outbound_payments: Mutex<HashMap<PaymentId, PendingOutboundPayment>>,
pub(super) retry_lock: Mutex<()>, pub(super) retry_lock: Mutex<()>,
@ -499,8 +511,7 @@ impl OutboundPayments {
NS::Target: NodeSigner, NS::Target: NodeSigner,
L::Target: Logger, L::Target: Logger,
IH: Fn() -> InFlightHtlcs, IH: Fn() -> InFlightHtlcs,
SP: Fn(&Path, &PaymentHash, RecipientOnionFields, u64, u32, PaymentId, SP: Fn(SendAlongPathArgs) -> Result<(), APIError>,
&Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>,
{ {
self.send_payment_internal(payment_id, payment_hash, recipient_onion, None, retry_strategy, self.send_payment_internal(payment_id, payment_hash, recipient_onion, None, retry_strategy,
route_params, router, first_hops, &compute_inflight_htlcs, entropy_source, node_signer, route_params, router, first_hops, &compute_inflight_htlcs, entropy_source, node_signer,
@ -515,8 +526,7 @@ impl OutboundPayments {
where where
ES::Target: EntropySource, ES::Target: EntropySource,
NS::Target: NodeSigner, NS::Target: NodeSigner,
F: Fn(&Path, &PaymentHash, RecipientOnionFields, u64, u32, PaymentId, F: Fn(SendAlongPathArgs) -> Result<(), APIError>
&Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>
{ {
let onion_session_privs = self.add_new_pending_payment(payment_hash, recipient_onion.clone(), payment_id, None, route, None, None, entropy_source, best_block_height)?; let onion_session_privs = self.add_new_pending_payment(payment_hash, recipient_onion.clone(), payment_id, None, route, None, None, entropy_source, best_block_height)?;
self.pay_route_internal(route, payment_hash, recipient_onion, None, payment_id, None, self.pay_route_internal(route, payment_hash, recipient_onion, None, payment_id, None,
@ -537,8 +547,7 @@ impl OutboundPayments {
NS::Target: NodeSigner, NS::Target: NodeSigner,
L::Target: Logger, L::Target: Logger,
IH: Fn() -> InFlightHtlcs, IH: Fn() -> InFlightHtlcs,
SP: Fn(&Path, &PaymentHash, RecipientOnionFields, u64, u32, PaymentId, SP: Fn(SendAlongPathArgs) -> Result<(), APIError>,
&Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>,
{ {
let preimage = payment_preimage let preimage = payment_preimage
.unwrap_or_else(|| PaymentPreimage(entropy_source.get_secure_random_bytes())); .unwrap_or_else(|| PaymentPreimage(entropy_source.get_secure_random_bytes()));
@ -557,8 +566,7 @@ impl OutboundPayments {
where where
ES::Target: EntropySource, ES::Target: EntropySource,
NS::Target: NodeSigner, NS::Target: NodeSigner,
F: Fn(&Path, &PaymentHash, RecipientOnionFields, u64, u32, PaymentId, F: Fn(SendAlongPathArgs) -> Result<(), APIError>,
&Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>
{ {
let preimage = payment_preimage let preimage = payment_preimage
.unwrap_or_else(|| PaymentPreimage(entropy_source.get_secure_random_bytes())); .unwrap_or_else(|| PaymentPreimage(entropy_source.get_secure_random_bytes()));
@ -587,8 +595,7 @@ impl OutboundPayments {
R::Target: Router, R::Target: Router,
ES::Target: EntropySource, ES::Target: EntropySource,
NS::Target: NodeSigner, NS::Target: NodeSigner,
SP: Fn(&Path, &PaymentHash, RecipientOnionFields, u64, u32, PaymentId, SP: Fn(SendAlongPathArgs) -> Result<(), APIError>,
&Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>,
IH: Fn() -> InFlightHtlcs, IH: Fn() -> InFlightHtlcs,
FH: Fn() -> Vec<ChannelDetails>, FH: Fn() -> Vec<ChannelDetails>,
L::Target: Logger, L::Target: Logger,
@ -658,8 +665,7 @@ impl OutboundPayments {
NS::Target: NodeSigner, NS::Target: NodeSigner,
L::Target: Logger, L::Target: Logger,
IH: Fn() -> InFlightHtlcs, IH: Fn() -> InFlightHtlcs,
SP: Fn(&Path, &PaymentHash, RecipientOnionFields, u64, u32, PaymentId, SP: Fn(SendAlongPathArgs) -> Result<(), APIError>,
&Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>
{ {
#[cfg(feature = "std")] { #[cfg(feature = "std")] {
if has_expired(&route_params) { if has_expired(&route_params) {
@ -699,8 +705,7 @@ impl OutboundPayments {
NS::Target: NodeSigner, NS::Target: NodeSigner,
L::Target: Logger, L::Target: Logger,
IH: Fn() -> InFlightHtlcs, IH: Fn() -> InFlightHtlcs,
SP: Fn(&Path, &PaymentHash, RecipientOnionFields, u64, u32, PaymentId, SP: Fn(SendAlongPathArgs) -> Result<(), APIError>,
&Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>
{ {
#[cfg(feature = "std")] { #[cfg(feature = "std")] {
if has_expired(&route_params) { if has_expired(&route_params) {
@ -821,8 +826,7 @@ impl OutboundPayments {
NS::Target: NodeSigner, NS::Target: NodeSigner,
L::Target: Logger, L::Target: Logger,
IH: Fn() -> InFlightHtlcs, IH: Fn() -> InFlightHtlcs,
SP: Fn(&Path, &PaymentHash, RecipientOnionFields, u64, u32, PaymentId, SP: Fn(SendAlongPathArgs) -> Result<(), APIError>,
&Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>
{ {
match err { match err {
PaymentSendFailure::AllFailedResendSafe(errs) => { PaymentSendFailure::AllFailedResendSafe(errs) => {
@ -894,8 +898,7 @@ impl OutboundPayments {
where where
ES::Target: EntropySource, ES::Target: EntropySource,
NS::Target: NodeSigner, NS::Target: NodeSigner,
F: Fn(&Path, &PaymentHash, RecipientOnionFields, u64, u32, PaymentId, F: Fn(SendAlongPathArgs) -> Result<(), APIError>,
&Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>
{ {
let payment_id = PaymentId(entropy_source.get_secure_random_bytes()); let payment_id = PaymentId(entropy_source.get_secure_random_bytes());
@ -989,8 +992,7 @@ impl OutboundPayments {
) -> Result<(), PaymentSendFailure> ) -> Result<(), PaymentSendFailure>
where where
NS::Target: NodeSigner, NS::Target: NodeSigner,
F: Fn(&Path, &PaymentHash, RecipientOnionFields, u64, u32, PaymentId, F: Fn(SendAlongPathArgs) -> Result<(), APIError>,
&Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>
{ {
if route.paths.len() < 1 { if route.paths.len() < 1 {
return Err(PaymentSendFailure::ParameterError(APIError::InvalidRoute{err: "There must be at least one path to send over".to_owned()})); return Err(PaymentSendFailure::ParameterError(APIError::InvalidRoute{err: "There must be at least one path to send over".to_owned()}));
@ -1031,9 +1033,11 @@ impl OutboundPayments {
let cur_height = best_block_height + 1; let cur_height = best_block_height + 1;
let mut results = Vec::new(); let mut results = Vec::new();
debug_assert_eq!(route.paths.len(), onion_session_privs.len()); debug_assert_eq!(route.paths.len(), onion_session_privs.len());
for (path, session_priv) in route.paths.iter().zip(onion_session_privs.into_iter()) { for (path, session_priv_bytes) in route.paths.iter().zip(onion_session_privs.into_iter()) {
let mut path_res = send_payment_along_path(&path, &payment_hash, recipient_onion.clone(), let mut path_res = send_payment_along_path(SendAlongPathArgs {
total_value, cur_height, payment_id, &keysend_preimage, session_priv); path: &path, payment_hash: &payment_hash, recipient_onion: recipient_onion.clone(),
total_value, cur_height, payment_id, keysend_preimage: &keysend_preimage, session_priv_bytes
});
match path_res { match path_res {
Ok(_) => {}, Ok(_) => {},
Err(APIError::MonitorUpdateInProgress) => { Err(APIError::MonitorUpdateInProgress) => {
@ -1044,7 +1048,7 @@ impl OutboundPayments {
Err(_) => { Err(_) => {
let mut pending_outbounds = self.pending_outbound_payments.lock().unwrap(); let mut pending_outbounds = self.pending_outbound_payments.lock().unwrap();
if let Some(payment) = pending_outbounds.get_mut(&payment_id) { if let Some(payment) = pending_outbounds.get_mut(&payment_id) {
let removed = payment.remove(&session_priv, Some(path)); let removed = payment.remove(&session_priv_bytes, Some(path));
debug_assert!(removed, "This can't happen as the payment has an entry for this path added by callers"); debug_assert!(removed, "This can't happen as the payment has an entry for this path added by callers");
} else { } else {
debug_assert!(false, "This can't happen as the payment was added by callers"); debug_assert!(false, "This can't happen as the payment was added by callers");
@ -1098,8 +1102,7 @@ impl OutboundPayments {
) -> Result<(), PaymentSendFailure> ) -> Result<(), PaymentSendFailure>
where where
NS::Target: NodeSigner, NS::Target: NodeSigner,
F: Fn(&Path, &PaymentHash, RecipientOnionFields, u64, u32, PaymentId, F: Fn(SendAlongPathArgs) -> Result<(), APIError>,
&Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>
{ {
self.pay_route_internal(route, payment_hash, recipient_onion, keysend_preimage, payment_id, self.pay_route_internal(route, payment_hash, recipient_onion, keysend_preimage, payment_id,
recv_value_msat, onion_session_privs, node_signer, best_block_height, recv_value_msat, onion_session_privs, node_signer, best_block_height,
@ -1480,8 +1483,8 @@ mod tests {
&&keys_manager, 0).unwrap(); &&keys_manager, 0).unwrap();
outbound_payments.retry_payment_internal( outbound_payments.retry_payment_internal(
PaymentHash([0; 32]), PaymentId([0; 32]), expired_route_params, &&router, vec![], PaymentHash([0; 32]), PaymentId([0; 32]), expired_route_params, &&router, vec![],
&|| InFlightHtlcs::new(), &&keys_manager, &&keys_manager, 0, &&logger, &|| InFlightHtlcs::new(), &&keys_manager, &&keys_manager, 0, &&logger, &pending_events,
&pending_events, &|_, _, _, _, _, _, _, _| Ok(())); &|_| Ok(()));
let events = pending_events.lock().unwrap(); let events = pending_events.lock().unwrap();
assert_eq!(events.len(), 1); assert_eq!(events.len(), 1);
if let Event::PaymentFailed { ref reason, .. } = events[0].0 { if let Event::PaymentFailed { ref reason, .. } = events[0].0 {
@ -1491,8 +1494,7 @@ mod tests {
let err = outbound_payments.send_payment( let err = outbound_payments.send_payment(
PaymentHash([0; 32]), RecipientOnionFields::spontaneous_empty(), PaymentId([0; 32]), PaymentHash([0; 32]), RecipientOnionFields::spontaneous_empty(), PaymentId([0; 32]),
Retry::Attempts(0), expired_route_params, &&router, vec![], || InFlightHtlcs::new(), Retry::Attempts(0), expired_route_params, &&router, vec![], || InFlightHtlcs::new(),
&&keys_manager, &&keys_manager, 0, &&logger, &&keys_manager, &&keys_manager, 0, &&logger, &pending_events, |_| Ok(())).unwrap_err();
&pending_events, |_, _, _, _, _, _, _, _| Ok(())).unwrap_err();
if let RetryableSendFailure::PaymentExpired = err { } else { panic!("Unexpected error"); } if let RetryableSendFailure::PaymentExpired = err { } else { panic!("Unexpected error"); }
} }
} }
@ -1528,8 +1530,8 @@ mod tests {
&&keys_manager, 0).unwrap(); &&keys_manager, 0).unwrap();
outbound_payments.retry_payment_internal( outbound_payments.retry_payment_internal(
PaymentHash([0; 32]), PaymentId([0; 32]), route_params, &&router, vec![], PaymentHash([0; 32]), PaymentId([0; 32]), route_params, &&router, vec![],
&|| InFlightHtlcs::new(), &&keys_manager, &&keys_manager, 0, &&logger, &|| InFlightHtlcs::new(), &&keys_manager, &&keys_manager, 0, &&logger, &pending_events,
&pending_events, &|_, _, _, _, _, _, _, _| Ok(())); &|_| Ok(()));
let events = pending_events.lock().unwrap(); let events = pending_events.lock().unwrap();
assert_eq!(events.len(), 1); assert_eq!(events.len(), 1);
if let Event::PaymentFailed { .. } = events[0].0 { } else { panic!("Unexpected event"); } if let Event::PaymentFailed { .. } = events[0].0 { } else { panic!("Unexpected event"); }
@ -1537,8 +1539,7 @@ mod tests {
let err = outbound_payments.send_payment( let err = outbound_payments.send_payment(
PaymentHash([0; 32]), RecipientOnionFields::spontaneous_empty(), PaymentId([0; 32]), PaymentHash([0; 32]), RecipientOnionFields::spontaneous_empty(), PaymentId([0; 32]),
Retry::Attempts(0), route_params, &&router, vec![], || InFlightHtlcs::new(), Retry::Attempts(0), route_params, &&router, vec![], || InFlightHtlcs::new(),
&&keys_manager, &&keys_manager, 0, &&logger, &&keys_manager, &&keys_manager, 0, &&logger, &pending_events, |_| Ok(())).unwrap_err();
&pending_events, |_, _, _, _, _, _, _, _| Ok(())).unwrap_err();
if let RetryableSendFailure::RouteNotFound = err { if let RetryableSendFailure::RouteNotFound = err {
} else { panic!("Unexpected error"); } } else { panic!("Unexpected error"); }
} }
@ -1587,8 +1588,7 @@ mod tests {
PaymentHash([0; 32]), RecipientOnionFields::spontaneous_empty(), PaymentId([0; 32]), PaymentHash([0; 32]), RecipientOnionFields::spontaneous_empty(), PaymentId([0; 32]),
Retry::Attempts(0), route_params.clone(), &&router, vec![], || InFlightHtlcs::new(), Retry::Attempts(0), route_params.clone(), &&router, vec![], || InFlightHtlcs::new(),
&&keys_manager, &&keys_manager, 0, &&logger, &pending_events, &&keys_manager, &&keys_manager, 0, &&logger, &pending_events,
|_, _, _, _, _, _, _, _| Err(APIError::ChannelUnavailable { err: "test".to_owned() })) |_| Err(APIError::ChannelUnavailable { err: "test".to_owned() })).unwrap();
.unwrap();
let mut events = pending_events.lock().unwrap(); let mut events = pending_events.lock().unwrap();
assert_eq!(events.len(), 2); assert_eq!(events.len(), 2);
if let Event::PaymentPathFailed { if let Event::PaymentPathFailed {
@ -1606,7 +1606,7 @@ mod tests {
PaymentHash([0; 32]), RecipientOnionFields::spontaneous_empty(), PaymentId([0; 32]), PaymentHash([0; 32]), RecipientOnionFields::spontaneous_empty(), PaymentId([0; 32]),
Retry::Attempts(0), route_params.clone(), &&router, vec![], || InFlightHtlcs::new(), Retry::Attempts(0), route_params.clone(), &&router, vec![], || InFlightHtlcs::new(),
&&keys_manager, &&keys_manager, 0, &&logger, &pending_events, &&keys_manager, &&keys_manager, 0, &&logger, &pending_events,
|_, _, _, _, _, _, _, _| Err(APIError::MonitorUpdateInProgress)).unwrap(); |_| Err(APIError::MonitorUpdateInProgress)).unwrap();
assert_eq!(pending_events.lock().unwrap().len(), 0); assert_eq!(pending_events.lock().unwrap().len(), 0);
// Ensure that any other error will result in a PaymentPathFailed event but no blamed scid. // Ensure that any other error will result in a PaymentPathFailed event but no blamed scid.
@ -1614,8 +1614,7 @@ mod tests {
PaymentHash([0; 32]), RecipientOnionFields::spontaneous_empty(), PaymentId([1; 32]), PaymentHash([0; 32]), RecipientOnionFields::spontaneous_empty(), PaymentId([1; 32]),
Retry::Attempts(0), route_params.clone(), &&router, vec![], || InFlightHtlcs::new(), Retry::Attempts(0), route_params.clone(), &&router, vec![], || InFlightHtlcs::new(),
&&keys_manager, &&keys_manager, 0, &&logger, &pending_events, &&keys_manager, &&keys_manager, 0, &&logger, &pending_events,
|_, _, _, _, _, _, _, _| Err(APIError::APIMisuseError { err: "test".to_owned() })) |_| Err(APIError::APIMisuseError { err: "test".to_owned() })).unwrap();
.unwrap();
let events = pending_events.lock().unwrap(); let events = pending_events.lock().unwrap();
assert_eq!(events.len(), 2); assert_eq!(events.len(), 2);
if let Event::PaymentPathFailed { if let Event::PaymentPathFailed {