Skip to content

Commit

Permalink
Delete EcdsaChannelSigner::sign_holder_anchor_input
Browse files Browse the repository at this point in the history
  • Loading branch information
tankyleo committed Jan 15, 2025
1 parent b17f61b commit 3d1aa57
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 57 deletions.
13 changes: 5 additions & 8 deletions lightning/src/events/bump_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,9 @@ pub enum BumpTransactionEvent {
/// broadcast first, as the child anchor transaction depends on it.
///
/// The consumer should be able to sign for any of the additional inputs included within the
/// child anchor transaction. To sign its anchor input, an [`EcdsaChannelSigner`] should be
/// re-derived through [`AnchorDescriptor::derive_channel_signer`]. The anchor input signature
/// can be computed with [`EcdsaChannelSigner::sign_holder_anchor_input`], which can then be
/// provided to [`build_anchor_input_witness`] along with the `funding_pubkey` to obtain the
/// full witness required to spend.
/// child anchor transaction. To sign its anchor input, a [`ChannelSigner`] should be
/// re-derived through [`AnchorDescriptor::derive_channel_signer`]. The anchor input witness
/// can be computed with [`ChannelSigner::spend_holder_anchor_output`].
///
/// It is possible to receive more than one instance of this event if a valid child anchor
/// transaction is never broadcast or is but not with a sufficient fee to be mined. Care should
Expand All @@ -142,9 +140,8 @@ pub enum BumpTransactionEvent {
/// an empty `pending_htlcs`), confirmation of the commitment transaction can be considered to
/// be not urgent.
///
/// [`EcdsaChannelSigner`]: crate::sign::ecdsa::EcdsaChannelSigner
/// [`EcdsaChannelSigner::sign_holder_anchor_input`]: crate::sign::ecdsa::EcdsaChannelSigner::sign_holder_anchor_input
/// [`build_anchor_input_witness`]: crate::ln::chan_utils::build_anchor_input_witness
/// [`ChannelSigner`]: crate::sign::ChannelSigner
/// [`ChannelSigner::spend_holder_anchor_output`]: crate::sign::ChannelSigner::spend_holder_anchor_output
ChannelClose {
/// The `channel_id` of the channel which has been closed.
channel_id: ChannelId,
Expand Down
13 changes: 0 additions & 13 deletions lightning/src/sign/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,6 @@ pub trait EcdsaChannelSigner: ChannelSigner {
fn sign_closing_transaction(
&self, closing_tx: &ClosingTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
) -> Result<Signature, ()>;
/// Computes the signature for a commitment transaction's anchor output used as an
/// input within `anchor_tx`, which spends the commitment transaction, at index `input`.
///
/// An `Err` can be returned to signal that the signer is unavailable/cannot produce a valid
/// signature and should be retried later. Once the signer is ready to provide a signature after
/// previously returning an `Err`, [`ChannelMonitor::signer_unblocked`] must be called on its
/// monitor or [`ChainMonitor::signer_unblocked`] called to attempt unblocking all monitors.
///
/// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
/// [`ChainMonitor::signer_unblocked`]: crate::chain::chainmonitor::ChainMonitor::signer_unblocked
fn sign_holder_anchor_input(
&self, anchor_tx: &Transaction, input: usize, secp_ctx: &Secp256k1<secp256k1::All>,
) -> Result<Signature, ()>;
/// Signs a channel announcement message with our funding key proving it comes from one of the
/// channel participants.
///
Expand Down
44 changes: 23 additions & 21 deletions lightning/src/sign/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,16 @@ pub trait ChannelSigner {
}
}

/// Spend the holder anchor output
/// Computes the signature for a commitment transaction's anchor output used as an
/// input within `anchor_tx`, which spends the commitment transaction, at index `input`.
///
/// An `Err` can be returned to signal that the signer is unavailable/cannot produce a valid
/// signature and should be retried later. Once the signer is ready to provide a signature after
/// previously returning an `Err`, [`ChannelMonitor::signer_unblocked`] must be called on its
/// monitor or [`ChainMonitor::signer_unblocked`] called to attempt unblocking all monitors.
///
/// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
/// [`ChainMonitor::signer_unblocked`]: crate::chain::chainmonitor::ChainMonitor::signer_unblocked
fn spend_holder_anchor_output(
&self, anchor_tx: &Transaction, input_idx: usize, secp_ctx: &Secp256k1<secp256k1::All>,
) -> Result<Witness, ()>;
Expand Down Expand Up @@ -1855,10 +1864,19 @@ impl ChannelSigner for InMemorySigner {
fn spend_holder_anchor_output(
&self, anchor_tx: &Transaction, input_idx: usize, secp_ctx: &Secp256k1<secp256k1::All>,
) -> Result<Witness, ()> {
let anchor_sig =
EcdsaChannelSigner::sign_holder_anchor_input(self, anchor_tx, input_idx, secp_ctx)?;
let funding_pubkey = self.pubkeys().funding_pubkey;
Ok(chan_utils::build_anchor_input_witness(&funding_pubkey, &anchor_sig))
let funding_pubkey = &self.pubkeys().funding_pubkey;
let witness_script = chan_utils::get_anchor_redeemscript(funding_pubkey);
let sighash = sighash::SighashCache::new(anchor_tx)
.p2wsh_signature_hash(
input_idx,
&witness_script,
Amount::from_sat(ANCHOR_OUTPUT_VALUE_SATOSHI),
EcdsaSighashType::All,
)
.unwrap();
let sig =
sign_with_aux_rand(secp_ctx, &hash_to_message!(&sighash[..]), &self.funding_key, &self);
Ok(chan_utils::build_anchor_input_witness(funding_pubkey, &sig))
}
}

Expand Down Expand Up @@ -1948,22 +1966,6 @@ impl EcdsaChannelSigner for InMemorySigner {
))
}

fn sign_holder_anchor_input(
&self, anchor_tx: &Transaction, input: usize, secp_ctx: &Secp256k1<secp256k1::All>,
) -> Result<Signature, ()> {
let witness_script =
chan_utils::get_anchor_redeemscript(&self.holder_channel_pubkeys.funding_pubkey);
let sighash = sighash::SighashCache::new(&*anchor_tx)
.p2wsh_signature_hash(
input,
&witness_script,
Amount::from_sat(ANCHOR_OUTPUT_VALUE_SATOSHI),
EcdsaSighashType::All,
)
.unwrap();
Ok(sign_with_aux_rand(secp_ctx, &hash_to_message!(&sighash[..]), &self.funding_key, &self))
}

fn sign_channel_announcement_with_funding_key(
&self, msg: &UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<secp256k1::All>,
) -> Result<Signature, ()> {
Expand Down
15 changes: 0 additions & 15 deletions lightning/src/util/test_channel_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// You may not use this file except in accordance with one or both of these
// licenses.

use crate::ln::channel::{ANCHOR_OUTPUT_VALUE_SATOSHI, MIN_CHAN_DUST_LIMIT_SATOSHIS};
use crate::ln::chan_utils::{HTLCOutputInCommitment, ChannelPublicKeys, HolderCommitmentTransaction, CommitmentTransaction, ChannelTransactionParameters, TrustedCommitmentTransaction, ClosingTransaction};
use crate::ln::channel_keys::{HtlcKey};
use crate::ln::msgs;
Expand Down Expand Up @@ -361,20 +360,6 @@ impl EcdsaChannelSigner for TestChannelSigner {
Ok(self.inner.sign_closing_transaction(closing_tx, secp_ctx).unwrap())
}

fn sign_holder_anchor_input(
&self, anchor_tx: &Transaction, input: usize, secp_ctx: &Secp256k1<secp256k1::All>,
) -> Result<Signature, ()> {
debug_assert!(MIN_CHAN_DUST_LIMIT_SATOSHIS > ANCHOR_OUTPUT_VALUE_SATOSHI);
// As long as our minimum dust limit is enforced and is greater than our anchor output
// value, an anchor output can only have an index within [0, 1].
assert!(anchor_tx.input[input].previous_output.vout == 0 || anchor_tx.input[input].previous_output.vout == 1);
#[cfg(test)]
if !self.is_signer_available(SignerOp::SignHolderAnchorInput) {
return Err(());
}
EcdsaChannelSigner::sign_holder_anchor_input(&self.inner, anchor_tx, input, secp_ctx)
}

fn sign_channel_announcement_with_funding_key(
&self, msg: &msgs::UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<secp256k1::All>
) -> Result<Signature, ()> {
Expand Down

0 comments on commit 3d1aa57

Please sign in to comment.