From 75d71cead386cac3c42a6c4d4f204869ec8dacc5 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 10 Feb 2021 22:25:42 -0500 Subject: [PATCH] Add additional Clone derives The only API change outside of additional derives is to change the inner field in `DecodeError::Io()` to an `std::io::ErrorKind` instead of an `std::io::Error`. While `std::io::Error` obviously makes more sense in context, it doesn't support Clone, and the inner error largely doesn't have a lot of value on its own. --- fuzz/src/router.rs | 2 +- lightning/src/chain/channelmonitor.rs | 2 +- lightning/src/ln/channelmanager.rs | 2 +- lightning/src/ln/msgs.rs | 8 +++++--- lightning/src/ln/peer_handler.rs | 1 + lightning/src/routing/network_graph.rs | 6 +++--- lightning/src/util/errors.rs | 1 + lightning/src/util/ser.rs | 2 +- 8 files changed, 14 insertions(+), 10 deletions(-) diff --git a/fuzz/src/router.rs b/fuzz/src/router.rs index 4eb85714f..55f08b628 100644 --- a/fuzz/src/router.rs +++ b/fuzz/src/router.rs @@ -130,7 +130,7 @@ pub fn do_test(data: &[u8], out: Out) { msgs::DecodeError::InvalidValue => return, msgs::DecodeError::BadLengthDescriptor => return, msgs::DecodeError::ShortRead => panic!("We picked the length..."), - msgs::DecodeError::Io(e) => panic!(format!("{}", e)), + msgs::DecodeError::Io(e) => panic!(format!("{:?}", e)), } } }} diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index b46a2df13..95495d1bf 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -174,7 +174,7 @@ pub enum ChannelMonitorUpdateErr { /// means you tried to update a monitor for a different channel or the ChannelMonitorUpdate was /// corrupted. /// Contains a developer-readable error message. -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct MonitorUpdateError(pub &'static str); /// An event to be processed by the ChannelManager. diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 621013724..3dcc74f90 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -514,7 +514,7 @@ pub struct ChannelDetails { /// If a payment fails to send, it can be in one of several states. This enum is returned as the /// Err() type describing which state the payment is in, see the description of individual enum /// states for more. -#[derive(Debug)] +#[derive(Clone, Debug)] pub enum PaymentSendFailure { /// A parameter which was passed to send_payment was invalid, preventing us from attempting to /// send the payment at all. No channel state has been changed or messages sent to peers, and diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index 289cdae4e..798764dc6 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -33,6 +33,7 @@ use bitcoin::hash_types::{Txid, BlockHash}; use ln::features::{ChannelFeatures, InitFeatures, NodeFeatures}; use std::{cmp, fmt}; +use std::fmt::Debug; use std::io::Read; use util::events::MessageSendEventsProvider; @@ -44,7 +45,7 @@ use ln::channelmanager::{PaymentPreimage, PaymentHash, PaymentSecret}; pub(crate) const MAX_VALUE_MSAT: u64 = 21_000_000_0000_0000_000; /// An error in decoding a message or struct. -#[derive(Debug)] +#[derive(Clone, Debug)] pub enum DecodeError { /// A version byte specified something we don't know how to handle. /// Includes unknown realm byte in an OnionHopData packet @@ -60,7 +61,7 @@ pub enum DecodeError { /// A length descriptor in the packet didn't describe the later data correctly BadLengthDescriptor, /// Error from std::io - Io(::std::io::Error), + Io(::std::io::ErrorKind), } /// An init message to be sent or received from a peer @@ -674,6 +675,7 @@ pub enum ErrorAction { } /// An Err type for failure to process messages. +#[derive(Clone)] pub struct LightningError { /// A human-readable message describing the error pub err: String, @@ -949,7 +951,7 @@ impl From<::std::io::Error> for DecodeError { if e.kind() == ::std::io::ErrorKind::UnexpectedEof { DecodeError::ShortRead } else { - DecodeError::Io(e) + DecodeError::Io(e.kind()) } } } diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index a3c229210..0e9facb8a 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -90,6 +90,7 @@ pub trait SocketDescriptor : cmp::Eq + hash::Hash + Clone { /// Error for PeerManager errors. If you get one of these, you must disconnect the socket and /// generate no further read_event/write_buffer_space_avail/socket_disconnected calls for the /// descriptor. +#[derive(Clone)] pub struct PeerHandleError { /// Used to indicate that we probably can't make any future connections to this peer, implying /// we should go ahead and force-close any channels we have with it. diff --git a/lightning/src/routing/network_graph.rs b/lightning/src/routing/network_graph.rs index bba99244b..040d3617b 100644 --- a/lightning/src/routing/network_graph.rs +++ b/lightning/src/routing/network_graph.rs @@ -329,7 +329,7 @@ where } } -#[derive(PartialEq, Debug)] +#[derive(Clone, PartialEq, Debug)] /// Details about one direction of a channel. Received /// within a channel update. pub struct DirectionalChannelInfo { @@ -441,7 +441,7 @@ impl Writeable for RoutingFees { } } -#[derive(PartialEq, Debug)] +#[derive(Clone, PartialEq, Debug)] /// Information received in the latest node_announcement from this node. pub struct NodeAnnouncementInfo { /// Protocol features the node announced support for @@ -507,7 +507,7 @@ impl Readable for NodeAnnouncementInfo { } } -#[derive(PartialEq)] +#[derive(Clone, PartialEq)] /// Details about a node in the network, known from the network announcement. pub struct NodeInfo { /// All valid channels a node has announced diff --git a/lightning/src/util/errors.rs b/lightning/src/util/errors.rs index a2a45a7b3..f67621c82 100644 --- a/lightning/src/util/errors.rs +++ b/lightning/src/util/errors.rs @@ -13,6 +13,7 @@ use std::fmt; /// Indicates an error on the client's part (usually some variant of attempting to use too-low or /// too-high values) +#[derive(Clone)] pub enum APIError { /// Indicates the API was wholly misused (see err for more). Cases where these can be returned /// are documented, but generally indicates some precondition of a function was violated. diff --git a/lightning/src/util/ser.rs b/lightning/src/util/ser.rs index 581f228ba..1d24e2640 100644 --- a/lightning/src/util/ser.rs +++ b/lightning/src/util/ser.rs @@ -718,7 +718,7 @@ macro_rules! impl_consensus_ser { match consensus::encode::Decodable::consensus_decode(r) { Ok(t) => Ok(t), Err(consensus::encode::Error::Io(ref e)) if e.kind() == ::std::io::ErrorKind::UnexpectedEof => Err(DecodeError::ShortRead), - Err(consensus::encode::Error::Io(e)) => Err(DecodeError::Io(e)), + Err(consensus::encode::Error::Io(e)) => Err(DecodeError::Io(e.kind())), Err(_) => Err(DecodeError::InvalidValue), } } -- 2.39.5