Use sign_holder_htlc_transaction to sign non-anchors holder HTLCs
[rust-lightning] / lightning / src / ln / chan_utils.rs
index d1489e2716836f928d5bdc04450f3d8722d4fbc9..1c068025b8f0853340dfc54e89ba347411cdf20a 100644 (file)
@@ -1599,6 +1599,11 @@ impl CommitmentTransaction {
                self.commitment_number
        }
 
+       /// The per commitment point used by the broadcaster.
+       pub fn per_commitment_point(&self) -> PublicKey {
+               self.keys.per_commitment_point
+       }
+
        /// The value to be sent to the broadcaster
        pub fn to_broadcaster_value_sat(&self) -> u64 {
                self.to_broadcaster_value_sat
@@ -1720,26 +1725,40 @@ impl<'a> TrustedCommitmentTransaction<'a> {
                Ok(ret)
        }
 
-       /// Gets a signed HTLC transaction given a preimage (for !htlc.offered) and the holder HTLC transaction signature.
-       pub(crate) fn get_signed_htlc_tx(&self, channel_parameters: &DirectedChannelTransactionParameters, htlc_index: usize, counterparty_signature: &Signature, signature: &Signature, preimage: &Option<PaymentPreimage>) -> Transaction {
-               let inner = self.inner;
-               let keys = &inner.keys;
-               let txid = inner.built.txid;
-               let this_htlc = &inner.htlcs[htlc_index];
+       /// Builds the second-level holder HTLC transaction for the HTLC with index `htlc_index`.
+       pub(crate) fn build_unsigned_htlc_tx(
+               &self, channel_parameters: &DirectedChannelTransactionParameters, htlc_index: usize,
+               preimage: &Option<PaymentPreimage>,
+       ) -> Transaction {
+               let keys = &self.inner.keys;
+               let this_htlc = &self.inner.htlcs[htlc_index];
                assert!(this_htlc.transaction_output_index.is_some());
                // if we don't have preimage for an HTLC-Success, we can't generate an HTLC transaction.
                if !this_htlc.offered && preimage.is_none() { unreachable!(); }
                // Further, we should never be provided the preimage for an HTLC-Timeout transaction.
                if  this_htlc.offered && preimage.is_some() { unreachable!(); }
 
-               let mut htlc_tx = build_htlc_transaction(&txid, inner.feerate_per_kw, channel_parameters.contest_delay(), &this_htlc, &self.channel_type_features, &keys.broadcaster_delayed_payment_key, &keys.revocation_key);
+               build_htlc_transaction(
+                       &self.inner.built.txid, self.inner.feerate_per_kw, channel_parameters.contest_delay(), &this_htlc,
+                       &self.channel_type_features, &keys.broadcaster_delayed_payment_key, &keys.revocation_key
+               )
+       }
 
-               let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys(&this_htlc, &self.channel_type_features, &keys.broadcaster_htlc_key, &keys.countersignatory_htlc_key, &keys.revocation_key);
 
-               htlc_tx.input[0].witness = chan_utils::build_htlc_input_witness(
-                       signature, counterparty_signature, preimage, &htlc_redeemscript, &self.channel_type_features,
+       /// Builds the witness required to spend the input for the HTLC with index `htlc_index` in a
+       /// second-level holder HTLC transaction.
+       pub(crate) fn build_htlc_input_witness(
+               &self, htlc_index: usize, counterparty_signature: &Signature, signature: &Signature,
+               preimage: &Option<PaymentPreimage>
+       ) -> Witness {
+               let keys = &self.inner.keys;
+               let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys(
+                       &self.inner.htlcs[htlc_index], &self.channel_type_features, &keys.broadcaster_htlc_key,
+                       &keys.countersignatory_htlc_key, &keys.revocation_key
                );
-               htlc_tx
+               chan_utils::build_htlc_input_witness(
+                       signature, counterparty_signature, preimage, &htlc_redeemscript, &self.channel_type_features,
+               )
        }
 
        /// Returns the index of the revokeable output, i.e. the `to_local` output sending funds to