]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Pass payment hash into pay_internal
authorValentine Wallace <vwallace@protonmail.com>
Thu, 9 Feb 2023 19:21:52 +0000 (13:21 -0600)
committerValentine Wallace <vwallace@protonmail.com>
Sun, 19 Feb 2023 23:01:01 +0000 (18:01 -0500)
Useful for generating Payment(Path)Failed events in this method

lightning/src/ln/outbound_payment.rs

index f252d88ac364e87947ed42c31bef96b5c276375f..9fbca12ec11ad95f2ccae1301f80350ffa2e67fd 100644 (file)
@@ -408,7 +408,7 @@ impl OutboundPayments {
                SP: Fn(&Vec<RouteHop>, &Option<PaymentParameters>, &PaymentHash, &Option<PaymentSecret>, u64,
                         u32, PaymentId, &Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>,
        {
-               self.pay_internal(payment_id, Some((payment_hash, payment_secret, None, retry_strategy)),
+               self.pay_internal(payment_id, payment_hash, Some((payment_secret, None, retry_strategy)),
                        route_params, router, first_hops, &compute_inflight_htlcs, entropy_source, node_signer,
                        best_block_height, logger, &send_payment_along_path)
                        .map_err(|e| { self.remove_outbound_if_all_failed(payment_id, &e); e })
@@ -449,7 +449,7 @@ impl OutboundPayments {
                let preimage = payment_preimage
                        .unwrap_or_else(|| PaymentPreimage(entropy_source.get_secure_random_bytes()));
                let payment_hash = PaymentHash(Sha256::hash(&preimage.0).into_inner());
-               self.pay_internal(payment_id, Some((payment_hash, &None, Some(preimage), retry_strategy)),
+               self.pay_internal(payment_id, payment_hash, Some((&None, Some(preimage), retry_strategy)),
                        route_params, router, first_hops, &inflight_htlcs, entropy_source, node_signer,
                        best_block_height, logger, &send_payment_along_path)
                        .map(|()| payment_hash)
@@ -501,9 +501,9 @@ impl OutboundPayments {
                        let mut retry_id_route_params = None;
                        for (pmt_id, pmt) in outbounds.iter_mut() {
                                if pmt.is_auto_retryable_now() {
-                                       if let PendingOutboundPayment::Retryable { pending_amt_msat, total_msat, payment_params: Some(params), .. } = pmt {
+                                       if let PendingOutboundPayment::Retryable { payment_hash, pending_amt_msat, total_msat, payment_params: Some(params), .. } = pmt {
                                                if pending_amt_msat < total_msat {
-                                                       retry_id_route_params = Some((*pmt_id, RouteParameters {
+                                                       retry_id_route_params = Some((*pmt_id, *payment_hash, RouteParameters {
                                                                final_value_msat: *total_msat - *pending_amt_msat,
                                                                final_cltv_expiry_delta:
                                                                        if let Some(delta) = params.final_cltv_expiry_delta { delta }
@@ -519,8 +519,8 @@ impl OutboundPayments {
                                }
                        }
                        core::mem::drop(outbounds);
-                       if let Some((payment_id, route_params)) = retry_id_route_params {
-                               if let Err(e) = self.pay_internal(payment_id, None, route_params, router, first_hops(), &inflight_htlcs, entropy_source, node_signer, best_block_height, logger, &send_payment_along_path) {
+                       if let Some((payment_id, payment_hash, route_params)) = retry_id_route_params {
+                               if let Err(e) = self.pay_internal(payment_id, payment_hash, None, route_params, router, first_hops(), &inflight_htlcs, entropy_source, node_signer, best_block_height, logger, &send_payment_along_path) {
                                        log_info!(logger, "Errored retrying payment: {:?}", e);
                                        // If we error on retry, there is no chance of the payment succeeding and no HTLCs have
                                        // been irrevocably committed to, so we can safely abandon.
@@ -553,8 +553,8 @@ impl OutboundPayments {
 
        /// Will return `Ok(())` iff at least one HTLC is sent for the payment.
        fn pay_internal<R: Deref, NS: Deref, ES: Deref, IH, SP, L: Deref>(
-               &self, payment_id: PaymentId,
-               initial_send_info: Option<(PaymentHash, &Option<PaymentSecret>, Option<PaymentPreimage>, Retry)>,
+               &self, payment_id: PaymentId, payment_hash: PaymentHash,
+               initial_send_info: Option<(&Option<PaymentSecret>, Option<PaymentPreimage>, Retry)>,
                route_params: RouteParameters, router: &R, first_hops: Vec<ChannelDetails>,
                inflight_htlcs: &IH, entropy_source: &ES, node_signer: &NS, best_block_height: u32,
                logger: &L, send_payment_along_path: &SP,
@@ -583,7 +583,7 @@ impl OutboundPayments {
                        err: format!("Failed to find a route for payment {}: {:?}", log_bytes!(payment_id.0), e), // TODO: add APIError::RouteNotFound
                }))?;
 
-               let res = if let Some((payment_hash, payment_secret, keysend_preimage, retry_strategy)) = initial_send_info {
+               let res = if let Some((payment_secret, keysend_preimage, retry_strategy)) = initial_send_info {
                        let onion_session_privs = self.add_new_pending_payment(payment_hash, *payment_secret, payment_id, keysend_preimage, &route, Some(retry_strategy), Some(route_params.payment_params.clone()), entropy_source, best_block_height)?;
                        self.pay_route_internal(&route, payment_hash, payment_secret, None, payment_id, None, onion_session_privs, node_signer, best_block_height, send_payment_along_path)
                } else {
@@ -591,7 +591,7 @@ impl OutboundPayments {
                };
                match res {
                        Err(PaymentSendFailure::AllFailedResendSafe(_)) => {
-                               let retry_res = self.pay_internal(payment_id, None, route_params, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, logger, send_payment_along_path);
+                               let retry_res = self.pay_internal(payment_id, payment_hash, None, route_params, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, logger, send_payment_along_path);
                                log_info!(logger, "Result retrying payment id {}: {:?}", log_bytes!(payment_id.0), retry_res);
                                if let Err(PaymentSendFailure::ParameterError(APIError::APIMisuseError { err })) = &retry_res {
                                        if err.starts_with("Retries exhausted ") { return res; }
@@ -602,7 +602,7 @@ impl OutboundPayments {
                                // Some paths were sent, even if we failed to send the full MPP value our recipient may
                                // misbehave and claim the funds, at which point we have to consider the payment sent, so
                                // return `Ok()` here, ignoring any retry errors.
-                               let retry_res = self.pay_internal(payment_id, None, retry, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, logger, send_payment_along_path);
+                               let retry_res = self.pay_internal(payment_id, payment_hash, None, retry, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, logger, send_payment_along_path);
                                log_info!(logger, "Result retrying payment id {}: {:?}", log_bytes!(payment_id.0), retry_res);
                                Ok(())
                        },
@@ -1279,8 +1279,9 @@ mod tests {
                };
                let err = if on_retry {
                        outbound_payments.pay_internal(
-                               PaymentId([0; 32]), None, expired_route_params, &&router, vec![], &|| InFlightHtlcs::new(),
-                               &&keys_manager, &&keys_manager, 0, &&logger, &|_, _, _, _, _, _, _, _, _| Ok(())).unwrap_err()
+                               PaymentId([0; 32]), PaymentHash([0; 32]), None, expired_route_params, &&router, vec![],
+                               &|| InFlightHtlcs::new(), &&keys_manager, &&keys_manager, 0, &&logger,
+                               &|_, _, _, _, _, _, _, _, _| Ok(())).unwrap_err()
                } else {
                        outbound_payments.send_payment(
                                PaymentHash([0; 32]), &None, PaymentId([0; 32]), Retry::Attempts(0), expired_route_params,
@@ -1322,8 +1323,9 @@ mod tests {
                                &Route { paths: vec![], payment_params: None }, Some(Retry::Attempts(1)),
                                Some(route_params.payment_params.clone()), &&keys_manager, 0).unwrap();
                        outbound_payments.pay_internal(
-                               PaymentId([0; 32]), None, route_params, &&router, vec![], &|| InFlightHtlcs::new(),
-                               &&keys_manager, &&keys_manager, 0, &&logger, &|_, _, _, _, _, _, _, _, _| Ok(())).unwrap_err()
+                               PaymentId([0; 32]), PaymentHash([0; 32]), None, route_params, &&router, vec![],
+                               &|| InFlightHtlcs::new(), &&keys_manager, &&keys_manager, 0, &&logger,
+                               &|_, _, _, _, _, _, _, _, _| Ok(())).unwrap_err()
                } else {
                        outbound_payments.send_payment(
                                PaymentHash([0; 32]), &None, PaymentId([0; 32]), Retry::Attempts(0), route_params,