Skip to content

Commit 75a6c5b

Browse files
authored
Merge pull request #4244 from tnull/2025-11-cleanup-wire-message-writeable
Consistently use `wire::Message` for encoding
2 parents fbf0c61 + dfa12d8 commit 75a6c5b

File tree

6 files changed

+264
-226
lines changed

6 files changed

+264
-226
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13904,7 +13904,9 @@ where
1390413904
&MessageSendEvent::UpdateHTLCs { .. } => false,
1390513905
&MessageSendEvent::SendRevokeAndACK { .. } => false,
1390613906
&MessageSendEvent::SendClosingSigned { .. } => false,
13907+
#[cfg(simple_close)]
1390713908
&MessageSendEvent::SendClosingComplete { .. } => false,
13909+
#[cfg(simple_close)]
1390813910
&MessageSendEvent::SendClosingSig { .. } => false,
1390913911
&MessageSendEvent::SendShutdown { .. } => false,
1391013912
&MessageSendEvent::SendChannelReestablish { .. } => false,

lightning/src/ln/functional_test_utils.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,9 @@ pub fn remove_first_msg_event_to_node(
11241124
MessageSendEvent::UpdateHTLCs { node_id, .. } => node_id == msg_node_id,
11251125
MessageSendEvent::SendRevokeAndACK { node_id, .. } => node_id == msg_node_id,
11261126
MessageSendEvent::SendClosingSigned { node_id, .. } => node_id == msg_node_id,
1127+
#[cfg(simple_close)]
11271128
MessageSendEvent::SendClosingComplete { node_id, .. } => node_id == msg_node_id,
1129+
#[cfg(simple_close)]
11281130
MessageSendEvent::SendClosingSig { node_id, .. } => node_id == msg_node_id,
11291131
MessageSendEvent::SendShutdown { node_id, .. } => node_id == msg_node_id,
11301132
MessageSendEvent::SendChannelReestablish { node_id, .. } => node_id == msg_node_id,

lightning/src/ln/msgs.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,13 +1857,15 @@ pub enum MessageSendEvent {
18571857
msg: ClosingSigned,
18581858
},
18591859
/// Used to indicate that a `closing_complete` message should be sent to the peer with the given `node_id`.
1860+
#[cfg(simple_close)]
18601861
SendClosingComplete {
18611862
/// The node_id of the node which should receive this message
18621863
node_id: PublicKey,
18631864
/// The message which should be sent.
18641865
msg: ClosingComplete,
18651866
},
18661867
/// Used to indicate that a `closing_sig` message should be sent to the peer with the given `node_id`.
1868+
#[cfg(simple_close)]
18671869
SendClosingSig {
18681870
/// The node_id of the node which should receive this message
18691871
node_id: PublicKey,

lightning/src/ln/peer_channel_encryptor.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ use crate::prelude::*;
1212
use crate::ln::msgs;
1313
use crate::ln::msgs::LightningError;
1414
use crate::ln::wire;
15+
use crate::ln::wire::Type;
1516
use crate::sign::{NodeSigner, Recipient};
17+
use crate::util::ser::Writeable;
1618

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

575579
self.encrypt_message_with_header_0s(&mut res.0);
576580
res.0

0 commit comments

Comments
 (0)