@@ -604,16 +604,18 @@ impl ChannelStaticInfo {
604
604
}
605
605
}
606
606
607
- /// This class tracks the information needed to build a holder's commitment transaction and to actually
608
- /// build and sign. It is used for holder transactions that we sign only when needed.
607
+ /// This class tracks the information needed to build a holder's commitment transaction.
608
+ /// It is used for holder transactions that we sign only when needed.
609
+ ///
610
+ /// TODO(devrandom): take over signing functionality from HolderCommitmentTransaction
609
611
#[ derive( Clone ) ]
610
612
pub struct HolderCommitmentTransactionInfo {
611
613
/// The non-party-specific transaction information
612
614
pub info : CommitmentTransactionInfo ,
613
615
/// Our counterparty's signature for the transaction
614
616
pub counterparty_sig : Signature ,
615
617
/// All non-dust counterparty HTLC signatures, in the order they appear in the transaction
616
- pub htlc_sigs : Vec < Signature > ,
618
+ pub counterparty_htlc_sigs : Vec < Signature > ,
617
619
}
618
620
619
621
impl PartialEq for HolderCommitmentTransactionInfo {
@@ -624,7 +626,7 @@ impl PartialEq for HolderCommitmentTransactionInfo {
624
626
}
625
627
626
628
impl_writeable ! ( HolderCommitmentTransactionInfo , 0 , {
627
- info, counterparty_sig, htlc_sigs
629
+ info, counterparty_sig, counterparty_htlc_sigs
628
630
} ) ;
629
631
630
632
impl HolderCommitmentTransactionInfo {
@@ -649,7 +651,7 @@ impl HolderCommitmentTransactionInfo {
649
651
}
650
652
} ,
651
653
counterparty_sig : dummy_sig,
652
- htlc_sigs : Vec :: new ( )
654
+ counterparty_htlc_sigs : Vec :: new ( )
653
655
}
654
656
}
655
657
pub ( crate ) fn txid < T : secp256k1:: Signing + secp256k1:: Verification > ( & self , channel_static_info : & ChannelStaticInfo , secp_ctx : & Secp256k1 < T > ) -> Txid {
@@ -659,7 +661,7 @@ impl HolderCommitmentTransactionInfo {
659
661
660
662
impl HolderCommitmentTransactionInfo {
661
663
pub ( crate ) fn to_holder_commitment_tx < T : secp256k1:: Signing + secp256k1:: Verification > ( & self , channel_static_info : & ChannelStaticInfo , secp_ctx : & Secp256k1 < T > ) -> HolderCommitmentTransaction {
662
- let opt_sigs: Vec < Option < Signature > > = self . htlc_sigs . iter ( ) . map ( |s| Some ( s. clone ( ) ) ) . collect ( ) ;
664
+ let opt_sigs: Vec < Option < Signature > > = self . counterparty_htlc_sigs . iter ( ) . map ( |s| Some ( s. clone ( ) ) ) . collect ( ) ;
663
665
let mut htlcs = self . info . htlcs . clone ( ) ;
664
666
let htlcs_with_sig = htlcs. drain ( ..) . zip ( opt_sigs) . collect ( ) ;
665
667
self . info . to_holder_commitment_tx ( self . counterparty_sig , htlcs_with_sig, channel_static_info, secp_ctx)
@@ -683,9 +685,11 @@ pub struct CommitmentTransactionInfo {
683
685
pub to_countersignatory_value_sat : u64 ,
684
686
/// The feerate paid per 1000-weight-unit in this commitment transaction.
685
687
pub feerate_per_kw : u32 ,
686
- /// The HTLCs which were included in this commitment transaction in output order.
688
+ /// The non-dust HTLCs (direction, amt, height expiration, hash, transaction output index)
689
+ /// which were included in this commitment transaction in output order.
690
+ /// The transaction index is always populated.
687
691
pub htlcs : Vec < HTLCOutputInCommitment > ,
688
- // A cache of pubkeys required to construct the transaction
692
+ // A cache of the parties' pubkeys required to construct the transaction
689
693
pub ( crate ) keys : TxCreationKeys ,
690
694
}
691
695
@@ -728,21 +732,12 @@ impl_writeable!(CommitmentTransactionInfo, 0, {
728
732
impl CommitmentTransactionInfo {
729
733
/// Construct an object of the class while assigning transaction output indices to HTLCs.
730
734
///
731
- /// Also keeps track of associated HTLC data and returns it along with the mutated HTLCs.
732
- pub fn new_with_auxiliary_htlc_data < T : Copy > (
733
- commitment_number : u64 ,
734
- to_broadcaster_value_sat : u64 ,
735
- to_countersignatory_value_sat : u64 ,
736
- keys : TxCreationKeys ,
737
- feerate_per_kw : u32 ,
738
- htlcs_with_aux : Vec < ( HTLCOutputInCommitment , T ) > ,
739
- broadcaster_pubkeys : & ChannelPublicKeys ,
740
- countersignatory_pubkeys : & ChannelPublicKeys ,
741
- contest_delay : u16 ,
742
- secp_ctx : & Secp256k1 < secp256k1:: All >
743
- ) -> ( CommitmentTransactionInfo , Vec < ( HTLCOutputInCommitment , T ) > ) {
744
- // Populate output indices while keeping track of the auxiliary data
745
- let mut txouts = Self :: do_build_outputs ( & keys, to_broadcaster_value_sat, to_countersignatory_value_sat, & htlcs_with_aux, broadcaster_pubkeys, countersignatory_pubkeys, contest_delay, & secp_ctx) . unwrap ( ) ;
735
+ /// Also keeps track of auxiliary HTLC data and returns it along with the mutated and sorted HTLCs.
736
+ /// This allows the caller to match the HTLC output index with the auxiliary data.
737
+ /// This auxiliary data is not stored in this object.
738
+ pub fn new_with_auxiliary_htlc_data < T : Copy > ( commitment_number : u64 , to_broadcaster_value_sat : u64 , to_countersignatory_value_sat : u64 , keys : TxCreationKeys , feerate_per_kw : u32 , htlcs_with_aux : Vec < ( HTLCOutputInCommitment , T ) > , holder : bool , channel_static_info : & ChannelStaticInfo , secp_ctx : & Secp256k1 < secp256k1:: All > ) -> ( CommitmentTransactionInfo , Vec < ( HTLCOutputInCommitment , T ) > ) {
739
+ // Sort outputs and populate output indices while keeping track of the auxiliary data
740
+ let mut txouts = Self :: do_build_outputs ( & keys, to_broadcaster_value_sat, to_countersignatory_value_sat, & htlcs_with_aux, holder, channel_static_info, & secp_ctx) . unwrap ( ) ;
746
741
let mut result_htlcs_with_aux = Vec :: new ( ) ;
747
742
let mut htlcs = Vec :: new ( ) ;
748
743
for ( idx, mut out) in txouts. drain ( ..) . enumerate ( ) {
@@ -769,15 +764,8 @@ impl CommitmentTransactionInfo {
769
764
tx. txid ( )
770
765
}
771
766
772
- /// Build the Bitcoin transaction.
773
- ///
774
- /// Required channel-static fields are provided by the caller.
775
- pub fn build < T : secp256k1:: Signing + secp256k1:: Verification > (
776
- & self ,
777
- holder : bool ,
778
- channel_static_info : & ChannelStaticInfo ,
779
- secp_ctx : & Secp256k1 < T > ,
780
- ) -> Result < ( bitcoin:: Transaction , Vec < HTLCOutputInCommitment > , Vec < Script > ) , ( ) > {
767
+ /// Build the Bitcoin transaction
768
+ pub fn build < T : secp256k1:: Signing + secp256k1:: Verification > ( & self , holder : bool , channel_static_info : & ChannelStaticInfo , secp_ctx : & Secp256k1 < T > ) -> Result < ( bitcoin:: Transaction , Vec < HTLCOutputInCommitment > , Vec < Script > ) , ( ) > {
781
769
let ( obscured_commitment_transaction_number, txins) = self . build_inputs ( holder, channel_static_info) ;
782
770
783
771
let mut txouts = self . build_outputs ( holder, channel_static_info, secp_ctx) ?;
@@ -808,18 +796,15 @@ impl CommitmentTransactionInfo {
808
796
809
797
fn build_outputs < T : secp256k1:: Signing + secp256k1:: Verification > ( & self , holder : bool , channel_static_info : & ChannelStaticInfo , secp_ctx : & Secp256k1 < T > ) -> Result < Vec < ( TxOut , ( Script , Option < HTLCOutputInCommitment > ) ) > , ( ) > {
810
798
let htlcs = self . htlcs . iter ( ) . map ( |h| ( h. clone ( ) , ( ) ) ) . collect ( ) ;
811
- let ( broadcaster_pubkeys, countersignatory_pubkeys) = channel_static_info. pubkeys ( holder) ;
812
- let mut txouts = Self :: do_build_outputs ( & self . keys , self . to_broadcaster_value_sat , self . to_countersignatory_value_sat , & htlcs, broadcaster_pubkeys, countersignatory_pubkeys, channel_static_info. contest_delay ( holder) , secp_ctx) ?;
799
+ let mut txouts = Self :: do_build_outputs ( & self . keys , self . to_broadcaster_value_sat , self . to_countersignatory_value_sat , & htlcs, holder, channel_static_info, secp_ctx) ?;
813
800
let outs = txouts. drain ( ..) . map ( |( out, ( s, extra) ) | ( out, ( s, extra. map ( |( p, _) | p) ) ) ) . collect ( ) ;
814
801
Ok ( outs)
815
802
}
816
803
817
- fn do_build_outputs < T : Copy , S : secp256k1:: Signing + secp256k1:: Verification > (
818
- keys : & TxCreationKeys ,
819
- to_broadcaster_value_sat : u64 ,
820
- to_countersignatory_value_sat : u64 ,
821
- htlcs : & Vec < ( HTLCOutputInCommitment , T ) > ,
822
- broadcaster_pubkeys : & ChannelPublicKeys , countersignatory_pubkeys : & ChannelPublicKeys , contest_delay : u16 , secp_ctx : & Secp256k1 < S > ) -> Result < Vec < ( TxOut , ( Script , Option < ( HTLCOutputInCommitment , T ) > ) ) > , ( ) > {
804
+ fn do_build_outputs < T : Copy , S : secp256k1:: Signing + secp256k1:: Verification > ( keys : & TxCreationKeys , to_broadcaster_value_sat : u64 , to_countersignatory_value_sat : u64 , htlcs : & Vec < ( HTLCOutputInCommitment , T ) > , holder : bool , channel_static_info : & ChannelStaticInfo , secp_ctx : & Secp256k1 < S > ) -> Result < Vec < ( TxOut , ( Script , Option < ( HTLCOutputInCommitment , T ) > ) ) > , ( ) > {
805
+ let ( broadcaster_pubkeys, countersignatory_pubkeys) = channel_static_info. pubkeys ( holder) ;
806
+ let contest_delay = channel_static_info. contest_delay ( holder) ;
807
+
823
808
let per_commitment_point = & keys. per_commitment_point ;
824
809
let to_broadcaster_delayed_pubkey = derive_public_key (
825
810
& secp_ctx,
@@ -928,6 +913,7 @@ impl CommitmentTransactionInfo {
928
913
( sighash, unsigned_tx)
929
914
}
930
915
916
+ // TODO(devrandom): remove this and subsume the HolderCommitmentTransaction signing functionality
931
917
pub ( crate ) fn to_holder_commitment_tx < T : secp256k1:: Signing + secp256k1:: Verification > ( & self , counterparty_sig : Signature , htlcs_with_sig : Vec < ( HTLCOutputInCommitment , Option < Signature > ) > , channel_static_info : & ChannelStaticInfo , secp_ctx : & Secp256k1 < T > ) -> HolderCommitmentTransaction {
932
918
let ( broadcaster_pubkeys, countersignatory_pubkeys) = channel_static_info. pubkeys ( true ) ;
933
919
let ( tx, _, _) = self . build ( true , channel_static_info, secp_ctx) . unwrap ( ) ;
0 commit comments