@@ -1208,7 +1208,7 @@ impl HolderCommitmentTransaction {
1208
1208
for _ in 0 ..htlcs. len ( ) {
1209
1209
counterparty_htlc_sigs. push ( dummy_sig) ;
1210
1210
}
1211
- 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 ( ) ) ;
1211
+ let inner = CommitmentTransaction :: new_with_auxiliary_htlc_data ( 0 , 0 , 0 , keys, 0 , htlcs, & channel_parameters. as_counterparty_broadcastable ( ) ) ;
1212
1212
htlcs. sort_by_key ( |htlc| htlc. 0 . transaction_output_index ) ;
1213
1213
HolderCommitmentTransaction {
1214
1214
inner,
@@ -1518,12 +1518,12 @@ impl CommitmentTransaction {
1518
1518
/// Only include HTLCs that are above the dust limit for the channel.
1519
1519
///
1520
1520
/// This is not exported to bindings users due to the generic though we likely should expose a version without
1521
- pub fn new_with_auxiliary_htlc_data < T > ( 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 ) -> CommitmentTransaction {
1521
+ pub fn new_with_auxiliary_htlc_data < T > ( 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 ) -> CommitmentTransaction {
1522
1522
let to_broadcaster_value_sat = Amount :: from_sat ( to_broadcaster_value_sat) ;
1523
1523
let to_countersignatory_value_sat = Amount :: from_sat ( to_countersignatory_value_sat) ;
1524
1524
1525
1525
// Sort outputs and populate output indices while keeping track of the auxiliary data
1526
- let ( outputs, htlcs) = Self :: internal_build_outputs ( & keys, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, channel_parameters, & broadcaster_funding_key , & countersignatory_funding_key ) . unwrap ( ) ;
1526
+ let ( outputs, htlcs) = Self :: internal_build_outputs ( & keys, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, channel_parameters) . unwrap ( ) ;
1527
1527
1528
1528
let ( obscured_commitment_transaction_number, txins) = Self :: internal_build_inputs ( commitment_number, channel_parameters) ;
1529
1529
let transaction = Self :: make_transaction ( obscured_commitment_transaction_number, txins, outputs) ;
@@ -1552,11 +1552,11 @@ impl CommitmentTransaction {
1552
1552
self
1553
1553
}
1554
1554
1555
- fn internal_rebuild_transaction ( & self , keys : & TxCreationKeys , channel_parameters : & DirectedChannelTransactionParameters , broadcaster_funding_key : & PublicKey , countersignatory_funding_key : & PublicKey ) -> Result < BuiltCommitmentTransaction , ( ) > {
1555
+ fn internal_rebuild_transaction ( & self , keys : & TxCreationKeys , channel_parameters : & DirectedChannelTransactionParameters ) -> Result < BuiltCommitmentTransaction , ( ) > {
1556
1556
let ( obscured_commitment_transaction_number, txins) = Self :: internal_build_inputs ( self . commitment_number , channel_parameters) ;
1557
1557
1558
1558
let mut htlcs_with_aux = self . htlcs . iter ( ) . map ( |h| ( h. clone ( ) , ( ) ) ) . collect ( ) ;
1559
- let ( outputs, _) = Self :: internal_build_outputs ( keys, self . to_broadcaster_value_sat , self . to_countersignatory_value_sat , & mut htlcs_with_aux, channel_parameters, broadcaster_funding_key , countersignatory_funding_key ) ?;
1559
+ let ( outputs, _) = Self :: internal_build_outputs ( keys, self . to_broadcaster_value_sat , self . to_countersignatory_value_sat , & mut htlcs_with_aux, channel_parameters) ?;
1560
1560
1561
1561
let transaction = Self :: make_transaction ( obscured_commitment_transaction_number, txins, outputs) ;
1562
1562
let txid = transaction. compute_txid ( ) ;
@@ -1580,17 +1580,20 @@ impl CommitmentTransaction {
1580
1580
// - initial sorting of outputs / HTLCs in the constructor, in which case T is auxiliary data the
1581
1581
// caller needs to have sorted together with the HTLCs so it can keep track of the output index
1582
1582
// - building of a bitcoin transaction during a verify() call, in which case T is just ()
1583
- 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 , broadcaster_funding_key : & PublicKey , countersignatory_funding_key : & PublicKey ) -> Result < ( Vec < TxOut > , Vec < HTLCOutputInCommitment > ) , ( ) > {
1584
- let countersignatory_pubkeys = channel_parameters. countersignatory_pubkeys ( ) ;
1583
+ 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 > ) , ( ) > {
1584
+ let countersignatory_payment_point = & channel_parameters. countersignatory_pubkeys ( ) . payment_point ;
1585
+ let countersignatory_funding_key = & channel_parameters. countersignatory_pubkeys ( ) . funding_pubkey ;
1586
+ let broadcaster_funding_key = & channel_parameters. broadcaster_pubkeys ( ) . funding_pubkey ;
1587
+ let channel_type = channel_parameters. channel_type_features ( ) ;
1585
1588
let contest_delay = channel_parameters. contest_delay ( ) ;
1586
1589
1587
1590
let mut txouts: Vec < ( TxOut , Option < & mut HTLCOutputInCommitment > ) > = Vec :: new ( ) ;
1588
1591
1589
1592
if to_countersignatory_value_sat > Amount :: ZERO {
1590
- let script = if channel_parameters . channel_type_features ( ) . supports_anchors_zero_fee_htlc_tx ( ) {
1591
- get_to_countersigner_keyed_anchor_redeemscript ( & countersignatory_pubkeys . payment_point ) . to_p2wsh ( )
1593
+ let script = if channel_type . supports_anchors_zero_fee_htlc_tx ( ) {
1594
+ get_to_countersigner_keyed_anchor_redeemscript ( countersignatory_payment_point ) . to_p2wsh ( )
1592
1595
} else {
1593
- ScriptBuf :: new_p2wpkh ( & Hash160 :: hash ( & countersignatory_pubkeys . payment_point . serialize ( ) ) . into ( ) )
1596
+ ScriptBuf :: new_p2wpkh ( & Hash160 :: hash ( & countersignatory_payment_point . serialize ( ) ) . into ( ) )
1594
1597
} ;
1595
1598
txouts. push ( (
1596
1599
TxOut {
@@ -1616,7 +1619,7 @@ impl CommitmentTransaction {
1616
1619
) ) ;
1617
1620
}
1618
1621
1619
- if channel_parameters . channel_type_features ( ) . supports_anchors_zero_fee_htlc_tx ( ) {
1622
+ if channel_type . supports_anchors_zero_fee_htlc_tx ( ) {
1620
1623
if to_broadcaster_value_sat > Amount :: ZERO || !htlcs_with_aux. is_empty ( ) {
1621
1624
let anchor_script = get_keyed_anchor_redeemscript ( broadcaster_funding_key) ;
1622
1625
txouts. push ( (
@@ -1642,7 +1645,7 @@ impl CommitmentTransaction {
1642
1645
1643
1646
let mut htlcs = Vec :: with_capacity ( htlcs_with_aux. len ( ) ) ;
1644
1647
for ( htlc, _) in htlcs_with_aux {
1645
- let script = get_htlc_redeemscript ( & htlc, & channel_parameters . channel_type_features ( ) , & keys) ;
1648
+ let script = get_htlc_redeemscript ( htlc, channel_type , keys) ;
1646
1649
let txout = TxOut {
1647
1650
script_pubkey : script. to_p2wsh ( ) ,
1648
1651
value : htlc. to_bitcoin_amount ( ) ,
@@ -1753,14 +1756,14 @@ impl CommitmentTransaction {
1753
1756
///
1754
1757
/// An external validating signer must call this method before signing
1755
1758
/// or using the built transaction.
1756
- pub fn verify < T : secp256k1:: Signing + secp256k1:: Verification > ( & self , channel_parameters : & DirectedChannelTransactionParameters , broadcaster_keys : & ChannelPublicKeys , countersignatory_keys : & ChannelPublicKeys , secp_ctx : & Secp256k1 < T > ) -> Result < TrustedCommitmentTransaction , ( ) > {
1759
+ pub fn verify < T : secp256k1:: Signing + secp256k1:: Verification > ( & self , channel_parameters : & DirectedChannelTransactionParameters , secp_ctx : & Secp256k1 < T > ) -> Result < TrustedCommitmentTransaction , ( ) > {
1757
1760
// This is the only field of the key cache that we trust
1758
- let per_commitment_point = self . keys . per_commitment_point ;
1759
- let keys = TxCreationKeys :: from_channel_static_keys ( & per_commitment_point, broadcaster_keys , countersignatory_keys , secp_ctx) ;
1761
+ let per_commitment_point = & self . keys . per_commitment_point ;
1762
+ let keys = TxCreationKeys :: from_channel_static_keys ( per_commitment_point, channel_parameters . broadcaster_pubkeys ( ) , channel_parameters . countersignatory_pubkeys ( ) , secp_ctx) ;
1760
1763
if keys != self . keys {
1761
1764
return Err ( ( ) ) ;
1762
1765
}
1763
- let tx = self . internal_rebuild_transaction ( & keys, channel_parameters, & broadcaster_keys . funding_pubkey , & countersignatory_keys . funding_pubkey ) ?;
1766
+ let tx = self . internal_rebuild_transaction ( & keys, channel_parameters) ?;
1764
1767
if self . built . transaction != tx. transaction || self . built . txid != tx. txid {
1765
1768
return Err ( ( ) ) ;
1766
1769
}
@@ -1983,8 +1986,6 @@ mod tests {
1983
1986
1984
1987
struct TestCommitmentTxBuilder {
1985
1988
commitment_number : u64 ,
1986
- holder_funding_pubkey : PublicKey ,
1987
- counterparty_funding_pubkey : PublicKey ,
1988
1989
keys : TxCreationKeys ,
1989
1990
feerate_per_kw : u32 ,
1990
1991
htlcs_with_aux : Vec < ( HTLCOutputInCommitment , ( ) ) > ,
@@ -2023,8 +2024,6 @@ mod tests {
2023
2024
2024
2025
Self {
2025
2026
commitment_number : 0 ,
2026
- holder_funding_pubkey : holder_pubkeys. funding_pubkey ,
2027
- counterparty_funding_pubkey : counterparty_pubkeys. funding_pubkey ,
2028
2027
keys,
2029
2028
feerate_per_kw : 1 ,
2030
2029
htlcs_with_aux,
@@ -2036,8 +2035,6 @@ mod tests {
2036
2035
fn build ( & mut self , to_broadcaster_sats : u64 , to_countersignatory_sats : u64 ) -> CommitmentTransaction {
2037
2036
CommitmentTransaction :: new_with_auxiliary_htlc_data (
2038
2037
self . commitment_number , to_broadcaster_sats, to_countersignatory_sats,
2039
- self . holder_funding_pubkey . clone ( ) ,
2040
- self . counterparty_funding_pubkey . clone ( ) ,
2041
2038
self . keys . clone ( ) , self . feerate_per_kw ,
2042
2039
& mut self . htlcs_with_aux , & self . channel_parameters . as_holder_broadcastable ( )
2043
2040
)
0 commit comments