@@ -1129,7 +1129,7 @@ impl_writeable_tlv_based!(HolderCommitmentTransaction, {
11291129
11301130impl HolderCommitmentTransaction {
11311131 #[ cfg( test) ]
1132- pub fn dummy ( channel_value_satoshis : u64 , htlcs : & mut Vec < ( HTLCOutputInCommitment , ( ) ) > ) -> Self {
1132+ pub fn dummy ( channel_value_satoshis : u64 , nondust_htlcs : & mut Vec < HTLCOutputInCommitment > ) -> Self {
11331133 let secp_ctx = Secp256k1 :: new ( ) ;
11341134 let dummy_key = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
11351135 let dummy_sig = sign ( & secp_ctx, & secp256k1:: Message :: from_digest ( [ 42 ; 32 ] ) , & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
@@ -1151,11 +1151,11 @@ impl HolderCommitmentTransaction {
11511151 channel_value_satoshis,
11521152 } ;
11531153 let mut counterparty_htlc_sigs = Vec :: new ( ) ;
1154- for _ in 0 ..htlcs . len ( ) {
1154+ for _ in 0 ..nondust_htlcs . len ( ) {
11551155 counterparty_htlc_sigs. push ( dummy_sig) ;
11561156 }
1157- let inner = CommitmentTransaction :: new_with_auxiliary_htlc_data ( 0 , & dummy_key. clone ( ) , 0 , 0 , 0 , htlcs , & channel_parameters. as_counterparty_broadcastable ( ) , & secp_ctx) ;
1158- htlcs . sort_by_key ( |htlc| htlc. 0 . transaction_output_index ) ;
1157+ let inner = CommitmentTransaction :: new ( 0 , & dummy_key. clone ( ) , 0 , 0 , 0 , nondust_htlcs . iter_mut ( ) . collect ( ) , & channel_parameters. as_counterparty_broadcastable ( ) , & secp_ctx) ;
1158+ nondust_htlcs . sort_by_key ( |htlc| htlc. transaction_output_index ) ;
11591159 HolderCommitmentTransaction {
11601160 inner,
11611161 counterparty_sig : dummy_sig,
@@ -1454,23 +1454,16 @@ impl Readable for CommitmentTransaction {
14541454}
14551455
14561456impl CommitmentTransaction {
1457- /// Construct an object of the class while assigning transaction output indices to HTLCs.
1457+ /// Construct an object of the class while assigning transaction output indices to HTLCs in `nondust_htlcs` .
14581458 ///
1459- /// Populates HTLCOutputInCommitment.transaction_output_index in htlcs_with_aux.
1460- ///
1461- /// The generic T allows the caller to match the HTLC output index with auxiliary data.
1462- /// This auxiliary data is not stored in this object.
1463- ///
1464- /// Only include HTLCs that are above the dust limit for the channel.
1465- ///
1466- /// This is not exported to bindings users due to the generic though we likely should expose a version without
1467- 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 {
1459+ /// `nondust_htlcs` should only include HTLCs that are above the dust limit for the channel.
1460+ 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 {
14681461 let to_broadcaster_value_sat = Amount :: from_sat ( to_broadcaster_value_sat) ;
14691462 let to_countersignatory_value_sat = Amount :: from_sat ( to_countersignatory_value_sat) ;
14701463 let keys = TxCreationKeys :: from_channel_static_keys ( per_commitment_point, channel_parameters. broadcaster_pubkeys ( ) , channel_parameters. countersignatory_pubkeys ( ) , secp_ctx) ;
14711464
1472- // Sort outputs and populate output indices while keeping track of the auxiliary data
1473- let ( outputs, htlcs ) = Self :: internal_build_outputs ( & keys, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux , channel_parameters) . unwrap ( ) ;
1465+ // Sort outputs and populate output indices
1466+ let ( outputs, nondust_htlcs ) = Self :: internal_build_outputs ( & keys, to_broadcaster_value_sat, to_countersignatory_value_sat, nondust_htlcs , channel_parameters) . unwrap ( ) ;
14741467
14751468 let ( obscured_commitment_transaction_number, txins) = Self :: internal_build_inputs ( commitment_number, channel_parameters) ;
14761469 let transaction = Self :: make_transaction ( obscured_commitment_transaction_number, txins, outputs) ;
@@ -1481,7 +1474,7 @@ impl CommitmentTransaction {
14811474 to_countersignatory_value_sat,
14821475 to_broadcaster_delay : Some ( channel_parameters. contest_delay ( ) ) ,
14831476 feerate_per_kw,
1484- htlcs,
1477+ htlcs : nondust_htlcs ,
14851478 channel_type_features : channel_parameters. channel_type_features ( ) . clone ( ) ,
14861479 keys,
14871480 built : BuiltCommitmentTransaction {
@@ -1502,8 +1495,8 @@ impl CommitmentTransaction {
15021495 fn internal_rebuild_transaction ( & self , keys : & TxCreationKeys , channel_parameters : & DirectedChannelTransactionParameters ) -> Result < BuiltCommitmentTransaction , ( ) > {
15031496 let ( obscured_commitment_transaction_number, txins) = Self :: internal_build_inputs ( self . commitment_number , channel_parameters) ;
15041497
1505- let mut htlcs_with_aux = self . htlcs . iter ( ) . map ( |h| ( h . clone ( ) , ( ) ) ) . collect ( ) ;
1506- let ( outputs, _) = Self :: internal_build_outputs ( keys, self . to_broadcaster_value_sat , self . to_countersignatory_value_sat , & mut htlcs_with_aux , channel_parameters) ?;
1498+ let mut nondust_htlcs = self . htlcs . clone ( ) ;
1499+ let ( outputs, _) = Self :: internal_build_outputs ( keys, self . to_broadcaster_value_sat , self . to_countersignatory_value_sat , nondust_htlcs . iter_mut ( ) . collect ( ) , channel_parameters) ?;
15071500
15081501 let transaction = Self :: make_transaction ( obscured_commitment_transaction_number, txins, outputs) ;
15091502 let txid = transaction. compute_txid ( ) ;
@@ -1527,7 +1520,7 @@ impl CommitmentTransaction {
15271520 // - initial sorting of outputs / HTLCs in the constructor, in which case T is auxiliary data the
15281521 // caller needs to have sorted together with the HTLCs so it can keep track of the output index
15291522 // - building of a bitcoin transaction during a verify() call, in which case T is just ()
1530- 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 > ) , ( ) > {
1523+ 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 > ) , ( ) > {
15311524 let countersignatory_pubkeys = channel_parameters. countersignatory_pubkeys ( ) ;
15321525 let broadcaster_funding_key = & channel_parameters. broadcaster_pubkeys ( ) . funding_pubkey ;
15331526 let countersignatory_funding_key = & countersignatory_pubkeys. funding_pubkey ;
@@ -1566,7 +1559,7 @@ impl CommitmentTransaction {
15661559 }
15671560
15681561 if channel_parameters. channel_type_features ( ) . supports_anchors_zero_fee_htlc_tx ( ) {
1569- if to_broadcaster_value_sat > Amount :: ZERO || !htlcs_with_aux . is_empty ( ) {
1562+ if to_broadcaster_value_sat > Amount :: ZERO || !nondust_htlcs . is_empty ( ) {
15701563 let anchor_script = get_anchor_redeemscript ( broadcaster_funding_key) ;
15711564 txouts. push ( (
15721565 TxOut {
@@ -1577,7 +1570,7 @@ impl CommitmentTransaction {
15771570 ) ) ;
15781571 }
15791572
1580- if to_countersignatory_value_sat > Amount :: ZERO || !htlcs_with_aux . is_empty ( ) {
1573+ if to_countersignatory_value_sat > Amount :: ZERO || !nondust_htlcs . is_empty ( ) {
15811574 let anchor_script = get_anchor_redeemscript ( countersignatory_funding_key) ;
15821575 txouts. push ( (
15831576 TxOut {
@@ -1589,8 +1582,8 @@ impl CommitmentTransaction {
15891582 }
15901583 }
15911584
1592- let mut htlcs = Vec :: with_capacity ( htlcs_with_aux . len ( ) ) ;
1593- for ( htlc, _ ) in htlcs_with_aux {
1585+ let mut htlcs = Vec :: with_capacity ( nondust_htlcs . len ( ) ) ;
1586+ for htlc in nondust_htlcs {
15941587 let script = get_htlc_redeemscript ( & htlc, & channel_parameters. channel_type_features ( ) , & keys) ;
15951588 let txout = TxOut {
15961589 script_pubkey : script. to_p2wsh ( ) ,
@@ -1934,7 +1927,7 @@ mod tests {
19341927 commitment_number : u64 ,
19351928 per_commitment_point : PublicKey ,
19361929 feerate_per_kw : u32 ,
1937- htlcs_with_aux : Vec < ( HTLCOutputInCommitment , ( ) ) > ,
1930+ nondust_htlcs : Vec < HTLCOutputInCommitment > ,
19381931 channel_parameters : ChannelTransactionParameters ,
19391932 counterparty_pubkeys : ChannelPublicKeys ,
19401933 secp_ctx : Secp256k1 :: < secp256k1:: All > ,
@@ -1961,23 +1954,23 @@ mod tests {
19611954 channel_type_features : ChannelTypeFeatures :: only_static_remote_key ( ) ,
19621955 channel_value_satoshis : 3000 ,
19631956 } ;
1964- let htlcs_with_aux = Vec :: new ( ) ;
1957+ let nondust_htlcs = Vec :: new ( ) ;
19651958
19661959 Self {
19671960 commitment_number : 0 ,
19681961 per_commitment_point,
19691962 feerate_per_kw : 1 ,
1970- htlcs_with_aux ,
1963+ nondust_htlcs ,
19711964 channel_parameters,
19721965 counterparty_pubkeys,
19731966 secp_ctx,
19741967 }
19751968 }
19761969
19771970 fn build ( & mut self , to_broadcaster_sats : u64 , to_countersignatory_sats : u64 ) -> CommitmentTransaction {
1978- CommitmentTransaction :: new_with_auxiliary_htlc_data (
1971+ CommitmentTransaction :: new (
19791972 self . commitment_number , & self . per_commitment_point , to_broadcaster_sats, to_countersignatory_sats, self . feerate_per_kw ,
1980- & mut self . htlcs_with_aux , & self . channel_parameters . as_holder_broadcastable ( ) , & self . secp_ctx
1973+ self . nondust_htlcs . iter_mut ( ) . collect ( ) , & self . channel_parameters . as_holder_broadcastable ( ) , & self . secp_ctx
19811974 )
19821975 }
19831976 }
@@ -2023,7 +2016,7 @@ mod tests {
20232016
20242017 // Generate broadcaster output and received and offered HTLC outputs, w/o anchors
20252018 builder. channel_parameters . channel_type_features = ChannelTypeFeatures :: only_static_remote_key ( ) ;
2026- builder. htlcs_with_aux = vec ! [ ( received_htlc. clone( ) , ( ) ) , ( offered_htlc. clone( ) , ( ) ) ] ;
2019+ builder. nondust_htlcs = vec ! [ received_htlc. clone( ) , offered_htlc. clone( ) ] ;
20272020 let tx = builder. build ( 3000 , 0 ) ;
20282021 let keys = & tx. trust ( ) . keys ( ) ;
20292022 assert_eq ! ( tx. built. transaction. output. len( ) , 3 ) ;
@@ -2036,7 +2029,7 @@ mod tests {
20362029
20372030 // Generate broadcaster output and received and offered HTLC outputs, with anchors
20382031 builder. channel_parameters . channel_type_features = ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies ( ) ;
2039- builder. htlcs_with_aux = vec ! [ ( received_htlc. clone( ) , ( ) ) , ( offered_htlc. clone( ) , ( ) ) ] ;
2032+ builder. nondust_htlcs = vec ! [ received_htlc. clone( ) , offered_htlc. clone( ) ] ;
20402033 let tx = builder. build ( 3000 , 0 ) ;
20412034 assert_eq ! ( tx. built. transaction. output. len( ) , 5 ) ;
20422035 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