@@ -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,
@@ -1452,12 +1452,12 @@ impl CommitmentTransaction {
14521452 /// Only include HTLCs that are above the dust limit for the channel.
14531453 ///
14541454 /// This is not exported to bindings users due to the generic though we likely should expose a version without
1455- 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 {
1455+ 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 {
14561456 let to_broadcaster_value_sat = Amount :: from_sat ( to_broadcaster_value_sat) ;
14571457 let to_countersignatory_value_sat = Amount :: from_sat ( to_countersignatory_value_sat) ;
14581458
14591459 // Sort outputs and populate output indices while keeping track of the auxiliary data
1460- 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 ( ) ;
1460+ 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 ( ) ;
14611461
14621462 let ( obscured_commitment_transaction_number, txins) = Self :: internal_build_inputs ( commitment_number, channel_parameters) ;
14631463 let transaction = Self :: make_transaction ( obscured_commitment_transaction_number, txins, outputs) ;
@@ -1486,11 +1486,11 @@ impl CommitmentTransaction {
14861486 self
14871487 }
14881488
1489- 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 , ( ) > {
1489+ 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 , ( ) > {
14901490 let ( obscured_commitment_transaction_number, txins) = Self :: internal_build_inputs ( self . commitment_number , channel_parameters) ;
14911491
14921492 let mut htlcs_with_aux = self . htlcs . iter ( ) . map ( |h| ( h. clone ( ) , ( ) ) ) . collect ( ) ;
1493- 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 ) ?;
1493+ 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 ) ?;
14941494
14951495 let transaction = Self :: make_transaction ( obscured_commitment_transaction_number, txins, outputs) ;
14961496 let txid = transaction. compute_txid ( ) ;
@@ -1514,7 +1514,7 @@ impl CommitmentTransaction {
15141514 // - initial sorting of outputs / HTLCs in the constructor, in which case T is auxiliary data the
15151515 // caller needs to have sorted together with the HTLCs so it can keep track of the output index
15161516 // - building of a bitcoin transaction during a verify() call, in which case T is just ()
1517- 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 > ) , ( ) > {
1517+ 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 > ) , ( ) > {
15181518 let mut txouts: Vec < ( TxOut , Option < & mut HTLCOutputInCommitment > ) > = Vec :: new ( ) ;
15191519
15201520 if to_countersignatory_value_sat > Amount :: ZERO {
@@ -1537,27 +1537,15 @@ impl CommitmentTransaction {
15371537 ) ) ;
15381538 }
15391539
1540- if channel_parameters. channel_type_features ( ) . supports_anchors_zero_fee_htlc_tx ( ) {
1541- if to_broadcaster_value_sat > Amount :: ZERO || !htlcs_with_aux. is_empty ( ) {
1542- let anchor_script = get_anchor_redeemscript ( broadcaster_funding_key) ;
1543- txouts. push ( (
1544- TxOut {
1545- script_pubkey : anchor_script. to_p2wsh ( ) ,
1546- value : Amount :: from_sat ( ANCHOR_OUTPUT_VALUE_SATOSHI ) ,
1547- } ,
1548- None ,
1549- ) ) ;
1540+ if to_broadcaster_value_sat > Amount :: ZERO || !htlcs_with_aux. is_empty ( ) {
1541+ if let Some ( txout) = signer. get_anchor_txout ( is_holder_tx, true ) {
1542+ txouts. push ( ( txout, None ) ) ;
15501543 }
1544+ }
15511545
1552- if to_countersignatory_value_sat > Amount :: ZERO || !htlcs_with_aux. is_empty ( ) {
1553- let anchor_script = get_anchor_redeemscript ( countersignatory_funding_key) ;
1554- txouts. push ( (
1555- TxOut {
1556- script_pubkey : anchor_script. to_p2wsh ( ) ,
1557- value : Amount :: from_sat ( ANCHOR_OUTPUT_VALUE_SATOSHI ) ,
1558- } ,
1559- None ,
1560- ) ) ;
1546+ if to_countersignatory_value_sat > Amount :: ZERO || !htlcs_with_aux. is_empty ( ) {
1547+ if let Some ( txout) = signer. get_anchor_txout ( is_holder_tx, false ) {
1548+ txouts. push ( ( txout, None ) ) ;
15611549 }
15621550 }
15631551
@@ -1673,14 +1661,10 @@ impl CommitmentTransaction {
16731661 ///
16741662 /// An external validating signer must call this method before signing
16751663 /// or using the built transaction.
1676- 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 , ( ) > {
1664+ pub fn verify < Signer : ChannelSigner > ( & self , channel_parameters : & DirectedChannelTransactionParameters , secp_ctx : & Secp256k1 < secp256k1:: All > , signer : & Signer , is_holder_tx : bool ) -> Result < TrustedCommitmentTransaction , ( ) > {
16771665 // This is the only field of the key cache that we trust
16781666 let per_commitment_point = self . keys . per_commitment_point ;
1679- let keys = TxCreationKeys :: from_channel_static_keys ( & per_commitment_point, broadcaster_keys, countersignatory_keys, secp_ctx) ;
1680- if keys != self . keys {
1681- return Err ( ( ) ) ;
1682- }
1683- 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) ?;
1667+ let tx = self . internal_rebuild_transaction ( & per_commitment_point, channel_parameters, signer, secp_ctx, is_holder_tx) ?;
16841668 if self . built . transaction != tx. transaction || self . built . txid != tx. txid {
16851669 return Err ( ( ) ) ;
16861670 }
@@ -1882,8 +1866,6 @@ mod tests {
18821866
18831867 struct TestCommitmentTxBuilder {
18841868 commitment_number : u64 ,
1885- holder_funding_pubkey : PublicKey ,
1886- counterparty_funding_pubkey : PublicKey ,
18871869 keys : TxCreationKeys ,
18881870 feerate_per_kw : u32 ,
18891871 htlcs_with_aux : Vec < ( HTLCOutputInCommitment , ( ) ) > ,
@@ -1919,8 +1901,6 @@ mod tests {
19191901
19201902 Self {
19211903 commitment_number : 0 ,
1922- holder_funding_pubkey : holder_pubkeys. funding_pubkey ,
1923- counterparty_funding_pubkey : counterparty_pubkeys. funding_pubkey ,
19241904 keys,
19251905 feerate_per_kw : 1 ,
19261906 htlcs_with_aux,
@@ -1936,8 +1916,6 @@ mod tests {
19361916 self . commitment_number ,
19371917 to_broadcaster_sats,
19381918 to_countersignatory_sats,
1939- self . holder_funding_pubkey . clone ( ) ,
1940- self . counterparty_funding_pubkey . clone ( ) ,
19411919 self . keys . clone ( ) , self . feerate_per_kw ,
19421920 & mut self . htlcs_with_aux , & self . channel_parameters . as_holder_broadcastable ( ) ,
19431921 & self . signer ,
0 commit comments