@@ -93,6 +93,12 @@ pub struct HTLCDescriptor {
93
93
pub commitment_txid : Txid ,
94
94
/// The number of the commitment transaction in which the HTLC output lives.
95
95
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 ,
96
102
/// The details of the HTLC as it appears in the commitment transaction.
97
103
pub htlc : HTLCOutputInCommitment ,
98
104
/// The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be
@@ -111,17 +117,15 @@ impl HTLCDescriptor {
111
117
112
118
/// Returns the delayed output created as a result of spending the HTLC output in the commitment
113
119
/// 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 {
117
121
let channel_params = self . channel_parameters . as_holder_broadcastable ( ) ;
118
122
let broadcaster_keys = channel_params. broadcaster_pubkeys ( ) ;
119
123
let counterparty_keys = channel_params. countersignatory_pubkeys ( ) ;
120
124
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
122
126
) ;
123
127
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
125
129
) ;
126
130
chan_utils:: build_htlc_output (
127
131
0 /* feerate_per_kw */ , channel_params. contest_delay ( ) , & self . htlc ,
@@ -130,20 +134,18 @@ impl HTLCDescriptor {
130
134
}
131
135
132
136
/// 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 {
136
138
let channel_params = self . channel_parameters . as_holder_broadcastable ( ) ;
137
139
let broadcaster_keys = channel_params. broadcaster_pubkeys ( ) ;
138
140
let counterparty_keys = channel_params. countersignatory_pubkeys ( ) ;
139
141
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
141
143
) ;
142
144
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
144
146
) ;
145
147
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
147
149
) ;
148
150
chan_utils:: get_htlc_redeemscript_with_explicit_keys (
149
151
& self . htlc , & ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies ( ) , & broadcaster_htlc_key, & counterparty_htlc_key,
@@ -696,15 +698,12 @@ where
696
698
let mut signers = HashMap :: new ( ) ;
697
699
let mut must_spend = Vec :: with_capacity ( htlc_descriptors. len ( ) ) ;
698
700
for htlc_descriptor in htlc_descriptors {
699
- let signer = signers. entry ( htlc_descriptor. channel_keys_id )
701
+ signers. entry ( htlc_descriptor. channel_keys_id )
700
702
. or_insert_with ( ||
701
703
self . signer_provider . derive_channel_signer (
702
704
htlc_descriptor. channel_value_satoshis , htlc_descriptor. channel_keys_id ,
703
705
)
704
706
) ;
705
- let per_commitment_point = signer. get_per_commitment_point (
706
- htlc_descriptor. per_commitment_number , & self . secp
707
- ) ;
708
707
709
708
let htlc_input = htlc_descriptor. unsigned_tx_input ( ) ;
710
709
must_spend. push ( Input {
@@ -716,7 +715,7 @@ where
716
715
} ,
717
716
} ) ;
718
717
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 ) ;
720
719
tx. output . push ( htlc_output) ;
721
720
}
722
721
@@ -743,10 +742,7 @@ where
743
742
let htlc_sig = signer. sign_holder_htlc_transaction (
744
743
& htlc_tx, idx, htlc_descriptor, & self . secp
745
744
) ?;
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 ) ;
750
746
htlc_tx. input [ idx] . witness = htlc_descriptor. tx_input_witness ( & htlc_sig, & witness_script) ;
751
747
}
752
748
0 commit comments