Skip to content

Commit 4be5d15

Browse files
committed
Avoid enums containing references with lifetimes
Having struct fields with references to other structs is tough in our bindings logic, but even worse if the fields are in an enum. Its simplest to just take the clone penalty here.
1 parent 8b7d802 commit 4be5d15

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

lightning/src/ln/channel.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5539,7 +5539,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
55395539
return None;
55405540
}
55415541
};
5542-
let our_node_sig = match node_signer.sign_gossip_message(msgs::UnsignedGossipMessage::ChannelAnnouncement(&announcement)) {
5542+
let our_node_sig = match node_signer.sign_gossip_message(msgs::UnsignedGossipMessage::ChannelAnnouncement(announcement.clone())) {
55435543
Err(_) => {
55445544
log_error!(logger, "Failed to generate node signature for channel_announcement. Channel will not be announced!");
55455545
return None;
@@ -5573,7 +5573,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
55735573
.map_err(|_| ChannelError::Ignore("Signer failed to retrieve own public key".to_owned()))?);
55745574
let were_node_one = announcement.node_id_1 == our_node_key;
55755575

5576-
let our_node_sig = node_signer.sign_gossip_message(msgs::UnsignedGossipMessage::ChannelAnnouncement(&announcement))
5576+
let our_node_sig = node_signer.sign_gossip_message(msgs::UnsignedGossipMessage::ChannelAnnouncement(announcement.clone()))
55775577
.map_err(|_| ChannelError::Ignore("Failed to generate node signature for channel_announcement".to_owned()))?;
55785578
let our_bitcoin_sig = self.holder_signer.sign_channel_announcement_with_funding_key(&announcement, &self.secp_ctx)
55795579
.map_err(|_| ChannelError::Ignore("Signer rejected channel_announcement".to_owned()))?;

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2650,7 +2650,7 @@ where
26502650
// If we returned an error and the `node_signer` cannot provide a signature for whatever
26512651
// reason`, we wouldn't be able to receive inbound payments through the corresponding
26522652
// channel.
2653-
let sig = self.node_signer.sign_gossip_message(msgs::UnsignedGossipMessage::ChannelUpdate(&unsigned)).unwrap();
2653+
let sig = self.node_signer.sign_gossip_message(msgs::UnsignedGossipMessage::ChannelUpdate(unsigned.clone())).unwrap();
26542654

26552655
Ok(msgs::ChannelUpdate {
26562656
signature: sig,

lightning/src/ln/msgs.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -658,16 +658,17 @@ impl Readable for NetAddress {
658658
}
659659

660660
/// Represents the set of gossip messages that require a signature from a node's identity key.
661-
pub enum UnsignedGossipMessage<'a> {
661+
#[derive(Clone)]
662+
pub enum UnsignedGossipMessage {
662663
/// An unsigned channel announcement.
663-
ChannelAnnouncement(&'a UnsignedChannelAnnouncement),
664+
ChannelAnnouncement(UnsignedChannelAnnouncement),
664665
/// An unsigned channel update.
665-
ChannelUpdate(&'a UnsignedChannelUpdate),
666+
ChannelUpdate(UnsignedChannelUpdate),
666667
/// An unsigned node announcement.
667-
NodeAnnouncement(&'a UnsignedNodeAnnouncement)
668+
NodeAnnouncement(UnsignedNodeAnnouncement)
668669
}
669670

670-
impl<'a> Writeable for UnsignedGossipMessage<'a> {
671+
impl Writeable for UnsignedGossipMessage {
671672
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
672673
match self {
673674
UnsignedGossipMessage::ChannelAnnouncement(ref msg) => msg.write(writer),

lightning/src/ln/peer_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2160,7 +2160,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
21602160
excess_data: Vec::new(),
21612161
};
21622162
let node_announce_sig = match self.node_signer.sign_gossip_message(
2163-
msgs::UnsignedGossipMessage::NodeAnnouncement(&announcement)
2163+
msgs::UnsignedGossipMessage::NodeAnnouncement(announcement.clone())
21642164
) {
21652165
Ok(sig) => sig,
21662166
Err(_) => {

lightning/src/ln/priv_short_conf_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ fn test_scid_alias_returned() {
506506
fee_proportional_millionths: last_hop[0].counterparty.forwarding_info.as_ref().unwrap().fee_proportional_millionths,
507507
excess_data: Vec::new(),
508508
};
509-
let signature = nodes[1].keys_manager.sign_gossip_message(msgs::UnsignedGossipMessage::ChannelUpdate(&contents)).unwrap();
509+
let signature = nodes[1].keys_manager.sign_gossip_message(msgs::UnsignedGossipMessage::ChannelUpdate(contents.clone())).unwrap();
510510
let msg = msgs::ChannelUpdate { signature, contents };
511511

512512
let mut err_data = Vec::new();

0 commit comments

Comments
 (0)