Skip to content

Commit 83676f7

Browse files
committed
Support signing non-anchors HTLCs with HTLCDescriptor
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.
1 parent b1d3aa8 commit 83676f7

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

lightning/src/chain/channelmonitor.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2835,6 +2835,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
28352835
per_commitment_point: self.onchain_tx_handler.signer.get_per_commitment_point(
28362836
htlc.per_commitment_number, &self.onchain_tx_handler.secp_ctx,
28372837
),
2838+
feerate_per_kw: 0,
28382839
htlc: htlc.htlc,
28392840
preimage: htlc.preimage,
28402841
counterparty_sig: htlc.counterparty_sig,

lightning/src/events/bump_transaction.rs

+20-13
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use crate::ln::chan_utils::{
2323
ANCHOR_INPUT_WITNESS_WEIGHT, HTLC_SUCCESS_INPUT_ANCHOR_WITNESS_WEIGHT,
2424
HTLC_TIMEOUT_INPUT_ANCHOR_WITNESS_WEIGHT, ChannelTransactionParameters, HTLCOutputInCommitment
2525
};
26-
use crate::ln::features::ChannelTypeFeatures;
2726
use crate::ln::PaymentPreimage;
2827
use crate::prelude::*;
2928
use crate::sign::{EcdsaChannelSigner, SignerProvider, WriteableEcdsaChannelSigner, P2WPKH_WITNESS_WEIGHT};
@@ -136,6 +135,10 @@ pub struct HTLCDescriptor {
136135
///
137136
/// See <https://github.com/lightning/bolts/blob/master/03-transactions.md#keys> for more info.
138137
pub per_commitment_point: PublicKey,
138+
/// The feerate to use on the HTLC claiming transaction. This is always `0` for HTLCs
139+
/// originating from a channel supporting anchor outputs, otherwise it is the same as the
140+
/// commitment transaction's feerate.
141+
pub feerate_per_kw: u32,
139142
/// The details of the HTLC as it appears in the commitment transaction.
140143
pub htlc: HTLCOutputInCommitment,
141144
/// The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be
@@ -146,13 +149,14 @@ pub struct HTLCDescriptor {
146149
}
147150

148151
impl_writeable_tlv_based!(HTLCDescriptor, {
149-
(0, channel_derivation_parameters, required),
150-
(2, commitment_txid, required),
151-
(4, per_commitment_number, required),
152-
(6, per_commitment_point, required),
153-
(8, htlc, required),
154-
(10, preimage, option),
155-
(12, counterparty_sig, required),
152+
(0, channel_derivation_parameters, required),
153+
(1, feerate_per_kw, (default_value, 0)),
154+
(2, commitment_txid, required),
155+
(4, per_commitment_number, required),
156+
(6, per_commitment_point, required),
157+
(8, htlc, required),
158+
(10, preimage, option),
159+
(12, counterparty_sig, required),
156160
});
157161

158162
impl HTLCDescriptor {
@@ -177,7 +181,9 @@ impl HTLCDescriptor {
177181
/// Returns the unsigned transaction input spending the HTLC output in the commitment
178182
/// transaction.
179183
pub fn unsigned_tx_input(&self) -> TxIn {
180-
chan_utils::build_htlc_input(&self.commitment_txid, &self.htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies())
184+
chan_utils::build_htlc_input(
185+
&self.commitment_txid, &self.htlc, &self.channel_derivation_parameters.transaction_parameters.channel_type_features
186+
)
181187
}
182188

183189
/// Returns the delayed output created as a result of spending the HTLC output in the commitment
@@ -193,8 +199,8 @@ impl HTLCDescriptor {
193199
secp, &self.per_commitment_point, &counterparty_keys.revocation_basepoint
194200
);
195201
chan_utils::build_htlc_output(
196-
0 /* feerate_per_kw */, channel_params.contest_delay(), &self.htlc,
197-
&ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &broadcaster_delayed_key, &counterparty_revocation_key
202+
self.feerate_per_kw, channel_params.contest_delay(), &self.htlc,
203+
channel_params.channel_type_features(), &broadcaster_delayed_key, &counterparty_revocation_key
198204
)
199205
}
200206

@@ -213,7 +219,7 @@ impl HTLCDescriptor {
213219
secp, &self.per_commitment_point, &counterparty_keys.revocation_basepoint
214220
);
215221
chan_utils::get_htlc_redeemscript_with_explicit_keys(
216-
&self.htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &broadcaster_htlc_key, &counterparty_htlc_key,
222+
&self.htlc, channel_params.channel_type_features(), &broadcaster_htlc_key, &counterparty_htlc_key,
217223
&counterparty_revocation_key,
218224
)
219225
}
@@ -222,7 +228,8 @@ impl HTLCDescriptor {
222228
/// transaction.
223229
pub fn tx_input_witness(&self, signature: &Signature, witness_script: &Script) -> Witness {
224230
chan_utils::build_htlc_input_witness(
225-
signature, &self.counterparty_sig, &self.preimage, witness_script, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies() /* opt_anchors */
231+
signature, &self.counterparty_sig, &self.preimage, witness_script,
232+
&self.channel_derivation_parameters.transaction_parameters.channel_type_features
226233
)
227234
}
228235

lightning/src/sign/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,7 @@ pub trait EcdsaChannelSigner: ChannelSigner {
552552
secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()>;
553553
/// Computes the signature for a commitment transaction's HTLC output used as an input within
554554
/// `htlc_tx`, which spends the commitment transaction at index `input`. The signature returned
555-
/// must be be computed using [`EcdsaSighashType::All`]. Note that this should only be used to
556-
/// sign HTLC transactions from channels supporting anchor outputs after all additional
557-
/// inputs/outputs have been added to the transaction.
555+
/// must be be computed using [`EcdsaSighashType::All`].
558556
///
559557
/// [`EcdsaSighashType::All`]: bitcoin::blockdata::transaction::EcdsaSighashType::All
560558
fn sign_holder_htlc_transaction(&self, htlc_tx: &Transaction, input: usize,

0 commit comments

Comments
 (0)