]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Support signing non-anchors HTLCs with HTLCDescriptor
authorWilmer Paulino <wilmer@wilmerpaulino.com>
Fri, 13 Oct 2023 20:49:50 +0000 (13:49 -0700)
committerWilmer Paulino <wilmer@wilmerpaulino.com>
Fri, 20 Oct 2023 18:03:01 +0000 (11:03 -0700)
We plan to use `EcdsaChannelSigner::sign_holder_htlc_transaction` to
also sign holder HTLC transactions on non-anchor outputs channels.
`HTLCDescriptor` was only used in an anchor outputs context, so a few
things needed changing, mostly to handle the different scripts and
feerate.

lightning/src/chain/channelmonitor.rs
lightning/src/events/bump_transaction.rs
lightning/src/sign/mod.rs

index bd0c15484283b5a12d0c815d13afb9310acb688e..acb735e151e672e579c09d095676f9cf643aed0a 100644 (file)
@@ -2835,6 +2835,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
                                                        per_commitment_point: self.onchain_tx_handler.signer.get_per_commitment_point(
                                                                htlc.per_commitment_number, &self.onchain_tx_handler.secp_ctx,
                                                        ),
+                                                       feerate_per_kw: 0,
                                                        htlc: htlc.htlc,
                                                        preimage: htlc.preimage,
                                                        counterparty_sig: htlc.counterparty_sig,
index 55c12d23e749cf020a7308f998ab686f28ea22d3..5d5161a67bb75f871eef675b37e41f8a5ede3389 100644 (file)
@@ -23,7 +23,6 @@ use crate::ln::chan_utils::{
        ANCHOR_INPUT_WITNESS_WEIGHT, HTLC_SUCCESS_INPUT_ANCHOR_WITNESS_WEIGHT,
        HTLC_TIMEOUT_INPUT_ANCHOR_WITNESS_WEIGHT, ChannelTransactionParameters, HTLCOutputInCommitment
 };
-use crate::ln::features::ChannelTypeFeatures;
 use crate::ln::PaymentPreimage;
 use crate::prelude::*;
 use crate::sign::{EcdsaChannelSigner, SignerProvider, WriteableEcdsaChannelSigner, P2WPKH_WITNESS_WEIGHT};
@@ -136,6 +135,10 @@ pub struct HTLCDescriptor {
        ///
        /// See <https://github.com/lightning/bolts/blob/master/03-transactions.md#keys> for more info.
        pub per_commitment_point: PublicKey,
+       /// The feerate to use on the HTLC claiming transaction. This is always `0` for HTLCs
+       /// originating from a channel supporting anchor outputs, otherwise it is the channel's
+       /// negotiated feerate at the time the commitment transaction was built.
+       pub feerate_per_kw: u32,
        /// The details of the HTLC as it appears in the commitment transaction.
        pub htlc: HTLCOutputInCommitment,
        /// The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be
@@ -146,13 +149,14 @@ pub struct HTLCDescriptor {
 }
 
 impl_writeable_tlv_based!(HTLCDescriptor, {
-    (0, channel_derivation_parameters, required),
-    (2, commitment_txid, required),
-    (4, per_commitment_number, required),
-    (6, per_commitment_point, required),
-    (8, htlc, required),
-    (10, preimage, option),
-    (12, counterparty_sig, required),
+       (0, channel_derivation_parameters, required),
+       (1, feerate_per_kw, (default_value, 0)),
+       (2, commitment_txid, required),
+       (4, per_commitment_number, required),
+       (6, per_commitment_point, required),
+       (8, htlc, required),
+       (10, preimage, option),
+       (12, counterparty_sig, required),
 });
 
 impl HTLCDescriptor {
@@ -177,7 +181,9 @@ impl HTLCDescriptor {
        /// Returns the unsigned transaction input spending the HTLC output in the commitment
        /// transaction.
        pub fn unsigned_tx_input(&self) -> TxIn {
-               chan_utils::build_htlc_input(&self.commitment_txid, &self.htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies())
+               chan_utils::build_htlc_input(
+                       &self.commitment_txid, &self.htlc, &self.channel_derivation_parameters.transaction_parameters.channel_type_features
+               )
        }
 
        /// Returns the delayed output created as a result of spending the HTLC output in the commitment
@@ -193,8 +199,8 @@ impl HTLCDescriptor {
                        secp, &self.per_commitment_point, &counterparty_keys.revocation_basepoint
                );
                chan_utils::build_htlc_output(
-                       0 /* feerate_per_kw */, channel_params.contest_delay(), &self.htlc,
-                       &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &broadcaster_delayed_key, &counterparty_revocation_key
+                       self.feerate_per_kw, channel_params.contest_delay(), &self.htlc,
+                       channel_params.channel_type_features(), &broadcaster_delayed_key, &counterparty_revocation_key
                )
        }
 
@@ -213,7 +219,7 @@ impl HTLCDescriptor {
                        secp, &self.per_commitment_point, &counterparty_keys.revocation_basepoint
                );
                chan_utils::get_htlc_redeemscript_with_explicit_keys(
-                       &self.htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &broadcaster_htlc_key, &counterparty_htlc_key,
+                       &self.htlc, channel_params.channel_type_features(), &broadcaster_htlc_key, &counterparty_htlc_key,
                        &counterparty_revocation_key,
                )
        }
@@ -222,7 +228,8 @@ impl HTLCDescriptor {
        /// transaction.
        pub fn tx_input_witness(&self, signature: &Signature, witness_script: &Script) -> Witness {
                chan_utils::build_htlc_input_witness(
-                       signature, &self.counterparty_sig, &self.preimage, witness_script, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies() /* opt_anchors */
+                       signature, &self.counterparty_sig, &self.preimage, witness_script,
+                       &self.channel_derivation_parameters.transaction_parameters.channel_type_features
                )
        }
 
index 04c4446e2c0c8c75bd4f2f7e3b415b8f35296cf2..d9992585819db48a9ec2b799681d1b2fef0ceaee 100644 (file)
@@ -552,9 +552,7 @@ pub trait EcdsaChannelSigner: ChannelSigner {
                secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()>;
        /// Computes the signature for a commitment transaction's HTLC output used as an input within
        /// `htlc_tx`, which spends the commitment transaction at index `input`. The signature returned
-       /// must be be computed using [`EcdsaSighashType::All`]. Note that this should only be used to
-       /// sign HTLC transactions from channels supporting anchor outputs after all additional
-       /// inputs/outputs have been added to the transaction.
+       /// must be be computed using [`EcdsaSighashType::All`].
        ///
        /// [`EcdsaSighashType::All`]: bitcoin::blockdata::transaction::EcdsaSighashType::All
        fn sign_holder_htlc_transaction(&self, htlc_tx: &Transaction, input: usize,