Merge pull request #2818 from valentinewallace/2024-01-blinded-path-retries
[rust-lightning] / lightning / src / ln / onion_utils.rs
index 1ea6fd83aa237f08e9f911dc052c42b06a042b01..4b39276c066c77ec5975be569c274081158750ed 100644 (file)
@@ -429,6 +429,7 @@ pub(crate) struct DecodedOnionFailure {
        pub(crate) network_update: Option<NetworkUpdate>,
        pub(crate) short_channel_id: Option<u64>,
        pub(crate) payment_failed_permanently: bool,
+       pub(crate) failed_within_blinded_path: bool,
        #[cfg(test)]
        pub(crate) onion_error_code: Option<u16>,
        #[cfg(test)]
@@ -463,6 +464,7 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
                network_update: Option<NetworkUpdate>,
                short_channel_id: Option<u64>,
                payment_failed_permanently: bool,
+               failed_within_blinded_path: bool,
        }
        let mut res: Option<FailureLearnings> = None;
        let mut htlc_msat = *first_hop_htlc_msat;
@@ -488,7 +490,8 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
                                error_code_ret = Some(BADONION | PERM | 24); // invalid_onion_blinding
                                error_packet_ret = Some(vec![0; 32]);
                                res = Some(FailureLearnings {
-                                       network_update: None, short_channel_id: None, payment_failed_permanently: false
+                                       network_update: None, short_channel_id: None, payment_failed_permanently: false,
+                                       failed_within_blinded_path: true,
                                });
                                return
                        },
@@ -520,7 +523,8 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
                                        }
 
                                        res = Some(FailureLearnings {
-                                               network_update: None, short_channel_id: None, payment_failed_permanently: false
+                                               network_update: None, short_channel_id: None, payment_failed_permanently: false,
+                                               failed_within_blinded_path: true,
                                        });
                                        return
                                }
@@ -550,7 +554,8 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
                                });
                                let short_channel_id = Some(route_hop.short_channel_id);
                                res = Some(FailureLearnings {
-                                       network_update, short_channel_id, payment_failed_permanently: is_from_final_node
+                                       network_update, short_channel_id, payment_failed_permanently: is_from_final_node,
+                                       failed_within_blinded_path: false
                                });
                                return
                        }
@@ -706,7 +711,8 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
 
                res = Some(FailureLearnings {
                        network_update, short_channel_id,
-                       payment_failed_permanently: error_code & PERM == PERM && is_from_final_node
+                       payment_failed_permanently: error_code & PERM == PERM && is_from_final_node,
+                       failed_within_blinded_path: false
                });
 
                let (description, title) = errors::get_onion_error_description(error_code);
@@ -717,10 +723,10 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
                }
        }).expect("Route that we sent via spontaneously grew invalid keys in the middle of it?");
        if let Some(FailureLearnings {
-               network_update, short_channel_id, payment_failed_permanently
+               network_update, short_channel_id, payment_failed_permanently, failed_within_blinded_path
        }) = res {
                DecodedOnionFailure {
-                       network_update, short_channel_id, payment_failed_permanently,
+                       network_update, short_channel_id, payment_failed_permanently, failed_within_blinded_path,
                        #[cfg(test)]
                        onion_error_code: error_code_ret,
                        #[cfg(test)]
@@ -731,6 +737,7 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
                // payment not retryable only when garbage is from the final node
                DecodedOnionFailure {
                        network_update: None, short_channel_id: None, payment_failed_permanently: is_from_final_node,
+                       failed_within_blinded_path: false,
                        #[cfg(test)]
                        onion_error_code: None,
                        #[cfg(test)]
@@ -878,6 +885,7 @@ impl HTLCFailReason {
                                                network_update: None,
                                                payment_failed_permanently: false,
                                                short_channel_id: Some(path.hops[0].short_channel_id),
+                                               failed_within_blinded_path: false,
                                                #[cfg(test)]
                                                onion_error_code: Some(*failure_code),
                                                #[cfg(test)]