Add additional Clone derives
authorMatt Corallo <git@bluematt.me>
Thu, 11 Feb 2021 03:25:42 +0000 (22:25 -0500)
committerMatt Corallo <git@bluematt.me>
Thu, 11 Feb 2021 03:34:19 +0000 (22:34 -0500)
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
lightning/src/chain/channelmonitor.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/msgs.rs
lightning/src/ln/peer_handler.rs
lightning/src/routing/network_graph.rs
lightning/src/util/errors.rs
lightning/src/util/ser.rs

index 4eb85714f3e22a813393a6c47a1e50bab7caaaf9..55f08b628977daa2bd4611387877d5713d1d668d 100644 (file)
@@ -130,7 +130,7 @@ pub fn do_test<Out: test_logger::Output>(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)),
                                }
                        }
                }}
index b46a2df13eea8d8c462e1df72dd6dca9fac2b45f..95495d1bf1334bb2381e6bf92b3485acf2f8ce09 100644 (file)
@@ -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.
index 621013724bc4195cd58b1dac9fb8c6aee915ef0b..3dcc74f905269a7f8a58978a529f96b6e48a5851 100644 (file)
@@ -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
index 289cdae4ed760eaeb7206e7d645c7a90bd55f07f..798764dc66042524eacda589d343840e246a8a1e 100644 (file)
@@ -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())
                }
        }
 }
index a3c2292103c3b64dc2b88697a9fcb0241701a375..0e9facb8ac888aee43711439a1453085533eb536 100644 (file)
@@ -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.
index bba99244b4a98624a1725c2d57a7eb2be15b6712..040d3617bf8045b1d20c54b5ff6c1bad9c06ad6b 100644 (file)
@@ -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
index a2a45a7b3afc66372ff3e41e6655d9a199b67099..f67621c828ca521f4739d99ec5a54760310cb1a8 100644 (file)
@@ -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.
index 581f228ba7574323180cf662581425e301d74aab..1d24e26408fba830603cb3f95b9b4bbd20354d57 100644 (file)
@@ -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),
                                }
                        }