@@ -47,8 +47,6 @@ use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
47
47
#[ allow( unused_imports) ]
48
48
use crate :: prelude:: * ;
49
49
50
- use alloc:: collections:: BTreeMap ;
51
-
52
50
use crate :: io:: { self , Cursor , Read } ;
53
51
use crate :: io_extras:: read_to_end;
54
52
use core:: fmt;
@@ -686,6 +684,20 @@ pub struct ClosingSigned {
686
684
pub fee_range : Option < ClosingSignedFeeRange > ,
687
685
}
688
686
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
+
689
701
/// An [`update_add_htlc`] message to be sent to or received from a peer.
690
702
///
691
703
/// [`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 {
795
807
pub failure_code : u16 ,
796
808
}
797
809
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
-
807
810
/// A [`commitment_signed`] message to be sent to or received from a peer.
808
811
///
809
812
/// [`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 {
815
818
pub signature : Signature ,
816
819
/// Signatures on the HTLC transactions
817
820
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 > ,
820
823
#[ cfg( taproot) ]
821
824
/// The partial Taproot signature on the commitment transaction
822
825
pub partial_signature_with_nonce : Option < PartialSignatureWithNonce > ,
@@ -1962,8 +1965,7 @@ pub trait ChannelMessageHandler: BaseMessageHandler {
1962
1965
fn handle_commitment_signed ( & self , their_node_id : PublicKey , msg : & CommitmentSigned ) ;
1963
1966
/// Handle a batch of incoming `commitment_signed` message from the given peer.
1964
1967
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 > ,
1967
1969
) ;
1968
1970
/// Handle an incoming `revoke_and_ack` message from the given peer.
1969
1971
fn handle_revoke_and_ack ( & self , their_node_id : PublicKey , msg : & RevokeAndACK ) ;
@@ -1974,19 +1976,10 @@ pub trait ChannelMessageHandler: BaseMessageHandler {
1974
1976
) {
1975
1977
assert ! ( !batch. is_empty( ) ) ;
1976
1978
if batch. len ( ) == 1 {
1977
- assert ! ( batch[ 0 ] . batch. is_none( ) ) ;
1978
1979
self . handle_commitment_signed ( their_node_id, & batch[ 0 ] ) ;
1979
1980
} else {
1980
1981
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 ( ) ) ;
1990
1983
}
1991
1984
}
1992
1985
@@ -2756,18 +2749,14 @@ impl_writeable!(ClosingSignedFeeRange, {
2756
2749
max_fee_satoshis
2757
2750
} ) ;
2758
2751
2759
- impl_writeable_msg ! ( CommitmentSignedBatch , {
2760
- batch_size,
2761
- funding_txid,
2762
- } , { } ) ;
2763
-
2764
2752
#[ cfg( not( taproot) ) ]
2765
2753
impl_writeable_msg ! ( CommitmentSigned , {
2766
2754
channel_id,
2767
2755
signature,
2768
2756
htlc_signatures
2769
2757
} , {
2770
- ( 0 , batch, option) ,
2758
+ // TOOD(splicing): Change this to 1 once the spec is finalized
2759
+ ( 1001 , funding_txid, option) ,
2771
2760
} ) ;
2772
2761
2773
2762
#[ cfg( taproot) ]
@@ -2776,8 +2765,9 @@ impl_writeable_msg!(CommitmentSigned, {
2776
2765
signature,
2777
2766
htlc_signatures
2778
2767
} , {
2779
- ( 0 , batch, option) ,
2780
2768
( 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) ,
2781
2771
} ) ;
2782
2772
2783
2773
impl_writeable ! ( DecodedOnionErrorPacket , {
@@ -3097,6 +3087,13 @@ impl_writeable_msg!(PeerStorage, { data }, {});
3097
3087
3098
3088
impl_writeable_msg ! ( PeerStorageRetrieval , { data } , { } ) ;
3099
3089
3090
+ impl_writeable_msg ! ( StartBatch , {
3091
+ channel_id,
3092
+ batch_size
3093
+ } , {
3094
+ ( 1 , message_type, option)
3095
+ } ) ;
3096
+
3100
3097
// Note that this is written as a part of ChannelManager objects, and thus cannot change its
3101
3098
// serialization format in a way which assumes we know the total serialized length/message end
3102
3099
// position.
@@ -5632,13 +5629,10 @@ mod tests {
5632
5629
channel_id : ChannelId :: from_bytes ( [ 2 ; 32 ] ) ,
5633
5630
signature : sig_1,
5634
5631
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
+ ) ,
5642
5636
#[ cfg( taproot) ]
5643
5637
partial_signature_with_nonce : None ,
5644
5638
} ;
@@ -5649,7 +5643,9 @@ mod tests {
5649
5643
} else {
5650
5644
target_value += "0000" ;
5651
5645
}
5652
- target_value += "002200036e96fe9f8b0ddcd729ba03cfafa5a27b050b39d354dd980814268dfa9a44d4c2" ; // batch
5646
+ target_value += "fd03e9" ; // Type (funding_txid)
5647
+ target_value += "20" ; // Length (funding_txid)
5648
+ target_value += "6e96fe9f8b0ddcd729ba03cfafa5a27b050b39d354dd980814268dfa9a44d4c2" ; // Value
5653
5649
assert_eq ! ( encoded_value. as_hex( ) . to_string( ) , target_value) ;
5654
5650
}
5655
5651
0 commit comments