Skip to content

Commit 9b338cc

Browse files
committed
Make the custom message traits cloneable as they're deep in nested structs
1 parent 09673d5 commit 9b338cc

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

lightning/src/ln/wire.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ impl<T> TestEq for T {}
4545
/// A Lightning message returned by [`read`] when decoding bytes received over the wire. Each
4646
/// variant contains a message from [`msgs`] or otherwise the message type if unknown.
4747
#[allow(missing_docs)]
48-
#[derive(Debug)]
48+
#[derive(Clone, Debug)]
4949
#[cfg_attr(test, derive(PartialEq))]
50-
pub(crate) enum Message<T> where T: core::fmt::Debug + Type + TestEq {
50+
pub(crate) enum Message<T> where T: Clone + core::fmt::Debug + Type + TestEq {
5151
Init(msgs::Init),
5252
Error(msgs::ErrorMessage),
5353
Warning(msgs::WarningMessage),
@@ -407,13 +407,13 @@ pub(crate) use self::encode::Encode;
407407
/// Defines a type identifier for sending messages over the wire.
408408
///
409409
/// Messages implementing this trait specify a type and must be [`Writeable`].
410-
pub trait Type: core::fmt::Debug + Writeable {
410+
pub trait Type: core::fmt::Debug + Writeable + Clone {
411411
/// Returns the type identifying the message payload.
412412
fn type_id(&self) -> u16;
413413
}
414414

415415
#[cfg(test)]
416-
pub trait Type: core::fmt::Debug + Writeable + PartialEq {
416+
pub trait Type: core::fmt::Debug + Writeable + Clone + PartialEq {
417417
fn type_id(&self) -> u16;
418418
}
419419

@@ -423,12 +423,12 @@ impl Type for () {
423423
}
424424

425425
#[cfg(test)]
426-
impl<T: core::fmt::Debug + Writeable + PartialEq> Type for T where T: Encode {
426+
impl<T: core::fmt::Debug + Writeable + Clone + PartialEq> Type for T where T: Encode {
427427
fn type_id(&self) -> u16 { T::TYPE }
428428
}
429429

430430
#[cfg(not(test))]
431-
impl<T: core::fmt::Debug + Writeable> Type for T where T: Encode {
431+
impl<T: core::fmt::Debug + Writeable + Clone> Type for T where T: Encode {
432432
fn type_id(&self) -> u16 { T::TYPE }
433433
}
434434

@@ -775,7 +775,7 @@ mod tests {
775775
}
776776
}
777777

778-
#[derive(Eq, PartialEq, Debug)]
778+
#[derive(Clone, Eq, PartialEq, Debug)]
779779
struct TestCustomMessage {}
780780

781781
const CUSTOM_MESSAGE_TYPE : u16 = 9000;

lightning/src/onion_message/functional_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ fn reply_path() {
427427
fn invalid_custom_message_type() {
428428
let nodes = create_nodes(2);
429429

430-
#[derive(Debug)]
430+
#[derive(Debug, Clone)]
431431
struct InvalidCustomMessage{}
432432
impl OnionMessageContents for InvalidCustomMessage {
433433
fn tlv_type(&self) -> u64 {

lightning/src/onion_message/messenger.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ pub(super) const MAX_TIMER_TICKS: usize = 2;
121121
/// &keys_manager, &keys_manager, logger, message_router, &offers_message_handler,
122122
/// &custom_message_handler
123123
/// );
124-
125-
/// # #[derive(Debug)]
124+
///
125+
/// # #[derive(Debug, Clone)]
126126
/// # struct YourCustomMessage {}
127127
/// impl Writeable for YourCustomMessage {
128128
/// fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {

lightning/src/onion_message/packet.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub(super) enum Payload<T: OnionMessageContents> {
117117
/// The contents of an [`OnionMessage`] as read from the wire.
118118
///
119119
/// [`OnionMessage`]: crate::ln::msgs::OnionMessage
120-
#[derive(Debug)]
120+
#[derive(Clone, Debug)]
121121
pub enum ParsedOnionMessageContents<T: OnionMessageContents> {
122122
/// A message related to BOLT 12 Offers.
123123
Offers(OffersMessage),
@@ -147,7 +147,7 @@ impl<T: OnionMessageContents> Writeable for ParsedOnionMessageContents<T> {
147147
}
148148

149149
/// The contents of an onion message.
150-
pub trait OnionMessageContents: Writeable + core::fmt::Debug {
150+
pub trait OnionMessageContents: Writeable + core::fmt::Debug + Clone {
151151
/// Returns the TLV type identifying the message contents. MUST be >= 64.
152152
fn tlv_type(&self) -> u64;
153153
}

0 commit comments

Comments
 (0)