@@ -47,8 +47,6 @@ use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
4747#[ allow( unused_imports) ]
4848use crate :: prelude:: * ;
4949
50- use alloc:: collections:: BTreeMap ;
51-
5250use crate :: io:: { self , Cursor , Read } ;
5351use crate :: io_extras:: read_to_end;
5452use core:: fmt;
@@ -686,6 +684,20 @@ pub struct ClosingSigned {
686684 pub fee_range : Option < ClosingSignedFeeRange > ,
687685}
688686
687+ /// A [`start_batch`] message to be sent to group together multiple channel messages as a single
688+ /// logical message.
689+ ///
690+ /// [`start_batch`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#batching-channel-messages
691+ #[ derive( Clone , Debug , Hash , PartialEq , Eq ) ]
692+ pub struct StartBatch {
693+ /// The channel ID of all messages in the batch.
694+ pub channel_id : ChannelId ,
695+ /// The number of messages to follow.
696+ pub batch_size : u16 ,
697+ /// The type of all messages expected in the batch.
698+ pub message_type : Option < 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
@@ -795,15 +807,6 @@ pub struct UpdateFailMalformedHTLC {
795807 pub failure_code : u16 ,
796808}
797809
798- /// Optional batch parameters for `commitment_signed` message.
799- #[ derive( Clone , Debug , Hash , PartialEq , Eq ) ]
800- pub struct CommitmentSignedBatch {
801- /// Batch size N: all N `commitment_signed` messages must be received before being processed
802- pub batch_size : u16 ,
803- /// The funding transaction, to discriminate among multiple pending funding transactions (e.g. in case of splicing)
804- pub funding_txid : Txid ,
805- }
806-
807810/// A [`commitment_signed`] message to be sent to or received from a peer.
808811///
809812/// [`commitment_signed`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#committing-updates-so-far-commitment_signed
@@ -815,8 +818,8 @@ pub struct CommitmentSigned {
815818 pub signature : Signature ,
816819 /// Signatures on the HTLC transactions
817820 pub htlc_signatures : Vec < Signature > ,
818- /// Optional batch size and other parameters
819- pub batch : Option < CommitmentSignedBatch > ,
821+ /// The funding transaction, to discriminate among multiple pending funding transactions (e.g. in case of splicing)
822+ pub funding_txid : Option < Txid > ,
820823 #[ cfg( taproot) ]
821824 /// The partial Taproot signature on the commitment transaction
822825 pub partial_signature_with_nonce : Option < PartialSignatureWithNonce > ,
@@ -1962,8 +1965,7 @@ pub trait ChannelMessageHandler: BaseMessageHandler {
19621965 fn handle_commitment_signed ( & self , their_node_id : PublicKey , msg : & CommitmentSigned ) ;
19631966 /// Handle a batch of incoming `commitment_signed` message from the given peer.
19641967 fn handle_commitment_signed_batch (
1965- & self , their_node_id : PublicKey , channel_id : ChannelId ,
1966- batch : BTreeMap < Txid , CommitmentSigned > ,
1968+ & self , their_node_id : PublicKey , channel_id : ChannelId , batch : Vec < CommitmentSigned > ,
19671969 ) ;
19681970 /// Handle an incoming `revoke_and_ack` message from the given peer.
19691971 fn handle_revoke_and_ack ( & self , their_node_id : PublicKey , msg : & RevokeAndACK ) ;
@@ -1974,19 +1976,10 @@ pub trait ChannelMessageHandler: BaseMessageHandler {
19741976 ) {
19751977 assert ! ( !batch. is_empty( ) ) ;
19761978 if batch. len ( ) == 1 {
1977- assert ! ( batch[ 0 ] . batch. is_none( ) ) ;
19781979 self . handle_commitment_signed ( their_node_id, & batch[ 0 ] ) ;
19791980 } else {
19801981 let channel_id = batch[ 0 ] . channel_id ;
1981- let batch: BTreeMap < Txid , CommitmentSigned > = batch
1982- . iter ( )
1983- . cloned ( )
1984- . map ( |mut cs| {
1985- let funding_txid = cs. batch . take ( ) . unwrap ( ) . funding_txid ;
1986- ( funding_txid, cs)
1987- } )
1988- . collect ( ) ;
1989- self . handle_commitment_signed_batch ( their_node_id, channel_id, batch) ;
1982+ self . handle_commitment_signed_batch ( their_node_id, channel_id, batch. clone ( ) ) ;
19901983 }
19911984 }
19921985
@@ -2756,18 +2749,14 @@ impl_writeable!(ClosingSignedFeeRange, {
27562749 max_fee_satoshis
27572750} ) ;
27582751
2759- impl_writeable_msg ! ( CommitmentSignedBatch , {
2760- batch_size,
2761- funding_txid,
2762- } , { } ) ;
2763-
27642752#[ cfg( not( taproot) ) ]
27652753impl_writeable_msg ! ( CommitmentSigned , {
27662754 channel_id,
27672755 signature,
27682756 htlc_signatures
27692757} , {
2770- ( 0 , batch, option) ,
2758+ // TOOD(splicing): Change this to 1 once the spec is finalized
2759+ ( 1001 , funding_txid, option) ,
27712760} ) ;
27722761
27732762#[ cfg( taproot) ]
@@ -2776,8 +2765,9 @@ impl_writeable_msg!(CommitmentSigned, {
27762765 signature,
27772766 htlc_signatures
27782767} , {
2779- ( 0 , batch, option) ,
27802768 ( 2 , partial_signature_with_nonce, option) ,
2769+ // TOOD(splicing): Change this to 1 and reorder once the spec is finalized
2770+ ( 1001 , funding_txid, option) ,
27812771} ) ;
27822772
27832773impl_writeable ! ( DecodedOnionErrorPacket , {
@@ -3097,6 +3087,13 @@ impl_writeable_msg!(PeerStorage, { data }, {});
30973087
30983088impl_writeable_msg ! ( PeerStorageRetrieval , { data } , { } ) ;
30993089
3090+ impl_writeable_msg ! ( StartBatch , {
3091+ channel_id,
3092+ batch_size
3093+ } , {
3094+ ( 1 , message_type, option)
3095+ } ) ;
3096+
31003097// Note that this is written as a part of ChannelManager objects, and thus cannot change its
31013098// serialization format in a way which assumes we know the total serialized length/message end
31023099// position.
@@ -5632,13 +5629,10 @@ mod tests {
56325629 channel_id : ChannelId :: from_bytes ( [ 2 ; 32 ] ) ,
56335630 signature : sig_1,
56345631 htlc_signatures : if htlcs { vec ! [ sig_2, sig_3, sig_4] } else { Vec :: new ( ) } ,
5635- batch : Some ( msgs:: CommitmentSignedBatch {
5636- batch_size : 3 ,
5637- funding_txid : Txid :: from_str (
5638- "c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e" ,
5639- )
5640- . unwrap ( ) ,
5641- } ) ,
5632+ funding_txid : Some (
5633+ Txid :: from_str ( "c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e" )
5634+ . unwrap ( ) ,
5635+ ) ,
56425636 #[ cfg( taproot) ]
56435637 partial_signature_with_nonce : None ,
56445638 } ;
@@ -5649,7 +5643,9 @@ mod tests {
56495643 } else {
56505644 target_value += "0000" ;
56515645 }
5652- target_value += "002200036e96fe9f8b0ddcd729ba03cfafa5a27b050b39d354dd980814268dfa9a44d4c2" ; // batch
5646+ target_value += "fd03e9" ; // Type (funding_txid)
5647+ target_value += "20" ; // Length (funding_txid)
5648+ target_value += "6e96fe9f8b0ddcd729ba03cfafa5a27b050b39d354dd980814268dfa9a44d4c2" ; // Value
56535649 assert_eq ! ( encoded_value. as_hex( ) . to_string( ) , target_value) ;
56545650 }
56555651
0 commit comments