@@ -1145,7 +1145,7 @@ impl_writeable_tlv_based!(HolderCommitmentTransaction, {
11451145
11461146impl HolderCommitmentTransaction {
11471147 #[ cfg( test) ]
1148- pub fn dummy ( channel_value_satoshis : u64 , htlcs : & mut Vec < ( HTLCOutputInCommitment , ( ) ) > ) -> Self {
1148+ pub fn dummy ( channel_value_satoshis : u64 , nondust_htlcs : & mut Vec < HTLCOutputInCommitment > ) -> Self {
11491149 let secp_ctx = Secp256k1 :: new ( ) ;
11501150 let dummy_key = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
11511151 let dummy_sig = sign ( & secp_ctx, & secp256k1:: Message :: from_digest ( [ 42 ; 32 ] ) , & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
@@ -1168,11 +1168,11 @@ impl HolderCommitmentTransaction {
11681168 channel_value_satoshis,
11691169 } ;
11701170 let mut counterparty_htlc_sigs = Vec :: new ( ) ;
1171- for _ in 0 ..htlcs . len ( ) {
1171+ for _ in 0 ..nondust_htlcs . len ( ) {
11721172 counterparty_htlc_sigs. push ( dummy_sig) ;
11731173 }
1174- let inner = CommitmentTransaction :: new_with_auxiliary_htlc_data ( 0 , & dummy_key. clone ( ) , 0 , 0 , 0 , htlcs , & channel_parameters. as_counterparty_broadcastable ( ) , & secp_ctx) ;
1175- htlcs . sort_by_key ( |htlc| htlc. 0 . transaction_output_index ) ;
1174+ let inner = CommitmentTransaction :: new ( 0 , & dummy_key. clone ( ) , 0 , 0 , 0 , nondust_htlcs . iter_mut ( ) . collect ( ) , & channel_parameters. as_counterparty_broadcastable ( ) , & secp_ctx) ;
1175+ nondust_htlcs . sort_by_key ( |htlc| htlc. transaction_output_index ) ;
11761176 HolderCommitmentTransaction {
11771177 inner,
11781178 counterparty_sig : dummy_sig,
@@ -1471,23 +1471,16 @@ impl Readable for CommitmentTransaction {
14711471}
14721472
14731473impl CommitmentTransaction {
1474- /// Construct an object of the class while assigning transaction output indices to HTLCs.
1474+ /// Construct an object of the class while assigning transaction output indices to HTLCs in `nondust_htlcs` .
14751475 ///
1476- /// Populates HTLCOutputInCommitment.transaction_output_index in htlcs_with_aux.
1477- ///
1478- /// The generic T allows the caller to match the HTLC output index with auxiliary data.
1479- /// This auxiliary data is not stored in this object.
1480- ///
1481- /// Only include HTLCs that are above the dust limit for the channel.
1482- ///
1483- /// This is not exported to bindings users due to the generic though we likely should expose a version without
1484- pub fn new_with_auxiliary_htlc_data < T > ( commitment_number : u64 , per_commitment_point : & PublicKey , to_broadcaster_value_sat : u64 , to_countersignatory_value_sat : u64 , feerate_per_kw : u32 , htlcs_with_aux : & mut Vec < ( HTLCOutputInCommitment , T ) > , channel_parameters : & DirectedChannelTransactionParameters , secp_ctx : & Secp256k1 < secp256k1:: All > ) -> CommitmentTransaction {
1476+ /// `nondust_htlcs` should only include HTLCs that are above the dust limit for the channel.
1477+ pub fn new ( commitment_number : u64 , per_commitment_point : & PublicKey , to_broadcaster_value_sat : u64 , to_countersignatory_value_sat : u64 , feerate_per_kw : u32 , nondust_htlcs : Vec < & mut HTLCOutputInCommitment > , channel_parameters : & DirectedChannelTransactionParameters , secp_ctx : & Secp256k1 < secp256k1:: All > ) -> CommitmentTransaction {
14851478 let to_broadcaster_value_sat = Amount :: from_sat ( to_broadcaster_value_sat) ;
14861479 let to_countersignatory_value_sat = Amount :: from_sat ( to_countersignatory_value_sat) ;
14871480 let keys = TxCreationKeys :: from_channel_static_keys ( per_commitment_point, channel_parameters. broadcaster_pubkeys ( ) , channel_parameters. countersignatory_pubkeys ( ) , secp_ctx) ;
14881481
1489- // Sort outputs and populate output indices while keeping track of the auxiliary data
1490- let ( outputs, htlcs ) = Self :: internal_build_outputs ( & keys, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux , channel_parameters) . unwrap ( ) ;
1482+ // Sort outputs and populate output indices
1483+ let ( outputs, nondust_htlcs ) = Self :: internal_build_outputs ( & keys, to_broadcaster_value_sat, to_countersignatory_value_sat, nondust_htlcs , channel_parameters) . unwrap ( ) ;
14911484
14921485 let ( obscured_commitment_transaction_number, txins) = Self :: internal_build_inputs ( commitment_number, channel_parameters) ;
14931486 let transaction = Self :: make_transaction ( obscured_commitment_transaction_number, txins, outputs) ;
@@ -1498,7 +1491,7 @@ impl CommitmentTransaction {
14981491 to_countersignatory_value_sat,
14991492 to_broadcaster_delay : Some ( channel_parameters. contest_delay ( ) ) ,
15001493 feerate_per_kw,
1501- htlcs,
1494+ htlcs : nondust_htlcs ,
15021495 channel_type_features : channel_parameters. channel_type_features ( ) . clone ( ) ,
15031496 keys,
15041497 built : BuiltCommitmentTransaction {
@@ -1519,8 +1512,8 @@ impl CommitmentTransaction {
15191512 fn internal_rebuild_transaction ( & self , keys : & TxCreationKeys , channel_parameters : & DirectedChannelTransactionParameters ) -> Result < BuiltCommitmentTransaction , ( ) > {
15201513 let ( obscured_commitment_transaction_number, txins) = Self :: internal_build_inputs ( self . commitment_number , channel_parameters) ;
15211514
1522- let mut htlcs_with_aux = self . htlcs . iter ( ) . map ( |h| ( h . clone ( ) , ( ) ) ) . collect ( ) ;
1523- let ( outputs, _) = Self :: internal_build_outputs ( keys, self . to_broadcaster_value_sat , self . to_countersignatory_value_sat , & mut htlcs_with_aux , channel_parameters) ?;
1515+ let mut nondust_htlcs = self . htlcs . clone ( ) ;
1516+ let ( outputs, _) = Self :: internal_build_outputs ( keys, self . to_broadcaster_value_sat , self . to_countersignatory_value_sat , nondust_htlcs . iter_mut ( ) . collect ( ) , channel_parameters) ?;
15241517
15251518 let transaction = Self :: make_transaction ( obscured_commitment_transaction_number, txins, outputs) ;
15261519 let txid = transaction. compute_txid ( ) ;
@@ -1544,7 +1537,7 @@ impl CommitmentTransaction {
15441537 // - initial sorting of outputs / HTLCs in the constructor, in which case T is auxiliary data the
15451538 // caller needs to have sorted together with the HTLCs so it can keep track of the output index
15461539 // - building of a bitcoin transaction during a verify() call, in which case T is just ()
1547- 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 > ) , ( ) > {
1540+ fn internal_build_outputs ( keys : & TxCreationKeys , to_broadcaster_value_sat : Amount , to_countersignatory_value_sat : Amount , nondust_htlcs : Vec < & mut HTLCOutputInCommitment > , channel_parameters : & DirectedChannelTransactionParameters ) -> Result < ( Vec < TxOut > , Vec < HTLCOutputInCommitment > ) , ( ) > {
15481541 let countersignatory_pubkeys = channel_parameters. countersignatory_pubkeys ( ) ;
15491542 let broadcaster_funding_key = & channel_parameters. broadcaster_pubkeys ( ) . funding_pubkey ;
15501543 let countersignatory_funding_key = & countersignatory_pubkeys. funding_pubkey ;
@@ -1583,7 +1576,7 @@ impl CommitmentTransaction {
15831576 }
15841577
15851578 if channel_parameters. channel_type_features ( ) . supports_anchors_zero_fee_htlc_tx ( ) {
1586- if to_broadcaster_value_sat > Amount :: ZERO || !htlcs_with_aux . is_empty ( ) {
1579+ if to_broadcaster_value_sat > Amount :: ZERO || !nondust_htlcs . is_empty ( ) {
15871580 let anchor_script = get_anchor_redeemscript ( broadcaster_funding_key) ;
15881581 txouts. push ( (
15891582 TxOut {
@@ -1594,7 +1587,7 @@ impl CommitmentTransaction {
15941587 ) ) ;
15951588 }
15961589
1597- if to_countersignatory_value_sat > Amount :: ZERO || !htlcs_with_aux . is_empty ( ) {
1590+ if to_countersignatory_value_sat > Amount :: ZERO || !nondust_htlcs . is_empty ( ) {
15981591 let anchor_script = get_anchor_redeemscript ( countersignatory_funding_key) ;
15991592 txouts. push ( (
16001593 TxOut {
@@ -1606,8 +1599,8 @@ impl CommitmentTransaction {
16061599 }
16071600 }
16081601
1609- let mut htlcs = Vec :: with_capacity ( htlcs_with_aux . len ( ) ) ;
1610- for ( htlc, _ ) in htlcs_with_aux {
1602+ let mut htlcs = Vec :: with_capacity ( nondust_htlcs . len ( ) ) ;
1603+ for htlc in nondust_htlcs {
16111604 let script = get_htlc_redeemscript ( & htlc, & channel_parameters. channel_type_features ( ) , & keys) ;
16121605 let txout = TxOut {
16131606 script_pubkey : script. to_p2wsh ( ) ,
@@ -1951,7 +1944,7 @@ mod tests {
19511944 commitment_number : u64 ,
19521945 per_commitment_point : PublicKey ,
19531946 feerate_per_kw : u32 ,
1954- htlcs_with_aux : Vec < ( HTLCOutputInCommitment , ( ) ) > ,
1947+ nondust_htlcs : Vec < HTLCOutputInCommitment > ,
19551948 channel_parameters : ChannelTransactionParameters ,
19561949 counterparty_pubkeys : ChannelPublicKeys ,
19571950 secp_ctx : Secp256k1 :: < secp256k1:: All > ,
@@ -1979,23 +1972,23 @@ mod tests {
19791972 channel_type_features : ChannelTypeFeatures :: only_static_remote_key ( ) ,
19801973 channel_value_satoshis : 3000 ,
19811974 } ;
1982- let htlcs_with_aux = Vec :: new ( ) ;
1975+ let nondust_htlcs = Vec :: new ( ) ;
19831976
19841977 Self {
19851978 commitment_number : 0 ,
19861979 per_commitment_point,
19871980 feerate_per_kw : 1 ,
1988- htlcs_with_aux ,
1981+ nondust_htlcs ,
19891982 channel_parameters,
19901983 counterparty_pubkeys,
19911984 secp_ctx,
19921985 }
19931986 }
19941987
19951988 fn build ( & mut self , to_broadcaster_sats : u64 , to_countersignatory_sats : u64 ) -> CommitmentTransaction {
1996- CommitmentTransaction :: new_with_auxiliary_htlc_data (
1989+ CommitmentTransaction :: new (
19971990 self . commitment_number , & self . per_commitment_point , to_broadcaster_sats, to_countersignatory_sats, self . feerate_per_kw ,
1998- & mut self . htlcs_with_aux , & self . channel_parameters . as_holder_broadcastable ( ) , & self . secp_ctx
1991+ self . nondust_htlcs . iter_mut ( ) . collect ( ) , & self . channel_parameters . as_holder_broadcastable ( ) , & self . secp_ctx
19991992 )
20001993 }
20011994 }
@@ -2041,7 +2034,7 @@ mod tests {
20412034
20422035 // Generate broadcaster output and received and offered HTLC outputs, w/o anchors
20432036 builder. channel_parameters . channel_type_features = ChannelTypeFeatures :: only_static_remote_key ( ) ;
2044- builder. htlcs_with_aux = vec ! [ ( received_htlc. clone( ) , ( ) ) , ( offered_htlc. clone( ) , ( ) ) ] ;
2037+ builder. nondust_htlcs = vec ! [ received_htlc. clone( ) , offered_htlc. clone( ) ] ;
20452038 let tx = builder. build ( 3000 , 0 ) ;
20462039 let keys = & tx. trust ( ) . keys ( ) ;
20472040 assert_eq ! ( tx. built. transaction. output. len( ) , 3 ) ;
@@ -2054,7 +2047,7 @@ mod tests {
20542047
20552048 // Generate broadcaster output and received and offered HTLC outputs, with anchors
20562049 builder. channel_parameters . channel_type_features = ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies ( ) ;
2057- builder. htlcs_with_aux = vec ! [ ( received_htlc. clone( ) , ( ) ) , ( offered_htlc. clone( ) , ( ) ) ] ;
2050+ builder. nondust_htlcs = vec ! [ received_htlc. clone( ) , offered_htlc. clone( ) ] ;
20582051 let tx = builder. build ( 3000 , 0 ) ;
20592052 assert_eq ! ( tx. built. transaction. output. len( ) , 5 ) ;
20602053 assert_eq ! ( tx. built. transaction. output[ 2 ] . script_pubkey, get_htlc_redeemscript( & received_htlc, & ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies( ) , & keys) . to_p2wsh( ) ) ;
0 commit comments