Skip to content

Commit fc2a45e

Browse files
committed
Delete EcdsaChannelSigner::sign_counterparty_htlc_transaction
1 parent 5f27ad7 commit fc2a45e

File tree

3 files changed

+42
-92
lines changed

3 files changed

+42
-92
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: 40 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ use crate::ln::chan_utils::{
5353
};
5454
use crate::ln::channel::ANCHOR_OUTPUT_VALUE_SATOSHI;
5555
use crate::ln::channel_keys::{
56-
add_public_key_tweak, DelayedPaymentBasepoint, DelayedPaymentKey, HtlcBasepoint, HtlcKey,
56+
add_public_key_tweak, DelayedPaymentBasepoint, DelayedPaymentKey, HtlcBasepoint,
5757
RevocationBasepoint, RevocationKey,
5858
};
5959
use crate::ln::inbound_payment::ExpandedKey;
@@ -888,8 +888,31 @@ pub trait ChannelSigner {
888888
}
889889
}
890890

891-
/// Sweep a HTLC output on a counterparty commitment transaction. Sweep an offered htlc output if
892-
/// the preimage is provided, otherwise, sweep a received htlc output.
891+
/// Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment
892+
/// transaction, either offered or received.
893+
///
894+
/// Such a transaction may claim multiples offered outputs at same time if we know the
895+
/// preimage for each when we create it, but only the input at index `input` should be
896+
/// signed for here. It may be called multiple times for same output(s) if a fee-bump is
897+
/// needed with regards to an upcoming timelock expiration.
898+
///
899+
/// `witness_script` is either an offered or received script as defined in BOLT3 for HTLC
900+
/// outputs.
901+
///
902+
/// `amount` is value of the output spent by this input, committed to in the BIP 143 signature.
903+
///
904+
/// `per_commitment_point` is the dynamic point corresponding to the channel state
905+
/// detected onchain. It has been generated by our counterparty and is used to derive
906+
/// channel state keys, which are then included in the witness script and committed to in the
907+
/// BIP 143 signature.
908+
///
909+
/// An `Err` can be returned to signal that the signer is unavailable/cannot produce a valid
910+
/// signature and should be retried later. Once the signer is ready to provide a signature after
911+
/// previously returning an `Err`, [`ChannelMonitor::signer_unblocked`] must be called on its
912+
/// monitor or [`ChainMonitor::signer_unblocked`] called to attempt unblocking all monitors.
913+
///
914+
/// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
915+
/// [`ChainMonitor::signer_unblocked`]: crate::chain::chainmonitor::ChainMonitor::signer_unblocked
893916
fn sweep_counterparty_htlc_output(
894917
&self, sweep_tx: &Transaction, input: usize, amount: u64,
895918
secp_ctx: &Secp256k1<secp256k1::All>, per_commitment_point: &PublicKey,
@@ -1702,15 +1725,20 @@ impl ChannelSigner for InMemorySigner {
17021725
);
17031726
let witness_script =
17041727
chan_utils::get_htlc_redeemscript(htlc, params.channel_type_features(), &keys);
1705-
let sig = EcdsaChannelSigner::sign_counterparty_htlc_transaction(
1706-
self,
1707-
sweep_tx,
1708-
input,
1709-
amount,
1710-
per_commitment_point,
1711-
htlc,
1712-
secp_ctx,
1713-
)?;
1728+
let htlc_key =
1729+
chan_utils::derive_private_key(&secp_ctx, &per_commitment_point, &self.htlc_base_key);
1730+
let mut sighash_parts = sighash::SighashCache::new(sweep_tx);
1731+
let sighash = hash_to_message!(
1732+
&sighash_parts
1733+
.p2wsh_signature_hash(
1734+
input,
1735+
&witness_script,
1736+
Amount::from_sat(amount),
1737+
EcdsaSighashType::All
1738+
)
1739+
.unwrap()[..]
1740+
);
1741+
let sig = sign_with_aux_rand(secp_ctx, &sighash, &htlc_key, &self);
17141742
let ecdsa_sig = EcdsaSignature::sighash_all(sig);
17151743
let element = match preimage {
17161744
Some(ref p) => &p.0[..],
@@ -1878,47 +1906,6 @@ impl EcdsaChannelSigner for InMemorySigner {
18781906
Ok((commitment_sig, htlc_sigs))
18791907
}
18801908

1881-
fn sign_counterparty_htlc_transaction(
1882-
&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey,
1883-
htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>,
1884-
) -> Result<Signature, ()> {
1885-
let htlc_key =
1886-
chan_utils::derive_private_key(&secp_ctx, &per_commitment_point, &self.htlc_base_key);
1887-
let revocation_pubkey = RevocationKey::from_basepoint(
1888-
&secp_ctx,
1889-
&self.pubkeys().revocation_basepoint,
1890-
&per_commitment_point,
1891-
);
1892-
let counterparty_keys = self.counterparty_pubkeys().expect(MISSING_PARAMS_ERR);
1893-
let counterparty_htlcpubkey = HtlcKey::from_basepoint(
1894-
&secp_ctx,
1895-
&counterparty_keys.htlc_basepoint,
1896-
&per_commitment_point,
1897-
);
1898-
let htlc_basepoint = self.pubkeys().htlc_basepoint;
1899-
let htlcpubkey = HtlcKey::from_basepoint(&secp_ctx, &htlc_basepoint, &per_commitment_point);
1900-
let chan_type = self.channel_type_features().expect(MISSING_PARAMS_ERR);
1901-
let witness_script = chan_utils::get_htlc_redeemscript_with_explicit_keys(
1902-
&htlc,
1903-
chan_type,
1904-
&counterparty_htlcpubkey,
1905-
&htlcpubkey,
1906-
&revocation_pubkey,
1907-
);
1908-
let mut sighash_parts = sighash::SighashCache::new(htlc_tx);
1909-
let sighash = hash_to_message!(
1910-
&sighash_parts
1911-
.p2wsh_signature_hash(
1912-
input,
1913-
&witness_script,
1914-
Amount::from_sat(amount),
1915-
EcdsaSighashType::All
1916-
)
1917-
.unwrap()[..]
1918-
);
1919-
Ok(sign_with_aux_rand(secp_ctx, &sighash, &htlc_key, &self))
1920-
}
1921-
19221909
fn sign_closing_transaction(
19231910
&self, closing_tx: &ClosingTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
19241911
) -> Result<Signature, ()> {

lightning/src/util/test_channel_signer.rs

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

361-
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, ()> {
362-
#[cfg(test)]
363-
if !self.is_signer_available(SignerOp::SignCounterpartyHtlcTransaction) {
364-
return Err(());
365-
}
366-
Ok(EcdsaChannelSigner::sign_counterparty_htlc_transaction(&self.inner, htlc_tx, input, amount, per_commitment_point, htlc, secp_ctx).unwrap())
367-
}
368-
369361
fn sign_closing_transaction(&self, closing_tx: &ClosingTransaction, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
370362
#[cfg(test)]
371363
if !self.is_signer_available(SignerOp::SignClosingTransaction) {

0 commit comments

Comments
 (0)