Skip to content

Commit f959254

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 e14e58d commit f959254

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
@@ -11633,7 +11633,7 @@ where
1163311633
return None;
1163411634
}
1163511635
};
11636-
let our_node_sig = match node_signer.sign_gossip_message(msgs::UnsignedGossipMessage::ChannelAnnouncement(&announcement)) {
11636+
let our_node_sig = match node_signer.sign_gossip_message(msgs::UnsignedGossipMessage::ChannelAnnouncement(announcement.clone())) {
1163711637
Err(_) => {
1163811638
log_error!(logger, "Failed to generate node signature for channel_announcement. Channel will not be announced!");
1163911639
return None;
@@ -11682,7 +11682,7 @@ where
1168211682
.map_err(|_| ChannelError::Ignore("Signer failed to retrieve own public key".to_owned()))?);
1168311683
let were_node_one = announcement.node_id_1 == our_node_key;
1168411684

11685-
let our_node_sig = node_signer.sign_gossip_message(msgs::UnsignedGossipMessage::ChannelAnnouncement(&announcement))
11685+
let our_node_sig = node_signer.sign_gossip_message(msgs::UnsignedGossipMessage::ChannelAnnouncement(announcement.clone()))
1168611686
.map_err(|_| ChannelError::Ignore("Failed to generate node signature for channel_announcement".to_owned()))?;
1168711687
match &self.context.holder_signer {
1168811688
ChannelSignerType::Ecdsa(ecdsa) => {

lightning/src/ln/channelmanager.rs

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

51875187
Ok(msgs::ChannelUpdate {
51885188
signature: sig,

lightning/src/ln/msgs.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,16 +1357,17 @@ impl FromStr for SocketAddress {
13571357
}
13581358

13591359
/// Represents the set of gossip messages that require a signature from a node's identity key.
1360-
pub enum UnsignedGossipMessage<'a> {
1360+
#[derive(Clone)]
1361+
pub enum UnsignedGossipMessage {
13611362
/// An unsigned channel announcement.
1362-
ChannelAnnouncement(&'a UnsignedChannelAnnouncement),
1363+
ChannelAnnouncement(UnsignedChannelAnnouncement),
13631364
/// An unsigned channel update.
1364-
ChannelUpdate(&'a UnsignedChannelUpdate),
1365+
ChannelUpdate(UnsignedChannelUpdate),
13651366
/// An unsigned node announcement.
1366-
NodeAnnouncement(&'a UnsignedNodeAnnouncement),
1367+
NodeAnnouncement(UnsignedNodeAnnouncement),
13671368
}
13681369

1369-
impl<'a> Writeable for UnsignedGossipMessage<'a> {
1370+
impl Writeable for UnsignedGossipMessage {
13701371
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
13711372
match self {
13721373
UnsignedGossipMessage::ChannelAnnouncement(ref msg) => msg.write(writer),

lightning/src/ln/offers_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ fn announce_node_address<'a, 'b, 'c>(
132132
excess_data: Vec::new(),
133133
};
134134
let signature = node.keys_manager.sign_gossip_message(
135-
UnsignedGossipMessage::NodeAnnouncement(&announcement)
135+
UnsignedGossipMessage::NodeAnnouncement(announcement.clone())
136136
).unwrap();
137137

138138
let msg = NodeAnnouncement {

lightning/src/ln/peer_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3650,7 +3650,7 @@ where
36503650
};
36513651
let node_announce_sig = match self
36523652
.node_signer
3653-
.sign_gossip_message(msgs::UnsignedGossipMessage::NodeAnnouncement(&announcement))
3653+
.sign_gossip_message(msgs::UnsignedGossipMessage::NodeAnnouncement(announcement.clone()))
36543654
{
36553655
Ok(sig) => sig,
36563656
Err(_) => {

0 commit comments

Comments
 (0)