@@ -93,6 +93,12 @@ pub struct HTLCDescriptor {
9393 pub commitment_txid : Txid ,
9494 /// The number of the commitment transaction in which the HTLC output lives.
9595 pub per_commitment_number : u64 ,
96+ /// The key tweak corresponding to the number of the commitment transaction in which the HTLC
97+ /// output lives. This tweak is applied to all the basepoints for both parties in the channel to
98+ /// arrive at unique keys per commitment.
99+ ///
100+ /// See <https://github.com/lightning/bolts/blob/master/03-transactions.md#keys> for more info.
101+ pub per_commitment_point : PublicKey ,
96102 /// The details of the HTLC as it appears in the commitment transaction.
97103 pub htlc : HTLCOutputInCommitment ,
98104 /// The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be
@@ -111,17 +117,15 @@ impl HTLCDescriptor {
111117
112118 /// Returns the delayed output created as a result of spending the HTLC output in the commitment
113119 /// transaction.
114- pub fn tx_output < C : secp256k1:: Signing + secp256k1:: Verification > (
115- & self , per_commitment_point : & PublicKey , secp : & Secp256k1 < C >
116- ) -> TxOut {
120+ pub fn tx_output < C : secp256k1:: Signing + secp256k1:: Verification > ( & self , secp : & Secp256k1 < C > ) -> TxOut {
117121 let channel_params = self . channel_parameters . as_holder_broadcastable ( ) ;
118122 let broadcaster_keys = channel_params. broadcaster_pubkeys ( ) ;
119123 let counterparty_keys = channel_params. countersignatory_pubkeys ( ) ;
120124 let broadcaster_delayed_key = chan_utils:: derive_public_key (
121- secp, per_commitment_point, & broadcaster_keys. delayed_payment_basepoint
125+ secp, & self . per_commitment_point , & broadcaster_keys. delayed_payment_basepoint
122126 ) ;
123127 let counterparty_revocation_key = chan_utils:: derive_public_revocation_key (
124- secp, per_commitment_point, & counterparty_keys. revocation_basepoint
128+ secp, & self . per_commitment_point , & counterparty_keys. revocation_basepoint
125129 ) ;
126130 chan_utils:: build_htlc_output (
127131 0 /* feerate_per_kw */ , channel_params. contest_delay ( ) , & self . htlc ,
@@ -130,20 +134,18 @@ impl HTLCDescriptor {
130134 }
131135
132136 /// Returns the witness script of the HTLC output in the commitment transaction.
133- pub fn witness_script < C : secp256k1:: Signing + secp256k1:: Verification > (
134- & self , per_commitment_point : & PublicKey , secp : & Secp256k1 < C >
135- ) -> Script {
137+ pub fn witness_script < C : secp256k1:: Signing + secp256k1:: Verification > ( & self , secp : & Secp256k1 < C > ) -> Script {
136138 let channel_params = self . channel_parameters . as_holder_broadcastable ( ) ;
137139 let broadcaster_keys = channel_params. broadcaster_pubkeys ( ) ;
138140 let counterparty_keys = channel_params. countersignatory_pubkeys ( ) ;
139141 let broadcaster_htlc_key = chan_utils:: derive_public_key (
140- secp, per_commitment_point, & broadcaster_keys. htlc_basepoint
142+ secp, & self . per_commitment_point , & broadcaster_keys. htlc_basepoint
141143 ) ;
142144 let counterparty_htlc_key = chan_utils:: derive_public_key (
143- secp, per_commitment_point, & counterparty_keys. htlc_basepoint
145+ secp, & self . per_commitment_point , & counterparty_keys. htlc_basepoint
144146 ) ;
145147 let counterparty_revocation_key = chan_utils:: derive_public_revocation_key (
146- secp, per_commitment_point, & counterparty_keys. revocation_basepoint
148+ secp, & self . per_commitment_point , & counterparty_keys. revocation_basepoint
147149 ) ;
148150 chan_utils:: get_htlc_redeemscript_with_explicit_keys (
149151 & self . htlc , & ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies ( ) , & broadcaster_htlc_key, & counterparty_htlc_key,
@@ -696,15 +698,12 @@ where
696698 let mut signers = HashMap :: new ( ) ;
697699 let mut must_spend = Vec :: with_capacity ( htlc_descriptors. len ( ) ) ;
698700 for htlc_descriptor in htlc_descriptors {
699- let signer = signers. entry ( htlc_descriptor. channel_keys_id )
701+ signers. entry ( htlc_descriptor. channel_keys_id )
700702 . or_insert_with ( ||
701703 self . signer_provider . derive_channel_signer (
702704 htlc_descriptor. channel_value_satoshis , htlc_descriptor. channel_keys_id ,
703705 )
704706 ) ;
705- let per_commitment_point = signer. get_per_commitment_point (
706- htlc_descriptor. per_commitment_number , & self . secp
707- ) ;
708707
709708 let htlc_input = htlc_descriptor. unsigned_tx_input ( ) ;
710709 must_spend. push ( Input {
@@ -716,7 +715,7 @@ where
716715 } ,
717716 } ) ;
718717 tx. input . push ( htlc_input) ;
719- let htlc_output = htlc_descriptor. tx_output ( & per_commitment_point , & self . secp ) ;
718+ let htlc_output = htlc_descriptor. tx_output ( & self . secp ) ;
720719 tx. output . push ( htlc_output) ;
721720 }
722721
@@ -743,10 +742,7 @@ where
743742 let htlc_sig = signer. sign_holder_htlc_transaction (
744743 & htlc_tx, idx, htlc_descriptor, & self . secp
745744 ) ?;
746- let per_commitment_point = signer. get_per_commitment_point (
747- htlc_descriptor. per_commitment_number , & self . secp
748- ) ;
749- let witness_script = htlc_descriptor. witness_script ( & per_commitment_point, & self . secp ) ;
745+ let witness_script = htlc_descriptor. witness_script ( & self . secp ) ;
750746 htlc_tx. input [ idx] . witness = htlc_descriptor. tx_input_witness ( & htlc_sig, & witness_script) ;
751747 }
752748
0 commit comments