@@ -1199,7 +1199,7 @@ impl HolderCommitmentTransaction {
11991199 for _ in 0 ..htlcs. len ( ) {
12001200 counterparty_htlc_sigs. push ( dummy_sig) ;
12011201 }
1202- 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 ( ) ) ;
1202+ let inner = CommitmentTransaction :: new_with_auxiliary_htlc_data ( 0 , 0 , 0 , keys, 0 , htlcs, & channel_parameters. as_counterparty_broadcastable ( ) ) ;
12031203 htlcs. sort_by_key ( |htlc| htlc. 0 . transaction_output_index ) ;
12041204 HolderCommitmentTransaction {
12051205 inner,
@@ -1509,12 +1509,12 @@ impl CommitmentTransaction {
15091509 /// Only include HTLCs that are above the dust limit for the channel.
15101510 ///
15111511 /// This is not exported to bindings users due to the generic though we likely should expose a version without
1512- 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 {
1512+ 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 {
15131513 let to_broadcaster_value_sat = Amount :: from_sat ( to_broadcaster_value_sat) ;
15141514 let to_countersignatory_value_sat = Amount :: from_sat ( to_countersignatory_value_sat) ;
15151515
15161516 // Sort outputs and populate output indices while keeping track of the auxiliary data
1517- 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 ( ) ;
1517+ let ( outputs, htlcs) = Self :: internal_build_outputs ( & keys, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, channel_parameters) . unwrap ( ) ;
15181518
15191519 let ( obscured_commitment_transaction_number, txins) = Self :: internal_build_inputs ( commitment_number, channel_parameters) ;
15201520 let transaction = Self :: make_transaction ( obscured_commitment_transaction_number, txins, outputs) ;
@@ -1543,11 +1543,11 @@ impl CommitmentTransaction {
15431543 self
15441544 }
15451545
1546- fn internal_rebuild_transaction ( & self , keys : & TxCreationKeys , channel_parameters : & DirectedChannelTransactionParameters , broadcaster_funding_key : & PublicKey , countersignatory_funding_key : & PublicKey ) -> Result < BuiltCommitmentTransaction , ( ) > {
1546+ fn internal_rebuild_transaction ( & self , keys : & TxCreationKeys , channel_parameters : & DirectedChannelTransactionParameters ) -> Result < BuiltCommitmentTransaction , ( ) > {
15471547 let ( obscured_commitment_transaction_number, txins) = Self :: internal_build_inputs ( self . commitment_number , channel_parameters) ;
15481548
15491549 let mut htlcs_with_aux = self . htlcs . iter ( ) . map ( |h| ( h. clone ( ) , ( ) ) ) . collect ( ) ;
1550- 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 ) ?;
1550+ let ( outputs, _) = Self :: internal_build_outputs ( keys, self . to_broadcaster_value_sat , self . to_countersignatory_value_sat , & mut htlcs_with_aux, channel_parameters) ?;
15511551
15521552 let transaction = Self :: make_transaction ( obscured_commitment_transaction_number, txins, outputs) ;
15531553 let txid = transaction. compute_txid ( ) ;
@@ -1571,17 +1571,20 @@ impl CommitmentTransaction {
15711571 // - initial sorting of outputs / HTLCs in the constructor, in which case T is auxiliary data the
15721572 // caller needs to have sorted together with the HTLCs so it can keep track of the output index
15731573 // - building of a bitcoin transaction during a verify() call, in which case T is just ()
1574- 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 > ) , ( ) > {
1575- let countersignatory_pubkeys = channel_parameters. countersignatory_pubkeys ( ) ;
1574+ 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 > ) , ( ) > {
1575+ let countersignatory_payment_point = & channel_parameters. countersignatory_pubkeys ( ) . payment_point ;
1576+ let countersignatory_funding_key = & channel_parameters. countersignatory_pubkeys ( ) . funding_pubkey ;
1577+ let broadcaster_funding_key = & channel_parameters. broadcaster_pubkeys ( ) . funding_pubkey ;
1578+ let channel_type = channel_parameters. channel_type_features ( ) ;
15761579 let contest_delay = channel_parameters. contest_delay ( ) ;
15771580
15781581 let mut txouts: Vec < ( TxOut , Option < & mut HTLCOutputInCommitment > ) > = Vec :: new ( ) ;
15791582
15801583 if to_countersignatory_value_sat > Amount :: ZERO {
1581- let script = if channel_parameters . channel_type_features ( ) . supports_anchors_zero_fee_htlc_tx ( ) {
1582- get_to_countersignatory_with_anchors_redeemscript ( & countersignatory_pubkeys . payment_point ) . to_p2wsh ( )
1584+ let script = if channel_type . supports_anchors_zero_fee_htlc_tx ( ) {
1585+ get_to_countersignatory_with_anchors_redeemscript ( countersignatory_payment_point ) . to_p2wsh ( )
15831586 } else {
1584- ScriptBuf :: new_p2wpkh ( & Hash160 :: hash ( & countersignatory_pubkeys . payment_point . serialize ( ) ) . into ( ) )
1587+ ScriptBuf :: new_p2wpkh ( & Hash160 :: hash ( & countersignatory_payment_point . serialize ( ) ) . into ( ) )
15851588 } ;
15861589 txouts. push ( (
15871590 TxOut {
@@ -1607,7 +1610,7 @@ impl CommitmentTransaction {
16071610 ) ) ;
16081611 }
16091612
1610- if channel_parameters . channel_type_features ( ) . supports_anchors_zero_fee_htlc_tx ( ) {
1613+ if channel_type . supports_anchors_zero_fee_htlc_tx ( ) {
16111614 if to_broadcaster_value_sat > Amount :: ZERO || !htlcs_with_aux. is_empty ( ) {
16121615 let anchor_script = get_anchor_redeemscript ( broadcaster_funding_key) ;
16131616 txouts. push ( (
@@ -1633,7 +1636,7 @@ impl CommitmentTransaction {
16331636
16341637 let mut htlcs = Vec :: with_capacity ( htlcs_with_aux. len ( ) ) ;
16351638 for ( htlc, _) in htlcs_with_aux {
1636- let script = get_htlc_redeemscript ( & htlc, & channel_parameters . channel_type_features ( ) , & keys) ;
1639+ let script = get_htlc_redeemscript ( htlc, channel_type , keys) ;
16371640 let txout = TxOut {
16381641 script_pubkey : script. to_p2wsh ( ) ,
16391642 value : htlc. to_bitcoin_amount ( ) ,
@@ -1744,14 +1747,14 @@ impl CommitmentTransaction {
17441747 ///
17451748 /// An external validating signer must call this method before signing
17461749 /// or using the built transaction.
1747- pub fn verify < T : secp256k1:: Signing + secp256k1:: Verification > ( & self , channel_parameters : & DirectedChannelTransactionParameters , broadcaster_keys : & ChannelPublicKeys , countersignatory_keys : & ChannelPublicKeys , secp_ctx : & Secp256k1 < T > ) -> Result < TrustedCommitmentTransaction , ( ) > {
1750+ pub fn verify < T : secp256k1:: Signing + secp256k1:: Verification > ( & self , channel_parameters : & DirectedChannelTransactionParameters , secp_ctx : & Secp256k1 < T > ) -> Result < TrustedCommitmentTransaction , ( ) > {
17481751 // This is the only field of the key cache that we trust
1749- let per_commitment_point = self . keys . per_commitment_point ;
1750- let keys = TxCreationKeys :: from_channel_static_keys ( & per_commitment_point, broadcaster_keys , countersignatory_keys , secp_ctx) ;
1752+ let per_commitment_point = & self . keys . per_commitment_point ;
1753+ let keys = TxCreationKeys :: from_channel_static_keys ( per_commitment_point, channel_parameters . broadcaster_pubkeys ( ) , channel_parameters . countersignatory_pubkeys ( ) , secp_ctx) ;
17511754 if keys != self . keys {
17521755 return Err ( ( ) ) ;
17531756 }
1754- let tx = self . internal_rebuild_transaction ( & keys, channel_parameters, & broadcaster_keys . funding_pubkey , & countersignatory_keys . funding_pubkey ) ?;
1757+ let tx = self . internal_rebuild_transaction ( & keys, channel_parameters) ?;
17551758 if self . built . transaction != tx. transaction || self . built . txid != tx. txid {
17561759 return Err ( ( ) ) ;
17571760 }
@@ -1974,8 +1977,6 @@ mod tests {
19741977
19751978 struct TestCommitmentTxBuilder {
19761979 commitment_number : u64 ,
1977- holder_funding_pubkey : PublicKey ,
1978- counterparty_funding_pubkey : PublicKey ,
19791980 keys : TxCreationKeys ,
19801981 feerate_per_kw : u32 ,
19811982 htlcs_with_aux : Vec < ( HTLCOutputInCommitment , ( ) ) > ,
@@ -2014,8 +2015,6 @@ mod tests {
20142015
20152016 Self {
20162017 commitment_number : 0 ,
2017- holder_funding_pubkey : holder_pubkeys. funding_pubkey ,
2018- counterparty_funding_pubkey : counterparty_pubkeys. funding_pubkey ,
20192018 keys,
20202019 feerate_per_kw : 1 ,
20212020 htlcs_with_aux,
@@ -2027,8 +2026,6 @@ mod tests {
20272026 fn build ( & mut self , to_broadcaster_sats : u64 , to_countersignatory_sats : u64 ) -> CommitmentTransaction {
20282027 CommitmentTransaction :: new_with_auxiliary_htlc_data (
20292028 self . commitment_number , to_broadcaster_sats, to_countersignatory_sats,
2030- self . holder_funding_pubkey . clone ( ) ,
2031- self . counterparty_funding_pubkey . clone ( ) ,
20322029 self . keys . clone ( ) , self . feerate_per_kw ,
20332030 & mut self . htlcs_with_aux , & self . channel_parameters . as_holder_broadcastable ( )
20342031 )
0 commit comments