@@ -41,7 +41,7 @@ use bitcoin::{secp256k1, Sequence, Witness};
4141use crate :: io;
4242use core:: cmp;
4343use crate :: util:: transaction_utils:: sort_outputs;
44- use crate :: ln:: channel:: { INITIAL_COMMITMENT_NUMBER , ANCHOR_OUTPUT_VALUE_SATOSHI } ;
44+ use crate :: ln:: channel:: INITIAL_COMMITMENT_NUMBER ;
4545use core:: ops:: Deref ;
4646use crate :: chain;
4747use crate :: types:: features:: ChannelTypeFeatures ;
@@ -1136,7 +1136,7 @@ impl HolderCommitmentTransaction {
11361136 for _ in 0 ..htlcs. len ( ) {
11371137 counterparty_htlc_sigs. push ( dummy_sig) ;
11381138 }
1139- 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 ( ) , & signer, & secp_ctx, false ) ;
1139+ let inner = CommitmentTransaction :: new_with_auxiliary_htlc_data ( 0 , 0 , 0 , keys, 0 , htlcs, & channel_parameters. as_counterparty_broadcastable ( ) , & signer, & secp_ctx, false ) ;
11401140 htlcs. sort_by_key ( |htlc| htlc. 0 . transaction_output_index ) ;
11411141 HolderCommitmentTransaction {
11421142 inner,
@@ -1446,12 +1446,12 @@ impl CommitmentTransaction {
14461446 /// Only include HTLCs that are above the dust limit for the channel.
14471447 ///
14481448 /// This is not exported to bindings users due to the generic though we likely should expose a version without
1449- pub fn new_with_auxiliary_htlc_data < T , Signer : ChannelSigner > ( 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 , signer : & Signer , secp_ctx : & Secp256k1 < secp256k1:: All > , is_holder_tx : bool ) -> CommitmentTransaction {
1449+ pub fn new_with_auxiliary_htlc_data < T , Signer : ChannelSigner > ( 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 , signer : & Signer , secp_ctx : & Secp256k1 < secp256k1:: All > , is_holder_tx : bool ) -> CommitmentTransaction {
14501450 let to_broadcaster_value_sat = Amount :: from_sat ( to_broadcaster_value_sat) ;
14511451 let to_countersignatory_value_sat = Amount :: from_sat ( to_countersignatory_value_sat) ;
14521452
14531453 // Sort outputs and populate output indices while keeping track of the auxiliary data
1454- let ( outputs, htlcs) = Self :: internal_build_outputs ( & keys. per_commitment_point , to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, channel_parameters , & broadcaster_funding_key , & countersignatory_funding_key , signer, secp_ctx, is_holder_tx, commitment_number) . unwrap ( ) ;
1454+ let ( outputs, htlcs) = Self :: internal_build_outputs ( & keys. per_commitment_point , to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, signer, secp_ctx, is_holder_tx, commitment_number) . unwrap ( ) ;
14551455
14561456 let ( obscured_commitment_transaction_number, txins) = Self :: internal_build_inputs ( commitment_number, channel_parameters) ;
14571457 let transaction = Self :: make_transaction ( obscured_commitment_transaction_number, txins, outputs) ;
@@ -1480,11 +1480,11 @@ impl CommitmentTransaction {
14801480 self
14811481 }
14821482
1483- fn internal_rebuild_transaction < Signer : ChannelSigner > ( & self , per_commitment_point : & PublicKey , channel_parameters : & DirectedChannelTransactionParameters , broadcaster_funding_key : & PublicKey , countersignatory_funding_key : & PublicKey , signer : & Signer , secp_ctx : & Secp256k1 < secp256k1:: All > , is_holder_tx : bool ) -> Result < BuiltCommitmentTransaction , ( ) > {
1483+ fn internal_rebuild_transaction < Signer : ChannelSigner > ( & self , per_commitment_point : & PublicKey , channel_parameters : & DirectedChannelTransactionParameters , signer : & Signer , secp_ctx : & Secp256k1 < secp256k1:: All > , is_holder_tx : bool ) -> Result < BuiltCommitmentTransaction , ( ) > {
14841484 let ( obscured_commitment_transaction_number, txins) = Self :: internal_build_inputs ( self . commitment_number , channel_parameters) ;
14851485
14861486 let mut htlcs_with_aux = self . htlcs . iter ( ) . map ( |h| ( h. clone ( ) , ( ) ) ) . collect ( ) ;
1487- let ( outputs, _) = Self :: internal_build_outputs ( per_commitment_point, self . to_broadcaster_value_sat , self . to_countersignatory_value_sat , & mut htlcs_with_aux, channel_parameters , broadcaster_funding_key , countersignatory_funding_key , signer, secp_ctx, is_holder_tx, self . commitment_number ) ?;
1487+ let ( outputs, _) = Self :: internal_build_outputs ( per_commitment_point, self . to_broadcaster_value_sat , self . to_countersignatory_value_sat , & mut htlcs_with_aux, signer, secp_ctx, is_holder_tx, self . commitment_number ) ?;
14881488
14891489 let transaction = Self :: make_transaction ( obscured_commitment_transaction_number, txins, outputs) ;
14901490 let txid = transaction. compute_txid ( ) ;
@@ -1508,7 +1508,7 @@ impl CommitmentTransaction {
15081508 // - initial sorting of outputs / HTLCs in the constructor, in which case T is auxiliary data the
15091509 // caller needs to have sorted together with the HTLCs so it can keep track of the output index
15101510 // - building of a bitcoin transaction during a verify() call, in which case T is just ()
1511- fn internal_build_outputs < T , Signer : ChannelSigner > ( per_commitment_point : & PublicKey , 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 , signer : & Signer , secp_ctx : & Secp256k1 < secp256k1:: All > , is_holder_tx : bool , commitment_number : u64 ) -> Result < ( Vec < TxOut > , Vec < HTLCOutputInCommitment > ) , ( ) > {
1511+ fn internal_build_outputs < T , Signer : ChannelSigner > ( per_commitment_point : & PublicKey , to_broadcaster_value_sat : Amount , to_countersignatory_value_sat : Amount , htlcs_with_aux : & mut Vec < ( HTLCOutputInCommitment , T ) > , signer : & Signer , secp_ctx : & Secp256k1 < secp256k1:: All > , is_holder_tx : bool , commitment_number : u64 ) -> Result < ( Vec < TxOut > , Vec < HTLCOutputInCommitment > ) , ( ) > {
15121512 let mut txouts: Vec < ( TxOut , Option < & mut HTLCOutputInCommitment > ) > = Vec :: new ( ) ;
15131513
15141514 if to_countersignatory_value_sat > Amount :: ZERO {
@@ -1531,27 +1531,15 @@ impl CommitmentTransaction {
15311531 ) ) ;
15321532 }
15331533
1534- if channel_parameters. channel_type_features ( ) . supports_anchors_zero_fee_htlc_tx ( ) {
1535- if to_broadcaster_value_sat > Amount :: ZERO || !htlcs_with_aux. is_empty ( ) {
1536- let anchor_script = get_anchor_redeemscript ( broadcaster_funding_key) ;
1537- txouts. push ( (
1538- TxOut {
1539- script_pubkey : anchor_script. to_p2wsh ( ) ,
1540- value : Amount :: from_sat ( ANCHOR_OUTPUT_VALUE_SATOSHI ) ,
1541- } ,
1542- None ,
1543- ) ) ;
1534+ if to_broadcaster_value_sat > Amount :: ZERO || !htlcs_with_aux. is_empty ( ) {
1535+ if let Some ( txout) = signer. get_broadcaster_anchor_txout ( is_holder_tx) {
1536+ txouts. push ( ( txout, None ) ) ;
15441537 }
1538+ }
15451539
1546- if to_countersignatory_value_sat > Amount :: ZERO || !htlcs_with_aux. is_empty ( ) {
1547- let anchor_script = get_anchor_redeemscript ( countersignatory_funding_key) ;
1548- txouts. push ( (
1549- TxOut {
1550- script_pubkey : anchor_script. to_p2wsh ( ) ,
1551- value : Amount :: from_sat ( ANCHOR_OUTPUT_VALUE_SATOSHI ) ,
1552- } ,
1553- None ,
1554- ) ) ;
1540+ if to_countersignatory_value_sat > Amount :: ZERO || !htlcs_with_aux. is_empty ( ) {
1541+ if let Some ( txout) = signer. get_counterparty_anchor_txout ( is_holder_tx) {
1542+ txouts. push ( ( txout, None ) ) ;
15551543 }
15561544 }
15571545
@@ -1667,14 +1655,10 @@ impl CommitmentTransaction {
16671655 ///
16681656 /// An external validating signer must call this method before signing
16691657 /// or using the built transaction.
1670- pub fn verify < Signer : ChannelSigner > ( & self , channel_parameters : & DirectedChannelTransactionParameters , broadcaster_keys : & ChannelPublicKeys , countersignatory_keys : & ChannelPublicKeys , secp_ctx : & Secp256k1 < secp256k1:: All > , signer : & Signer , is_holder_tx : bool ) -> Result < TrustedCommitmentTransaction , ( ) > {
1658+ pub fn verify < Signer : ChannelSigner > ( & self , channel_parameters : & DirectedChannelTransactionParameters , secp_ctx : & Secp256k1 < secp256k1:: All > , signer : & Signer , is_holder_tx : bool ) -> Result < TrustedCommitmentTransaction , ( ) > {
16711659 // This is the only field of the key cache that we trust
16721660 let per_commitment_point = self . keys . per_commitment_point ;
1673- let keys = TxCreationKeys :: from_channel_static_keys ( & per_commitment_point, broadcaster_keys, countersignatory_keys, secp_ctx) ;
1674- if keys != self . keys {
1675- return Err ( ( ) ) ;
1676- }
1677- let tx = self . internal_rebuild_transaction ( & keys. per_commitment_point , channel_parameters, & broadcaster_keys. funding_pubkey , & countersignatory_keys. funding_pubkey , signer, secp_ctx, is_holder_tx) ?;
1661+ let tx = self . internal_rebuild_transaction ( & per_commitment_point, channel_parameters, signer, secp_ctx, is_holder_tx) ?;
16781662 if self . built . transaction != tx. transaction || self . built . txid != tx. txid {
16791663 return Err ( ( ) ) ;
16801664 }
@@ -1876,8 +1860,6 @@ mod tests {
18761860
18771861 struct TestCommitmentTxBuilder {
18781862 commitment_number : u64 ,
1879- holder_funding_pubkey : PublicKey ,
1880- counterparty_funding_pubkey : PublicKey ,
18811863 keys : TxCreationKeys ,
18821864 feerate_per_kw : u32 ,
18831865 htlcs_with_aux : Vec < ( HTLCOutputInCommitment , ( ) ) > ,
@@ -1913,8 +1895,6 @@ mod tests {
19131895
19141896 Self {
19151897 commitment_number : 0 ,
1916- holder_funding_pubkey : holder_pubkeys. funding_pubkey ,
1917- counterparty_funding_pubkey : counterparty_pubkeys. funding_pubkey ,
19181898 keys,
19191899 feerate_per_kw : 1 ,
19201900 htlcs_with_aux,
@@ -1930,8 +1910,6 @@ mod tests {
19301910 self . commitment_number ,
19311911 to_broadcaster_sats,
19321912 to_countersignatory_sats,
1933- self . holder_funding_pubkey . clone ( ) ,
1934- self . counterparty_funding_pubkey . clone ( ) ,
19351913 self . keys . clone ( ) , self . feerate_per_kw ,
19361914 & mut self . htlcs_with_aux , & self . channel_parameters . as_holder_broadcastable ( ) ,
19371915 & self . signer ,
0 commit comments