Rename onion util internal var
[rust-lightning] / lightning / src / ln / onion_utils.rs
index 8782323ea77333d0ce1e46a17c17aebea2580051..c591010ae4dd671a5e5ee42b4b0bb5efb61e8c44 100644 (file)
@@ -13,6 +13,7 @@ use crate::ln::msgs;
 use crate::ln::wire::Encode;
 use crate::routing::gossip::NetworkUpdate;
 use crate::routing::router::{BlindedTail, Path, RouteHop};
+use crate::sign::NodeSigner;
 use crate::util::chacha20::{ChaCha20, ChaChaReader};
 use crate::util::errors::{self, APIError};
 use crate::util::ser::{Readable, ReadableArgs, Writeable, Writer, LengthCalculatingWriter};
@@ -506,7 +507,7 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
                                        is_permanent: true,
                                });
                                let short_channel_id = Some(route_hop.short_channel_id);
-                               res = Some((network_update, short_channel_id, !is_from_final_node));
+                               res = Some((network_update, short_channel_id, is_from_final_node));
                                return
                        }
                };
@@ -658,7 +659,7 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
                        short_channel_id = Some(route_hop.short_channel_id);
                }
 
-               res = Some((network_update, short_channel_id, !(error_code & PERM == PERM && is_from_final_node)));
+               res = Some((network_update, short_channel_id, error_code & PERM == PERM && is_from_final_node));
 
                let (description, title) = errors::get_onion_error_description(error_code);
                if debug_field_size > 0 && err_packet.failuremsg.len() >= 4 + debug_field_size {
@@ -667,9 +668,9 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
                        log_info!(logger, "Onion Error[from {}: {}({:#x})] {}", route_hop.pubkey, title, error_code, description);
                }
        }).expect("Route that we sent via spontaneously grew invalid keys in the middle of it?");
-       if let Some((network_update, short_channel_id, payment_retryable)) = res {
+       if let Some((network_update, short_channel_id, payment_failed_permanently)) = res {
                DecodedOnionFailure {
-                       network_update, short_channel_id, payment_retryable,
+                       network_update, short_channel_id, payment_retryable: !payment_failed_permanently,
                        #[cfg(test)]
                        onion_error_code: error_code_ret,
                        #[cfg(test)]
@@ -885,8 +886,11 @@ pub(crate) enum OnionDecodeErr {
        },
 }
 
-pub(crate) fn decode_next_payment_hop(shared_secret: [u8; 32], hop_data: &[u8], hmac_bytes: [u8; 32], payment_hash: PaymentHash) -> Result<Hop, OnionDecodeErr> {
-       match decode_next_hop(shared_secret, hop_data, hmac_bytes, Some(payment_hash), ()) {
+pub(crate) fn decode_next_payment_hop<NS: Deref>(
+       shared_secret: [u8; 32], hop_data: &[u8], hmac_bytes: [u8; 32], payment_hash: PaymentHash,
+       node_signer: &NS,
+) -> Result<Hop, OnionDecodeErr> where NS::Target: NodeSigner {
+       match decode_next_hop(shared_secret, hop_data, hmac_bytes, Some(payment_hash), node_signer) {
                Ok((next_hop_data, None)) => Ok(Hop::Receive(next_hop_data)),
                Ok((next_hop_data, Some((next_hop_hmac, FixedSizeOnionPacket(new_packet_bytes))))) => {
                        Ok(Hop::Forward {