Log peer features in peer_handler (and check for all req bits)
[rust-lightning] / src / ln / channelmanager.rs
index e7c6965e94e1c69575c75c82da3b04ae67e9314d..d6246166bb7c3ac9ddd6f2bc2aa6d1a094750230 100644 (file)
@@ -16,9 +16,10 @@ use ln::channel::{Channel, ChannelKeys};
 use ln::channelmonitor::ManyChannelMonitor;
 use ln::router::{Route,RouteHop};
 use ln::msgs;
-use ln::msgs::{HandleError,ChannelMessageHandler,MsgEncodable,MsgDecodable};
+use ln::msgs::{HandleError,ChannelMessageHandler};
 use util::{byte_utils, events, internal_traits, rng};
 use util::sha2::Sha256;
+use util::ser::{Readable, Writeable};
 use util::chacha20poly1305rfc::ChaCha20;
 use util::logger::Logger;
 use util::errors::APIError;
@@ -32,6 +33,7 @@ use crypto::symmetriccipher::SynchronousStreamCipher;
 use std::{ptr, mem};
 use std::collections::HashMap;
 use std::collections::hash_map;
+use std::io::Cursor;
 use std::sync::{Mutex,MutexGuard,Arc};
 use std::sync::atomic::{AtomicUsize, Ordering};
 use std::time::{Instant,Duration};
@@ -78,23 +80,6 @@ mod channel_held_info {
                Fail(HTLCFailureMsg),
        }
 
-       #[cfg(feature = "fuzztarget")]
-       impl PendingHTLCStatus {
-               pub fn dummy() -> Self {
-                       let secp_ctx = ::secp256k1::Secp256k1::signing_only();
-                       PendingHTLCStatus::Forward(PendingForwardHTLCInfo {
-                               onion_packet: None,
-                               incoming_shared_secret: SharedSecret::new(&secp_ctx,
-                                               &::secp256k1::key::PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[1; 32]).unwrap()),
-                                               &SecretKey::from_slice(&secp_ctx, &[1; 32]).unwrap()),
-                               payment_hash: [0; 32],
-                               short_channel_id: 0,
-                               amt_to_forward: 0,
-                               outgoing_cltv_value: 0,
-                       })
-               }
-       }
-
        /// Tracks the inbound corresponding to an outbound HTLC
        #[derive(Clone)]
        pub struct HTLCPreviousHopData {
@@ -112,7 +97,7 @@ mod channel_held_info {
                        session_priv: SecretKey,
                },
        }
-       #[cfg(any(test, feature = "fuzztarget"))]
+       #[cfg(test)]
        impl HTLCSource {
                pub fn dummy() -> Self {
                        HTLCSource::OutboundRoute {
@@ -123,7 +108,7 @@ mod channel_held_info {
        }
 
        #[derive(Clone)] // See Channel::revoke_and_ack for why, tl;dr: Rust bug
-       pub enum HTLCFailReason {
+       pub(crate) enum HTLCFailReason {
                ErrorPacket {
                        err: msgs::OnionErrorPacket,
                },
@@ -132,20 +117,8 @@ mod channel_held_info {
                        data: Vec<u8>,
                }
        }
-
-       #[cfg(feature = "fuzztarget")]
-       impl HTLCFailReason {
-               pub fn dummy() -> Self {
-                       HTLCFailReason::Reason {
-                               failure_code: 0, data: Vec::new(),
-                       }
-               }
-       }
 }
-#[cfg(feature = "fuzztarget")]
-pub use self::channel_held_info::*;
-#[cfg(not(feature = "fuzztarget"))]
-pub(crate) use self::channel_held_info::*;
+pub(super) use self::channel_held_info::*;
 
 struct MsgHandleErrInternal {
        err: msgs::HandleError,
@@ -819,7 +792,7 @@ impl ChannelManager {
                let next_hop_data = {
                        let mut decoded = [0; 65];
                        chacha.process(&msg.onion_routing_packet.hop_data[0..65], &mut decoded);
-                       match msgs::OnionHopData::decode(&decoded[..]) {
+                       match msgs::OnionHopData::read(&mut Cursor::new(&decoded[..])) {
                                Err(err) => {
                                        let error_code = match err {
                                                msgs::DecodeError::UnknownRealmByte => 0x4000 | 1,
@@ -1717,7 +1690,7 @@ impl ChannelManager {
                                        chacha.process(&packet_decrypted, &mut decryption_tmp[..]);
                                        packet_decrypted = decryption_tmp;
 
-                                       if let Ok(err_packet) = msgs::DecodedOnionErrorPacket::decode(&packet_decrypted) {
+                                       if let Ok(err_packet) = msgs::DecodedOnionErrorPacket::read(&mut Cursor::new(&packet_decrypted)) {
                                                if err_packet.failuremsg.len() >= 2 {
                                                        let um = ChannelManager::gen_um_from_shared_secret(&shared_secret);
 
@@ -1733,7 +1706,7 @@ impl ChannelManager {
                                                                                if err_packet.failuremsg.len() >= 4 {
                                                                                        let update_len = byte_utils::slice_to_be16(&err_packet.failuremsg[2..4]) as usize;
                                                                                        if err_packet.failuremsg.len() >= 4 + update_len {
-                                                                                               if let Ok(chan_update) = msgs::ChannelUpdate::decode(&err_packet.failuremsg[4..4 + update_len]) {
+                                                                                               if let Ok(chan_update) = msgs::ChannelUpdate::read(&mut Cursor::new(&err_packet.failuremsg[4..4 + update_len])) {
                                                                                                        res = Some(msgs::HTLCFailChannelUpdate::ChannelUpdateMessage {
                                                                                                                msg: chan_update,
                                                                                                        });
@@ -2250,11 +2223,12 @@ mod tests {
        use ln::channelmanager::{ChannelManager,OnionKeys};
        use ln::router::{Route, RouteHop, Router};
        use ln::msgs;
-       use ln::msgs::{MsgEncodable,ChannelMessageHandler,RoutingMessageHandler};
+       use ln::msgs::{ChannelMessageHandler,RoutingMessageHandler};
        use util::test_utils;
        use util::events::{Event, EventsProvider};
-       use util::logger::Logger;
        use util::errors::APIError;
+       use util::logger::Logger;
+       use util::ser::Writeable;
 
        use bitcoin::util::hash::Sha256dHash;
        use bitcoin::blockdata::block::{Block, BlockHeader};