Skip to content

Commit 91bd3e3

Browse files
committed
Add start_batch message
Instead of batching commitment_signed messages using a batch TLV, the splicing spec has been updated to introduce a start_batch messages. It used to indicate that the next batch_size messages for the channel_id should be treated as one logical message. This commit simply adds the message while the following commits will implement the handling logic.
1 parent 98297a6 commit 91bd3e3

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

lightning/src/ln/msgs.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,18 @@ pub struct ClosingSigned {
686686
pub fee_range: Option<ClosingSignedFeeRange>,
687687
}
688688

689+
/// A [`start_batch`] message to be sent to group together multiple channel messages as a single
690+
/// logical message.
691+
///
692+
/// [`start_batch`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#batching-channel-messages
693+
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
694+
pub struct StartBatch {
695+
/// The channel ID of all messages in the batch.
696+
pub channel_id: ChannelId,
697+
/// The number of messages to follow.
698+
pub batch_size: u16,
699+
}
700+
689701
/// An [`update_add_htlc`] message to be sent to or received from a peer.
690702
///
691703
/// [`update_add_htlc`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#adding-an-htlc-update_add_htlc
@@ -3082,6 +3094,11 @@ impl_writeable_msg!(PeerStorage, { data }, {});
30823094

30833095
impl_writeable_msg!(PeerStorageRetrieval, { data }, {});
30843096

3097+
impl_writeable_msg!(StartBatch, {
3098+
channel_id,
3099+
batch_size
3100+
}, {});
3101+
30853102
// Note that this is written as a part of ChannelManager objects, and thus cannot change its
30863103
// serialization format in a way which assumes we know the total serialized length/message end
30873104
// position.

lightning/src/ln/peer_handler.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,9 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
18991899
},
19001900

19011901
// Channel messages:
1902+
wire::Message::StartBatch(_msg) => {
1903+
debug_assert!(false);
1904+
},
19021905
wire::Message::OpenChannel(msg) => {
19031906
self.message_handler.chan_handler.handle_open_channel(their_node_id, &msg);
19041907
},

lightning/src/ln/wire.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ pub(crate) enum Message<T: core::fmt::Debug + Type + TestEq> {
8282
Shutdown(msgs::Shutdown),
8383
ClosingSigned(msgs::ClosingSigned),
8484
OnionMessage(msgs::OnionMessage),
85+
StartBatch(msgs::StartBatch),
8586
UpdateAddHTLC(msgs::UpdateAddHTLC),
8687
UpdateFulfillHTLC(msgs::UpdateFulfillHTLC),
8788
UpdateFailHTLC(msgs::UpdateFailHTLC),
@@ -142,6 +143,7 @@ impl<T: core::fmt::Debug + Type + TestEq> Writeable for Message<T> {
142143
&Message::Shutdown(ref msg) => msg.write(writer),
143144
&Message::ClosingSigned(ref msg) => msg.write(writer),
144145
&Message::OnionMessage(ref msg) => msg.write(writer),
146+
&Message::StartBatch(ref msg) => msg.write(writer),
145147
&Message::UpdateAddHTLC(ref msg) => msg.write(writer),
146148
&Message::UpdateFulfillHTLC(ref msg) => msg.write(writer),
147149
&Message::UpdateFailHTLC(ref msg) => msg.write(writer),
@@ -202,6 +204,7 @@ impl<T: core::fmt::Debug + Type + TestEq> Type for Message<T> {
202204
&Message::Shutdown(ref msg) => msg.type_id(),
203205
&Message::ClosingSigned(ref msg) => msg.type_id(),
204206
&Message::OnionMessage(ref msg) => msg.type_id(),
207+
&Message::StartBatch(ref msg) => msg.type_id(),
205208
&Message::UpdateAddHTLC(ref msg) => msg.type_id(),
206209
&Message::UpdateFulfillHTLC(ref msg) => msg.type_id(),
207210
&Message::UpdateFailHTLC(ref msg) => msg.type_id(),
@@ -350,6 +353,9 @@ where
350353
msgs::OnionMessage::TYPE => {
351354
Ok(Message::OnionMessage(LengthReadable::read_from_fixed_length_buffer(buffer)?))
352355
},
356+
msgs::StartBatch::TYPE => {
357+
Ok(Message::StartBatch(LengthReadable::read_from_fixed_length_buffer(buffer)?))
358+
},
353359
msgs::UpdateAddHTLC::TYPE => {
354360
Ok(Message::UpdateAddHTLC(LengthReadable::read_from_fixed_length_buffer(buffer)?))
355361
},
@@ -590,6 +596,10 @@ impl Encode for msgs::OnionMessage {
590596
const TYPE: u16 = 513;
591597
}
592598

599+
impl Encode for msgs::StartBatch {
600+
const TYPE: u16 = 127;
601+
}
602+
593603
impl Encode for msgs::UpdateAddHTLC {
594604
const TYPE: u16 = 128;
595605
}

0 commit comments

Comments
 (0)