X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fonion_utils.rs;h=6d9118e21a8e38529e4ab5f93f8109c5b21a1363;hb=3b67be235a46d8f9a9a6faf7ca7c5872ffbd8646;hp=52e7d2fefc882d955166d717730c0990b56f4f0f;hpb=5bd7f24634a983326924f200bfff7c7c0fa56601;p=rust-lightning diff --git a/lightning/src/ln/onion_utils.rs b/lightning/src/ln/onion_utils.rs index 52e7d2fe..6d9118e2 100644 --- a/lightning/src/ln/onion_utils.rs +++ b/lightning/src/ln/onion_utils.rs @@ -1,11 +1,21 @@ -use ln::channelmanager::{PaymentHash, PaymentSecret, HTLCSource}; +// This file is Copyright its original authors, visible in version control +// history. +// +// This file is licensed under the Apache License, Version 2.0 or the MIT license +// , at your option. +// You may not use this file except in accordance with one or both of these +// licenses. + +use ln::{PaymentHash, PaymentSecret}; +use ln::channelmanager::HTLCSource; use ln::msgs; use routing::router::RouteHop; use util::byte_utils; use util::chacha20::ChaCha20; use util::errors::{self, APIError}; use util::ser::{Readable, Writeable, LengthCalculatingWriter}; -use util::logger::{Logger, LogHolder}; +use util::logger::Logger; use bitcoin::hashes::{Hash, HashEngine}; use bitcoin::hashes::cmp::fixed_time_eq; @@ -18,7 +28,7 @@ use bitcoin::secp256k1::ecdh::SharedSecret; use bitcoin::secp256k1; use std::io::Cursor; -use std::sync::Arc; +use std::ops::Deref; pub(super) struct OnionKeys { #[cfg(test)] @@ -146,11 +156,11 @@ pub(super) fn build_onion_payloads(path: &Vec, total_msat: u64, paymen }); cur_value_msat += hop.fee_msat; if cur_value_msat >= 21000000 * 100000000 * 1000 { - return Err(APIError::RouteError{err: "Channel fees overflowed?!"}); + return Err(APIError::RouteError{err: "Channel fees overflowed?"}); } cur_cltv += hop.cltv_expiry_delta as u32; if cur_cltv >= 500000000 { - return Err(APIError::RouteError{err: "Channel CLTV overflowed?!"}); + return Err(APIError::RouteError{err: "Channel CLTV overflowed?"}); } last_short_channel_id = hop.short_channel_id; } @@ -297,8 +307,8 @@ pub(super) fn build_failure_packet(shared_secret: &[u8], failure_type: u16, fail }; let mut packet = msgs::DecodedOnionErrorPacket { hmac: [0; 32], - failuremsg: failuremsg, - pad: pad, + failuremsg, + pad, }; let mut hmac = HmacEngine::::new(&um); @@ -318,7 +328,7 @@ pub(super) fn build_first_hop_failure_packet(shared_secret: &[u8], failure_type: /// OutboundRoute). /// Returns update, a boolean indicating that the payment itself failed, and the error code. #[inline] -pub(super) fn process_onion_failure(secp_ctx: &Secp256k1, logger: &Arc, htlc_source: &HTLCSource, mut packet_decrypted: Vec) -> (Option, bool, Option, Option>) { +pub(super) fn process_onion_failure(secp_ctx: &Secp256k1, logger: &L, htlc_source: &HTLCSource, mut packet_decrypted: Vec) -> (Option, bool, Option, Option>) where L::Target: Logger { if let &HTLCSource::OutboundRoute { ref path, ref session_priv, ref first_hop_htlc_msat } = htlc_source { let mut res = None; let mut htlc_msat = *first_hop_htlc_msat; @@ -440,12 +450,10 @@ pub(super) fn process_onion_failure(secp_ctx: &Secp256k1< let (description, title) = errors::get_onion_error_description(error_code); if debug_field_size > 0 && err_packet.failuremsg.len() >= 4 + debug_field_size { - let log_holder = LogHolder { logger }; - log_warn!(log_holder, "Onion Error[{}({:#x}) {}({})] {}", title, error_code, debug_field, log_bytes!(&err_packet.failuremsg[4..4+debug_field_size]), description); + log_warn!(logger, "Onion Error[from {}: {}({:#x}) {}({})] {}", route_hop.pubkey, title, error_code, debug_field, log_bytes!(&err_packet.failuremsg[4..4+debug_field_size]), description); } else { - let log_holder = LogHolder { logger }; - log_warn!(log_holder, "Onion Error[{}({:#x})] {}", title, error_code, description); + log_warn!(logger, "Onion Error[from {}: {}({:#x})] {}", route_hop.pubkey, title, error_code, description); } } else { // Useless packet that we can't use but it passed HMAC, so it @@ -470,7 +478,7 @@ pub(super) fn process_onion_failure(secp_ctx: &Secp256k1< #[cfg(test)] mod tests { - use ln::channelmanager::PaymentHash; + use ln::PaymentHash; use ln::features::{ChannelFeatures, NodeFeatures}; use routing::router::{Route, RouteHop}; use ln::msgs;