Skip to content

Commit 931d62d

Browse files
committed
Delete EcdsaChannelSigner::sign_counterparty_htlc_transaction
1 parent 014449c commit 931d62d

File tree

3 files changed

+41
-91
lines changed

3 files changed

+41
-91
lines changed

lightning/src/sign/ecdsa.rs

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use bitcoin::transaction::Transaction;
44

55
use bitcoin::secp256k1;
66
use bitcoin::secp256k1::ecdsa::Signature;
7-
use bitcoin::secp256k1::{PublicKey, Secp256k1};
7+
use bitcoin::secp256k1::Secp256k1;
88

9-
use crate::ln::chan_utils::{ClosingTransaction, CommitmentTransaction, HTLCOutputInCommitment};
9+
use crate::ln::chan_utils::{ClosingTransaction, CommitmentTransaction};
1010
use crate::ln::msgs::UnsignedChannelAnnouncement;
1111
use crate::types::payment::PaymentPreimage;
1212

@@ -54,35 +54,6 @@ pub trait EcdsaChannelSigner: ChannelSigner {
5454
&self, commitment_tx: &CommitmentTransaction, inbound_htlc_preimages: Vec<PaymentPreimage>,
5555
outbound_htlc_preimages: Vec<PaymentPreimage>, secp_ctx: &Secp256k1<secp256k1::All>,
5656
) -> Result<(Signature, Vec<Signature>), ()>;
57-
/// Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment
58-
/// transaction, either offered or received.
59-
///
60-
/// Such a transaction may claim multiples offered outputs at same time if we know the
61-
/// preimage for each when we create it, but only the input at index `input` should be
62-
/// signed for here. It may be called multiple times for same output(s) if a fee-bump is
63-
/// needed with regards to an upcoming timelock expiration.
64-
///
65-
/// `witness_script` is either an offered or received script as defined in BOLT3 for HTLC
66-
/// outputs.
67-
///
68-
/// `amount` is value of the output spent by this input, committed to in the BIP 143 signature.
69-
///
70-
/// `per_commitment_point` is the dynamic point corresponding to the channel state
71-
/// detected onchain. It has been generated by our counterparty and is used to derive
72-
/// channel state keys, which are then included in the witness script and committed to in the
73-
/// BIP 143 signature.
74-
///
75-
/// An `Err` can be returned to signal that the signer is unavailable/cannot produce a valid
76-
/// signature and should be retried later. Once the signer is ready to provide a signature after
77-
/// previously returning an `Err`, [`ChannelMonitor::signer_unblocked`] must be called on its
78-
/// monitor or [`ChainMonitor::signer_unblocked`] called to attempt unblocking all monitors.
79-
///
80-
/// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
81-
/// [`ChainMonitor::signer_unblocked`]: crate::chain::chainmonitor::ChainMonitor::signer_unblocked
82-
fn sign_counterparty_htlc_transaction(
83-
&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey,
84-
htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>,
85-
) -> Result<Signature, ()>;
8657
/// Create a signature for a (proposed) closing transaction.
8758
///
8859
/// Note that, due to rounding, there may be one "missing" satoshi, and either party may have

lightning/src/sign/mod.rs

Lines changed: 39 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -925,8 +925,31 @@ pub trait ChannelSigner {
925925
}
926926
}
927927

928-
/// Sweep a HTLC output on a counterparty commitment transaction. Sweep an offered htlc output if
929-
/// the preimage is provided, otherwise, sweep a received htlc output.
928+
/// Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment
929+
/// transaction, either offered or received.
930+
///
931+
/// Such a transaction may claim multiples offered outputs at same time if we know the
932+
/// preimage for each when we create it, but only the input at index `input` should be
933+
/// signed for here. It may be called multiple times for same output(s) if a fee-bump is
934+
/// needed with regards to an upcoming timelock expiration.
935+
///
936+
/// `witness_script` is either an offered or received script as defined in BOLT3 for HTLC
937+
/// outputs.
938+
///
939+
/// `amount` is value of the output spent by this input, committed to in the BIP 143 signature.
940+
///
941+
/// `per_commitment_point` is the dynamic point corresponding to the channel state
942+
/// detected onchain. It has been generated by our counterparty and is used to derive
943+
/// channel state keys, which are then included in the witness script and committed to in the
944+
/// BIP 143 signature.
945+
///
946+
/// An `Err` can be returned to signal that the signer is unavailable/cannot produce a valid
947+
/// signature and should be retried later. Once the signer is ready to provide a signature after
948+
/// previously returning an `Err`, [`ChannelMonitor::signer_unblocked`] must be called on its
949+
/// monitor or [`ChainMonitor::signer_unblocked`] called to attempt unblocking all monitors.
950+
///
951+
/// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
952+
/// [`ChainMonitor::signer_unblocked`]: crate::chain::chainmonitor::ChainMonitor::signer_unblocked
930953
fn sweep_counterparty_htlc_output(
931954
&self, sweep_tx: &Transaction, input: usize, amount: u64,
932955
secp_ctx: &Secp256k1<secp256k1::All>, per_commitment_point: &PublicKey,
@@ -1739,15 +1762,20 @@ impl ChannelSigner for InMemorySigner {
17391762
);
17401763
let witness_script =
17411764
chan_utils::get_htlc_redeemscript(htlc, params.channel_type_features(), &keys);
1742-
let sig = EcdsaChannelSigner::sign_counterparty_htlc_transaction(
1743-
self,
1744-
sweep_tx,
1745-
input,
1746-
amount,
1747-
per_commitment_point,
1748-
htlc,
1749-
secp_ctx,
1750-
)?;
1765+
let htlc_key =
1766+
chan_utils::derive_private_key(&secp_ctx, &per_commitment_point, &self.htlc_base_key);
1767+
let mut sighash_parts = sighash::SighashCache::new(sweep_tx);
1768+
let sighash = hash_to_message!(
1769+
&sighash_parts
1770+
.p2wsh_signature_hash(
1771+
input,
1772+
&witness_script,
1773+
Amount::from_sat(amount),
1774+
EcdsaSighashType::All
1775+
)
1776+
.unwrap()[..]
1777+
);
1778+
let sig = sign_with_aux_rand(secp_ctx, &sighash, &htlc_key, &self);
17511779
let ecdsa_sig = EcdsaSignature::sighash_all(sig);
17521780
let element = match preimage {
17531781
Some(ref p) => &p.0[..],
@@ -1904,47 +1932,6 @@ impl EcdsaChannelSigner for InMemorySigner {
19041932
Ok((commitment_sig, htlc_sigs))
19051933
}
19061934

1907-
fn sign_counterparty_htlc_transaction(
1908-
&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey,
1909-
htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>,
1910-
) -> Result<Signature, ()> {
1911-
let htlc_key =
1912-
chan_utils::derive_private_key(&secp_ctx, &per_commitment_point, &self.htlc_base_key);
1913-
let revocation_pubkey = RevocationKey::from_basepoint(
1914-
&secp_ctx,
1915-
&self.pubkeys().revocation_basepoint,
1916-
&per_commitment_point,
1917-
);
1918-
let counterparty_keys = self.counterparty_pubkeys().expect(MISSING_PARAMS_ERR);
1919-
let counterparty_htlcpubkey = HtlcKey::from_basepoint(
1920-
&secp_ctx,
1921-
&counterparty_keys.htlc_basepoint,
1922-
&per_commitment_point,
1923-
);
1924-
let htlc_basepoint = self.pubkeys().htlc_basepoint;
1925-
let htlcpubkey = HtlcKey::from_basepoint(&secp_ctx, &htlc_basepoint, &per_commitment_point);
1926-
let chan_type = self.channel_type_features().expect(MISSING_PARAMS_ERR);
1927-
let witness_script = chan_utils::get_htlc_redeemscript_with_explicit_keys(
1928-
&htlc,
1929-
chan_type,
1930-
&counterparty_htlcpubkey,
1931-
&htlcpubkey,
1932-
&revocation_pubkey,
1933-
);
1934-
let mut sighash_parts = sighash::SighashCache::new(htlc_tx);
1935-
let sighash = hash_to_message!(
1936-
&sighash_parts
1937-
.p2wsh_signature_hash(
1938-
input,
1939-
&witness_script,
1940-
Amount::from_sat(amount),
1941-
EcdsaSighashType::All
1942-
)
1943-
.unwrap()[..]
1944-
);
1945-
Ok(sign_with_aux_rand(secp_ctx, &sighash, &htlc_key, &self))
1946-
}
1947-
19481935
fn sign_closing_transaction(
19491936
&self, closing_tx: &ClosingTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
19501937
) -> Result<Signature, ()> {

lightning/src/util/test_channel_signer.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,6 @@ impl EcdsaChannelSigner for TestChannelSigner {
351351
Ok(self.inner.sign_counterparty_commitment(commitment_tx, inbound_htlc_preimages, outbound_htlc_preimages, secp_ctx).unwrap())
352352
}
353353

354-
fn sign_counterparty_htlc_transaction(&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
355-
#[cfg(test)]
356-
if !self.is_signer_available(SignerOp::SignCounterpartyHtlcTransaction) {
357-
return Err(());
358-
}
359-
Ok(EcdsaChannelSigner::sign_counterparty_htlc_transaction(&self.inner, htlc_tx, input, amount, per_commitment_point, htlc, secp_ctx).unwrap())
360-
}
361-
362354
fn sign_closing_transaction(&self, closing_tx: &ClosingTransaction, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
363355
#[cfg(test)]
364356
if !self.is_signer_available(SignerOp::SignClosingTransaction) {

0 commit comments

Comments
 (0)