Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13872,7 +13872,9 @@ where
&MessageSendEvent::UpdateHTLCs { .. } => false,
&MessageSendEvent::SendRevokeAndACK { .. } => false,
&MessageSendEvent::SendClosingSigned { .. } => false,
#[cfg(simple_close)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we've historically not cfg-flagged messages even if the implementation in LDK isn't complete. There doesn't really seem any reason to imo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we've historically not cfg-flagged messages even if the implementation in LDK isn't complete. There doesn't really seem any reason to imo.

Hmm, yeah, debatable. But this PR seems the wrong place to drop the cfg(simple_close). I only added the instances that became necessary by the new approach.

&MessageSendEvent::SendClosingComplete { .. } => false,
#[cfg(simple_close)]
&MessageSendEvent::SendClosingSig { .. } => false,
&MessageSendEvent::SendShutdown { .. } => false,
&MessageSendEvent::SendChannelReestablish { .. } => false,
Expand Down
2 changes: 2 additions & 0 deletions lightning/src/ln/functional_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,9 @@ pub fn remove_first_msg_event_to_node(
MessageSendEvent::UpdateHTLCs { node_id, .. } => node_id == msg_node_id,
MessageSendEvent::SendRevokeAndACK { node_id, .. } => node_id == msg_node_id,
MessageSendEvent::SendClosingSigned { node_id, .. } => node_id == msg_node_id,
#[cfg(simple_close)]
MessageSendEvent::SendClosingComplete { node_id, .. } => node_id == msg_node_id,
#[cfg(simple_close)]
MessageSendEvent::SendClosingSig { node_id, .. } => node_id == msg_node_id,
MessageSendEvent::SendShutdown { node_id, .. } => node_id == msg_node_id,
MessageSendEvent::SendChannelReestablish { node_id, .. } => node_id == msg_node_id,
Expand Down
2 changes: 2 additions & 0 deletions lightning/src/ln/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1857,13 +1857,15 @@ pub enum MessageSendEvent {
msg: ClosingSigned,
},
/// Used to indicate that a `closing_complete` message should be sent to the peer with the given `node_id`.
#[cfg(simple_close)]
SendClosingComplete {
/// The node_id of the node which should receive this message
node_id: PublicKey,
/// The message which should be sent.
msg: ClosingComplete,
},
/// Used to indicate that a `closing_sig` message should be sent to the peer with the given `node_id`.
#[cfg(simple_close)]
SendClosingSig {
/// The node_id of the node which should receive this message
node_id: PublicKey,
Expand Down
8 changes: 6 additions & 2 deletions lightning/src/ln/peer_channel_encryptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use crate::prelude::*;
use crate::ln::msgs;
use crate::ln::msgs::LightningError;
use crate::ln::wire;
use crate::ln::wire::Type;
use crate::sign::{NodeSigner, Recipient};
use crate::util::ser::Writeable;

use bitcoin::hashes::sha256::Hash as Sha256;
use bitcoin::hashes::{Hash, HashEngine};
Expand Down Expand Up @@ -565,12 +567,14 @@ impl PeerChannelEncryptor {
/// Encrypts the given message, returning the encrypted version.
/// panics if the length of `message`, once encoded, is greater than 65535 or if the Noise
/// handshake has not finished.
pub fn encrypt_message<M: wire::Type>(&mut self, message: &M) -> Vec<u8> {
pub fn encrypt_message<T: wire::Type>(&mut self, message: wire::Message<T>) -> Vec<u8> {
// Allocate a buffer with 2KB, fitting most common messages. Reserve the first 16+2 bytes
// for the 2-byte message type prefix and its MAC.
let mut res = VecWriter(Vec::with_capacity(MSG_BUF_ALLOC_SIZE));
res.0.resize(16 + 2, 0);
wire::write(message, &mut res).expect("In-memory messages must never fail to serialize");

message.type_id().write(&mut res).expect("In-memory messages must never fail to serialize");
message.write(&mut res).expect("In-memory messages must never fail to serialize");

self.encrypt_message_with_header_0s(&mut res.0);
res.0
Expand Down
Loading