@@ -1208,7 +1208,7 @@ impl HolderCommitmentTransaction {
12081208 for _ in 0 ..htlcs. len ( ) {
12091209 counterparty_htlc_sigs. push ( dummy_sig) ;
12101210 }
1211- let inner = CommitmentTransaction :: new_with_auxiliary_htlc_data ( 0 , 0 , 0 , dummy_key . clone ( ) , dummy_key . clone ( ) , keys, 0 , htlcs, & channel_parameters. as_counterparty_broadcastable ( ) ) ;
1211+ let inner = CommitmentTransaction :: new_with_auxiliary_htlc_data ( 0 , 0 , 0 , keys, 0 , htlcs, & channel_parameters. as_counterparty_broadcastable ( ) ) ;
12121212 htlcs. sort_by_key ( |htlc| htlc. 0 . transaction_output_index ) ;
12131213 HolderCommitmentTransaction {
12141214 inner,
@@ -1518,12 +1518,12 @@ impl CommitmentTransaction {
15181518 /// Only include HTLCs that are above the dust limit for the channel.
15191519 ///
15201520 /// This is not exported to bindings users due to the generic though we likely should expose a version without
1521- pub fn new_with_auxiliary_htlc_data < T > ( commitment_number : u64 , to_broadcaster_value_sat : u64 , to_countersignatory_value_sat : u64 , broadcaster_funding_key : PublicKey , countersignatory_funding_key : PublicKey , keys : TxCreationKeys , feerate_per_kw : u32 , htlcs_with_aux : & mut Vec < ( HTLCOutputInCommitment , T ) > , channel_parameters : & DirectedChannelTransactionParameters ) -> CommitmentTransaction {
1521+ pub fn new_with_auxiliary_htlc_data < T > ( commitment_number : u64 , to_broadcaster_value_sat : u64 , to_countersignatory_value_sat : u64 , keys : TxCreationKeys , feerate_per_kw : u32 , htlcs_with_aux : & mut Vec < ( HTLCOutputInCommitment , T ) > , channel_parameters : & DirectedChannelTransactionParameters ) -> CommitmentTransaction {
15221522 let to_broadcaster_value_sat = Amount :: from_sat ( to_broadcaster_value_sat) ;
15231523 let to_countersignatory_value_sat = Amount :: from_sat ( to_countersignatory_value_sat) ;
15241524
15251525 // Sort outputs and populate output indices while keeping track of the auxiliary data
1526- let ( outputs, htlcs) = Self :: internal_build_outputs ( & keys, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, channel_parameters, & broadcaster_funding_key , & countersignatory_funding_key ) . unwrap ( ) ;
1526+ let ( outputs, htlcs) = Self :: internal_build_outputs ( & keys, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, channel_parameters) . unwrap ( ) ;
15271527
15281528 let ( obscured_commitment_transaction_number, txins) = Self :: internal_build_inputs ( commitment_number, channel_parameters) ;
15291529 let transaction = Self :: make_transaction ( obscured_commitment_transaction_number, txins, outputs) ;
@@ -1552,11 +1552,11 @@ impl CommitmentTransaction {
15521552 self
15531553 }
15541554
1555- fn internal_rebuild_transaction ( & self , keys : & TxCreationKeys , channel_parameters : & DirectedChannelTransactionParameters , broadcaster_funding_key : & PublicKey , countersignatory_funding_key : & PublicKey ) -> Result < BuiltCommitmentTransaction , ( ) > {
1555+ fn internal_rebuild_transaction ( & self , keys : & TxCreationKeys , channel_parameters : & DirectedChannelTransactionParameters ) -> Result < BuiltCommitmentTransaction , ( ) > {
15561556 let ( obscured_commitment_transaction_number, txins) = Self :: internal_build_inputs ( self . commitment_number , channel_parameters) ;
15571557
15581558 let mut htlcs_with_aux = self . htlcs . iter ( ) . map ( |h| ( h. clone ( ) , ( ) ) ) . collect ( ) ;
1559- let ( outputs, _) = Self :: internal_build_outputs ( keys, self . to_broadcaster_value_sat , self . to_countersignatory_value_sat , & mut htlcs_with_aux, channel_parameters, broadcaster_funding_key , countersignatory_funding_key ) ?;
1559+ let ( outputs, _) = Self :: internal_build_outputs ( keys, self . to_broadcaster_value_sat , self . to_countersignatory_value_sat , & mut htlcs_with_aux, channel_parameters) ?;
15601560
15611561 let transaction = Self :: make_transaction ( obscured_commitment_transaction_number, txins, outputs) ;
15621562 let txid = transaction. compute_txid ( ) ;
@@ -1580,17 +1580,20 @@ impl CommitmentTransaction {
15801580 // - initial sorting of outputs / HTLCs in the constructor, in which case T is auxiliary data the
15811581 // caller needs to have sorted together with the HTLCs so it can keep track of the output index
15821582 // - building of a bitcoin transaction during a verify() call, in which case T is just ()
1583- fn internal_build_outputs < T > ( keys : & TxCreationKeys , to_broadcaster_value_sat : Amount , to_countersignatory_value_sat : Amount , htlcs_with_aux : & mut Vec < ( HTLCOutputInCommitment , T ) > , channel_parameters : & DirectedChannelTransactionParameters , broadcaster_funding_key : & PublicKey , countersignatory_funding_key : & PublicKey ) -> Result < ( Vec < TxOut > , Vec < HTLCOutputInCommitment > ) , ( ) > {
1584- let countersignatory_pubkeys = channel_parameters. countersignatory_pubkeys ( ) ;
1583+ fn internal_build_outputs < T > ( keys : & TxCreationKeys , to_broadcaster_value_sat : Amount , to_countersignatory_value_sat : Amount , htlcs_with_aux : & mut Vec < ( HTLCOutputInCommitment , T ) > , channel_parameters : & DirectedChannelTransactionParameters ) -> Result < ( Vec < TxOut > , Vec < HTLCOutputInCommitment > ) , ( ) > {
1584+ let countersignatory_payment_point = & channel_parameters. countersignatory_pubkeys ( ) . payment_point ;
1585+ let countersignatory_funding_key = & channel_parameters. countersignatory_pubkeys ( ) . funding_pubkey ;
1586+ let broadcaster_funding_key = & channel_parameters. broadcaster_pubkeys ( ) . funding_pubkey ;
1587+ let channel_type = channel_parameters. channel_type_features ( ) ;
15851588 let contest_delay = channel_parameters. contest_delay ( ) ;
15861589
15871590 let mut txouts: Vec < ( TxOut , Option < & mut HTLCOutputInCommitment > ) > = Vec :: new ( ) ;
15881591
15891592 if to_countersignatory_value_sat > Amount :: ZERO {
1590- let script = if channel_parameters . channel_type_features ( ) . supports_anchors_zero_fee_htlc_tx ( ) {
1591- get_to_countersigner_keyed_anchor_redeemscript ( & countersignatory_pubkeys . payment_point ) . to_p2wsh ( )
1593+ let script = if channel_type . supports_anchors_zero_fee_htlc_tx ( ) {
1594+ get_to_countersigner_keyed_anchor_redeemscript ( countersignatory_payment_point ) . to_p2wsh ( )
15921595 } else {
1593- ScriptBuf :: new_p2wpkh ( & Hash160 :: hash ( & countersignatory_pubkeys . payment_point . serialize ( ) ) . into ( ) )
1596+ ScriptBuf :: new_p2wpkh ( & Hash160 :: hash ( & countersignatory_payment_point . serialize ( ) ) . into ( ) )
15941597 } ;
15951598 txouts. push ( (
15961599 TxOut {
@@ -1616,7 +1619,7 @@ impl CommitmentTransaction {
16161619 ) ) ;
16171620 }
16181621
1619- if channel_parameters . channel_type_features ( ) . supports_anchors_zero_fee_htlc_tx ( ) {
1622+ if channel_type . supports_anchors_zero_fee_htlc_tx ( ) {
16201623 if to_broadcaster_value_sat > Amount :: ZERO || !htlcs_with_aux. is_empty ( ) {
16211624 let anchor_script = get_keyed_anchor_redeemscript ( broadcaster_funding_key) ;
16221625 txouts. push ( (
@@ -1642,7 +1645,7 @@ impl CommitmentTransaction {
16421645
16431646 let mut htlcs = Vec :: with_capacity ( htlcs_with_aux. len ( ) ) ;
16441647 for ( htlc, _) in htlcs_with_aux {
1645- let script = get_htlc_redeemscript ( & htlc, & channel_parameters . channel_type_features ( ) , & keys) ;
1648+ let script = get_htlc_redeemscript ( htlc, channel_type , keys) ;
16461649 let txout = TxOut {
16471650 script_pubkey : script. to_p2wsh ( ) ,
16481651 value : htlc. to_bitcoin_amount ( ) ,
@@ -1753,14 +1756,14 @@ impl CommitmentTransaction {
17531756 ///
17541757 /// An external validating signer must call this method before signing
17551758 /// or using the built transaction.
1756- pub fn verify < T : secp256k1:: Signing + secp256k1:: Verification > ( & self , channel_parameters : & DirectedChannelTransactionParameters , broadcaster_keys : & ChannelPublicKeys , countersignatory_keys : & ChannelPublicKeys , secp_ctx : & Secp256k1 < T > ) -> Result < TrustedCommitmentTransaction , ( ) > {
1759+ pub fn verify < T : secp256k1:: Signing + secp256k1:: Verification > ( & self , channel_parameters : & DirectedChannelTransactionParameters , secp_ctx : & Secp256k1 < T > ) -> Result < TrustedCommitmentTransaction , ( ) > {
17571760 // This is the only field of the key cache that we trust
1758- let per_commitment_point = self . keys . per_commitment_point ;
1759- let keys = TxCreationKeys :: from_channel_static_keys ( & per_commitment_point, broadcaster_keys , countersignatory_keys , secp_ctx) ;
1761+ let per_commitment_point = & self . keys . per_commitment_point ;
1762+ let keys = TxCreationKeys :: from_channel_static_keys ( per_commitment_point, channel_parameters . broadcaster_pubkeys ( ) , channel_parameters . countersignatory_pubkeys ( ) , secp_ctx) ;
17601763 if keys != self . keys {
17611764 return Err ( ( ) ) ;
17621765 }
1763- let tx = self . internal_rebuild_transaction ( & keys, channel_parameters, & broadcaster_keys . funding_pubkey , & countersignatory_keys . funding_pubkey ) ?;
1766+ let tx = self . internal_rebuild_transaction ( & keys, channel_parameters) ?;
17641767 if self . built . transaction != tx. transaction || self . built . txid != tx. txid {
17651768 return Err ( ( ) ) ;
17661769 }
@@ -1983,8 +1986,6 @@ mod tests {
19831986
19841987 struct TestCommitmentTxBuilder {
19851988 commitment_number : u64 ,
1986- holder_funding_pubkey : PublicKey ,
1987- counterparty_funding_pubkey : PublicKey ,
19881989 keys : TxCreationKeys ,
19891990 feerate_per_kw : u32 ,
19901991 htlcs_with_aux : Vec < ( HTLCOutputInCommitment , ( ) ) > ,
@@ -2023,8 +2024,6 @@ mod tests {
20232024
20242025 Self {
20252026 commitment_number : 0 ,
2026- holder_funding_pubkey : holder_pubkeys. funding_pubkey ,
2027- counterparty_funding_pubkey : counterparty_pubkeys. funding_pubkey ,
20282027 keys,
20292028 feerate_per_kw : 1 ,
20302029 htlcs_with_aux,
@@ -2036,8 +2035,6 @@ mod tests {
20362035 fn build ( & mut self , to_broadcaster_sats : u64 , to_countersignatory_sats : u64 ) -> CommitmentTransaction {
20372036 CommitmentTransaction :: new_with_auxiliary_htlc_data (
20382037 self . commitment_number , to_broadcaster_sats, to_countersignatory_sats,
2039- self . holder_funding_pubkey . clone ( ) ,
2040- self . counterparty_funding_pubkey . clone ( ) ,
20412038 self . keys . clone ( ) , self . feerate_per_kw ,
20422039 & mut self . htlcs_with_aux , & self . channel_parameters . as_holder_broadcastable ( )
20432040 )
0 commit comments