Merge pull request #2337 from alecchendev/2023-06-watchtower-support
[rust-lightning] / lightning / src / ln / outbound_payment.rs
index d0851373bdde8b558e5ddaf82c393b9090c05de2..5b18acfe3b34c2779f3199435b213f1117df79f4 100644 (file)
@@ -515,9 +515,9 @@ impl RecipientOnionFields {
                let tlvs = &mut self.custom_tlvs;
                let further_tlvs = &mut further_htlc_fields.custom_tlvs;
 
-               let even_tlvs: Vec<&(u64, Vec<u8>)> = tlvs.iter().filter(|(typ, _)| *typ % 2 == 0).collect();
-               let further_even_tlvs: Vec<&(u64, Vec<u8>)> = further_tlvs.iter().filter(|(typ, _)| *typ % 2 == 0).collect();
-               if even_tlvs != further_even_tlvs { return Err(()) }
+               let even_tlvs = tlvs.iter().filter(|(typ, _)| *typ % 2 == 0);
+               let further_even_tlvs = further_tlvs.iter().filter(|(typ, _)| *typ % 2 == 0);
+               if even_tlvs.ne(further_even_tlvs) { return Err(()) }
 
                tlvs.retain(|tlv| further_tlvs.iter().any(|further_tlv| tlv == further_tlv));
                further_tlvs.retain(|further_tlv| tlvs.iter().any(|tlv| tlv == further_tlv));
@@ -739,7 +739,7 @@ impl OutboundPayments {
 
                let res = self.pay_route_internal(&route, payment_hash, recipient_onion, keysend_preimage, payment_id, None,
                        onion_session_privs, node_signer, best_block_height, &send_payment_along_path);
-               log_info!(logger, "Result sending payment with id {}: {:?}", log_bytes!(payment_id.0), res);
+               log_info!(logger, "Result sending payment with id {}: {:?}", &payment_id, res);
                if let Err(e) = res {
                        self.handle_pay_route_err(e, payment_id, payment_hash, route, route_params, router, first_hops, &inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, &send_payment_along_path);
                }
@@ -762,7 +762,7 @@ impl OutboundPayments {
        {
                #[cfg(feature = "std")] {
                        if has_expired(&route_params) {
-                               log_error!(logger, "Payment params expired on retry, abandoning payment {}", log_bytes!(payment_id.0));
+                               log_error!(logger, "Payment params expired on retry, abandoning payment {}", &payment_id);
                                self.abandon_payment(payment_id, PaymentFailureReason::PaymentExpired, pending_events);
                                return
                        }
@@ -775,7 +775,7 @@ impl OutboundPayments {
                ) {
                        Ok(route) => route,
                        Err(e) => {
-                               log_error!(logger, "Failed to find a route on retry, abandoning payment {}: {:#?}", log_bytes!(payment_id.0), e);
+                               log_error!(logger, "Failed to find a route on retry, abandoning payment {}: {:#?}", &payment_id, e);
                                self.abandon_payment(payment_id, PaymentFailureReason::RouteNotFound, pending_events);
                                return
                        }
@@ -844,7 +844,7 @@ impl OutboundPayments {
                                                },
                                        };
                                        if !payment.get().is_retryable_now() {
-                                               log_error!(logger, "Retries exhausted for payment id {}", log_bytes!(payment_id.0));
+                                               log_error!(logger, "Retries exhausted for payment id {}", &payment_id);
                                                abandon_with_entry!(payment, PaymentFailureReason::RetriesExhausted);
                                                return
                                        }
@@ -855,7 +855,7 @@ impl OutboundPayments {
                                        res
                                },
                                hash_map::Entry::Vacant(_) => {
-                                       log_error!(logger, "Payment with ID {} not found", log_bytes!(payment_id.0));
+                                       log_error!(logger, "Payment with ID {} not found", &payment_id);
                                        return
                                }
                        }
@@ -863,7 +863,7 @@ impl OutboundPayments {
                let res = self.pay_route_internal(&route, payment_hash, recipient_onion, keysend_preimage,
                        payment_id, Some(total_msat), onion_session_privs, node_signer, best_block_height,
                        &send_payment_along_path);
-               log_info!(logger, "Result retrying payment id {}: {:?}", log_bytes!(payment_id.0), res);
+               log_info!(logger, "Result retrying payment id {}: {:?}", &payment_id, res);
                if let Err(e) = res {
                        self.handle_pay_route_err(e, payment_id, payment_hash, route, route_params, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, send_payment_along_path);
                }
@@ -1177,7 +1177,7 @@ impl OutboundPayments {
 
        pub(super) fn claim_htlc<L: Deref>(
                &self, payment_id: PaymentId, payment_preimage: PaymentPreimage, session_priv: SecretKey,
-               path: Path, from_onchain: bool,
+               path: Path, from_onchain: bool, ev_completion_action: EventCompletionAction,
                pending_events: &Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>,
                logger: &L,
        ) where L::Target: Logger {
@@ -1194,7 +1194,7 @@ impl OutboundPayments {
                                        payment_preimage,
                                        payment_hash,
                                        fee_paid_msat,
-                               }, None));
+                               }, Some(ev_completion_action.clone())));
                                payment.get_mut().mark_fulfilled();
                        }
 
@@ -1211,11 +1211,11 @@ impl OutboundPayments {
                                                payment_id,
                                                payment_hash,
                                                path,
-                                       }, None));
+                                       }, Some(ev_completion_action)));
                                }
                        }
                } else {
-                       log_trace!(logger, "Received duplicative fulfill for HTLC with payment_preimage {}", log_bytes!(payment_preimage.0));
+                       log_trace!(logger, "Received duplicative fulfill for HTLC with payment_preimage {}", &payment_preimage);
                }
        }
 
@@ -1323,11 +1323,11 @@ impl OutboundPayments {
                let mut pending_retry_ev = false;
                let attempts_remaining = if let hash_map::Entry::Occupied(mut payment) = outbounds.entry(*payment_id) {
                        if !payment.get_mut().remove(&session_priv_bytes, Some(&path)) {
-                               log_trace!(logger, "Received duplicative fail for HTLC with payment_hash {}", log_bytes!(payment_hash.0));
+                               log_trace!(logger, "Received duplicative fail for HTLC with payment_hash {}", &payment_hash);
                                return false
                        }
                        if payment.get().is_fulfilled() {
-                               log_trace!(logger, "Received failure of HTLC with payment_hash {} after payment completion", log_bytes!(payment_hash.0));
+                               log_trace!(logger, "Received failure of HTLC with payment_hash {} after payment completion", &payment_hash);
                                return false
                        }
                        let mut is_retryable_now = payment.get().is_auto_retryable_now();
@@ -1361,11 +1361,11 @@ impl OutboundPayments {
                        }
                        is_retryable_now
                } else {
-                       log_trace!(logger, "Received duplicative fail for HTLC with payment_hash {}", log_bytes!(payment_hash.0));
+                       log_trace!(logger, "Received duplicative fail for HTLC with payment_hash {}", &payment_hash);
                        return false
                };
                core::mem::drop(outbounds);
-               log_trace!(logger, "Failing outbound payment HTLC with payment_hash {}", log_bytes!(payment_hash.0));
+               log_trace!(logger, "Failing outbound payment HTLC with payment_hash {}", &payment_hash);
 
                let path_failure = {
                        if payment_is_probe {