@@ -1129,7 +1129,7 @@ impl_writeable_tlv_based!(HolderCommitmentTransaction, {
1129
1129
1130
1130
impl HolderCommitmentTransaction {
1131
1131
#[ 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 {
1133
1133
let secp_ctx = Secp256k1 :: new ( ) ;
1134
1134
let dummy_key = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
1135
1135
let dummy_sig = sign ( & secp_ctx, & secp256k1:: Message :: from_digest ( [ 42 ; 32 ] ) , & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
@@ -1151,11 +1151,11 @@ impl HolderCommitmentTransaction {
1151
1151
channel_value_satoshis,
1152
1152
} ;
1153
1153
let mut counterparty_htlc_sigs = Vec :: new ( ) ;
1154
- for _ in 0 ..htlcs . len ( ) {
1154
+ for _ in 0 ..nondust_htlcs . len ( ) {
1155
1155
counterparty_htlc_sigs. push ( dummy_sig) ;
1156
1156
}
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 ) ;
1159
1159
HolderCommitmentTransaction {
1160
1160
inner,
1161
1161
counterparty_sig : dummy_sig,
@@ -1454,23 +1454,16 @@ impl Readable for CommitmentTransaction {
1454
1454
}
1455
1455
1456
1456
impl 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` .
1458
1458
///
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 {
1468
1461
let to_broadcaster_value_sat = Amount :: from_sat ( to_broadcaster_value_sat) ;
1469
1462
let to_countersignatory_value_sat = Amount :: from_sat ( to_countersignatory_value_sat) ;
1470
1463
let keys = TxCreationKeys :: from_channel_static_keys ( per_commitment_point, channel_parameters. broadcaster_pubkeys ( ) , channel_parameters. countersignatory_pubkeys ( ) , secp_ctx) ;
1471
1464
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 ( ) ;
1474
1467
1475
1468
let ( obscured_commitment_transaction_number, txins) = Self :: internal_build_inputs ( commitment_number, channel_parameters) ;
1476
1469
let transaction = Self :: make_transaction ( obscured_commitment_transaction_number, txins, outputs) ;
@@ -1481,7 +1474,7 @@ impl CommitmentTransaction {
1481
1474
to_countersignatory_value_sat,
1482
1475
to_broadcaster_delay : Some ( channel_parameters. contest_delay ( ) ) ,
1483
1476
feerate_per_kw,
1484
- htlcs,
1477
+ htlcs : nondust_htlcs ,
1485
1478
channel_type_features : channel_parameters. channel_type_features ( ) . clone ( ) ,
1486
1479
keys,
1487
1480
built : BuiltCommitmentTransaction {
@@ -1502,8 +1495,8 @@ impl CommitmentTransaction {
1502
1495
fn internal_rebuild_transaction ( & self , keys : & TxCreationKeys , channel_parameters : & DirectedChannelTransactionParameters ) -> Result < BuiltCommitmentTransaction , ( ) > {
1503
1496
let ( obscured_commitment_transaction_number, txins) = Self :: internal_build_inputs ( self . commitment_number , channel_parameters) ;
1504
1497
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) ?;
1507
1500
1508
1501
let transaction = Self :: make_transaction ( obscured_commitment_transaction_number, txins, outputs) ;
1509
1502
let txid = transaction. compute_txid ( ) ;
@@ -1527,7 +1520,7 @@ impl CommitmentTransaction {
1527
1520
// - initial sorting of outputs / HTLCs in the constructor, in which case T is auxiliary data the
1528
1521
// caller needs to have sorted together with the HTLCs so it can keep track of the output index
1529
1522
// - 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 > ) , ( ) > {
1531
1524
let countersignatory_pubkeys = channel_parameters. countersignatory_pubkeys ( ) ;
1532
1525
let broadcaster_funding_key = & channel_parameters. broadcaster_pubkeys ( ) . funding_pubkey ;
1533
1526
let countersignatory_funding_key = & countersignatory_pubkeys. funding_pubkey ;
@@ -1566,7 +1559,7 @@ impl CommitmentTransaction {
1566
1559
}
1567
1560
1568
1561
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 ( ) {
1570
1563
let anchor_script = get_anchor_redeemscript ( broadcaster_funding_key) ;
1571
1564
txouts. push ( (
1572
1565
TxOut {
@@ -1577,7 +1570,7 @@ impl CommitmentTransaction {
1577
1570
) ) ;
1578
1571
}
1579
1572
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 ( ) {
1581
1574
let anchor_script = get_anchor_redeemscript ( countersignatory_funding_key) ;
1582
1575
txouts. push ( (
1583
1576
TxOut {
@@ -1589,8 +1582,8 @@ impl CommitmentTransaction {
1589
1582
}
1590
1583
}
1591
1584
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 {
1594
1587
let script = get_htlc_redeemscript ( & htlc, & channel_parameters. channel_type_features ( ) , & keys) ;
1595
1588
let txout = TxOut {
1596
1589
script_pubkey : script. to_p2wsh ( ) ,
@@ -1934,7 +1927,7 @@ mod tests {
1934
1927
commitment_number : u64 ,
1935
1928
per_commitment_point : PublicKey ,
1936
1929
feerate_per_kw : u32 ,
1937
- htlcs_with_aux : Vec < ( HTLCOutputInCommitment , ( ) ) > ,
1930
+ nondust_htlcs : Vec < HTLCOutputInCommitment > ,
1938
1931
channel_parameters : ChannelTransactionParameters ,
1939
1932
counterparty_pubkeys : ChannelPublicKeys ,
1940
1933
secp_ctx : Secp256k1 :: < secp256k1:: All > ,
@@ -1961,23 +1954,23 @@ mod tests {
1961
1954
channel_type_features : ChannelTypeFeatures :: only_static_remote_key ( ) ,
1962
1955
channel_value_satoshis : 3000 ,
1963
1956
} ;
1964
- let htlcs_with_aux = Vec :: new ( ) ;
1957
+ let nondust_htlcs = Vec :: new ( ) ;
1965
1958
1966
1959
Self {
1967
1960
commitment_number : 0 ,
1968
1961
per_commitment_point,
1969
1962
feerate_per_kw : 1 ,
1970
- htlcs_with_aux ,
1963
+ nondust_htlcs ,
1971
1964
channel_parameters,
1972
1965
counterparty_pubkeys,
1973
1966
secp_ctx,
1974
1967
}
1975
1968
}
1976
1969
1977
1970
fn build ( & mut self , to_broadcaster_sats : u64 , to_countersignatory_sats : u64 ) -> CommitmentTransaction {
1978
- CommitmentTransaction :: new_with_auxiliary_htlc_data (
1971
+ CommitmentTransaction :: new (
1979
1972
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
1981
1974
)
1982
1975
}
1983
1976
}
@@ -2023,7 +2016,7 @@ mod tests {
2023
2016
2024
2017
// Generate broadcaster output and received and offered HTLC outputs, w/o anchors
2025
2018
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( ) ] ;
2027
2020
let tx = builder. build ( 3000 , 0 ) ;
2028
2021
let keys = & tx. trust ( ) . keys ( ) ;
2029
2022
assert_eq ! ( tx. built. transaction. output. len( ) , 3 ) ;
@@ -2036,7 +2029,7 @@ mod tests {
2036
2029
2037
2030
// Generate broadcaster output and received and offered HTLC outputs, with anchors
2038
2031
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( ) ] ;
2040
2033
let tx = builder. build ( 3000 , 0 ) ;
2041
2034
assert_eq ! ( tx. built. transaction. output. len( ) , 5 ) ;
2042
2035
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