Make the custom message traits cloneable as they're deep in nested structs
authorMatt Corallo <git@bluematt.me>
Fri, 24 Sep 2021 18:44:32 +0000 (18:44 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 22 Apr 2024 21:57:48 +0000 (21:57 +0000)
lightning/src/ln/wire.rs
lightning/src/onion_message/functional_tests.rs
lightning/src/onion_message/messenger.rs
lightning/src/onion_message/packet.rs

index 5087df33b83fee55bfd7edc788ae13459deb486e..855fbfe53d2b29e048b0b54495d226dc0ec49f71 100644 (file)
@@ -45,9 +45,9 @@ impl<T> TestEq for T {}
 /// A Lightning message returned by [`read`] when decoding bytes received over the wire. Each
 /// variant contains a message from [`msgs`] or otherwise the message type if unknown.
 #[allow(missing_docs)]
-#[derive(Debug)]
+#[derive(Clone, Debug)]
 #[cfg_attr(test, derive(PartialEq))]
-pub(crate) enum Message<T> where T: core::fmt::Debug + Type + TestEq {
+pub(crate) enum Message<T> where T: Clone + core::fmt::Debug + Type + TestEq {
        Init(msgs::Init),
        Error(msgs::ErrorMessage),
        Warning(msgs::WarningMessage),
@@ -407,13 +407,13 @@ pub(crate) use self::encode::Encode;
 /// Defines a type identifier for sending messages over the wire.
 ///
 /// Messages implementing this trait specify a type and must be [`Writeable`].
-pub trait Type: core::fmt::Debug + Writeable {
+pub trait Type: core::fmt::Debug + Writeable + Clone {
        /// Returns the type identifying the message payload.
        fn type_id(&self) -> u16;
 }
 
 #[cfg(test)]
-pub trait Type: core::fmt::Debug + Writeable + PartialEq {
+pub trait Type: core::fmt::Debug + Writeable + Clone + PartialEq {
        fn type_id(&self) -> u16;
 }
 
@@ -423,12 +423,12 @@ impl Type for () {
 }
 
 #[cfg(test)]
-impl<T: core::fmt::Debug + Writeable + PartialEq> Type for T where T: Encode {
+impl<T: core::fmt::Debug + Writeable + Clone + PartialEq> Type for T where T: Encode {
        fn type_id(&self) -> u16 { T::TYPE }
 }
 
 #[cfg(not(test))]
-impl<T: core::fmt::Debug + Writeable> Type for T where T: Encode {
+impl<T: core::fmt::Debug + Writeable + Clone> Type for T where T: Encode {
        fn type_id(&self) -> u16 { T::TYPE }
 }
 
@@ -775,7 +775,7 @@ mod tests {
                }
        }
 
-       #[derive(Eq, PartialEq, Debug)]
+       #[derive(Clone, Eq, PartialEq, Debug)]
        struct TestCustomMessage {}
 
        const CUSTOM_MESSAGE_TYPE : u16 = 9000;
index 3947e1531cc600a35c8962ca6f81ef76a456ea67..f1246531ab0630d8464c357c174628f69f34e2fc 100644 (file)
@@ -427,7 +427,7 @@ fn reply_path() {
 fn invalid_custom_message_type() {
        let nodes = create_nodes(2);
 
-       #[derive(Debug)]
+       #[derive(Debug, Clone)]
        struct InvalidCustomMessage{}
        impl OnionMessageContents for InvalidCustomMessage {
                fn tlv_type(&self) -> u64 {
index f56f425061f9e2d50c4d8c009ca9a67f9bd8a2ee..5554497a4b74ddd0e9729380c94fe60066faba09 100644 (file)
@@ -121,8 +121,8 @@ pub(super) const MAX_TIMER_TICKS: usize = 2;
 ///     &keys_manager, &keys_manager, logger, message_router, &offers_message_handler,
 ///     &custom_message_handler
 /// );
-
-/// # #[derive(Debug)]
+///
+/// # #[derive(Debug, Clone)]
 /// # struct YourCustomMessage {}
 /// impl Writeable for YourCustomMessage {
 ///    fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
index d9349fdadbfaba6c1f0d08c265c48bf14da49bb7..e38dbd089311c02602dcca61d62b8050b623e0c4 100644 (file)
@@ -117,7 +117,7 @@ pub(super) enum Payload<T: OnionMessageContents> {
 /// The contents of an [`OnionMessage`] as read from the wire.
 ///
 /// [`OnionMessage`]: crate::ln::msgs::OnionMessage
-#[derive(Debug)]
+#[derive(Clone, Debug)]
 pub enum ParsedOnionMessageContents<T: OnionMessageContents> {
        /// A message related to BOLT 12 Offers.
        Offers(OffersMessage),
@@ -147,7 +147,7 @@ impl<T: OnionMessageContents> Writeable for ParsedOnionMessageContents<T> {
 }
 
 /// The contents of an onion message.
-pub trait OnionMessageContents: Writeable + core::fmt::Debug {
+pub trait OnionMessageContents: Writeable + core::fmt::Debug + Clone {
        /// Returns the TLV type identifying the message contents. MUST be >= 64.
        fn tlv_type(&self) -> u64;
 }