What changed, and why it matters
This commit is a routine internal code cleanup in the Lightning Dev Kit's Rust implementation. It removes a wrapper type called ChannelSignerType that previously distinguished between different kinds of channel signers, because the project now plans to support only one signer type (ECDSA). The change simplifies function signatures and removes now-unnecessary pattern matching, but does not fix a security bug or change cryptographic behavior.
No security action required. Treat as normal maintenance/refactoring. Reviewers may optionally verify that all signer access sites compile and tests pass, which the diff strongly suggests they do.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit deletes lightning/src/sign/type_resolver.rs and removes all uses of ChannelSignerType
Changed components
lightning/src/ln/channel.rslightning/src/ln/async_signer_tests.rslightning/src/ln/functional_test_utils.rslightning/src/ln/functional_tests.rslightning/src/ln/htlc_reserve_unit_tests.rslightning/src/ln/update_fee_tests.rslightning/src/sign/mod.rslightning/src/sign/type_resolver.rsInspect captured patch +192 / −241
diff --git a/lightning/src/ln/async_signer_tests.rs b/lightning/src/ln/async_signer_tests.rs
index 451af39..b9e5763 100644
--- a/lightning/src/ln/async_signer_tests.rs
+++ b/lightning/src/ln/async_signer_tests.rs
@@ -1246,7 +1246,7 @@ fn do_test_closing_signed(extra_closing_signed: bool, reconnect: bool) {
let channel = chan_lock.channel_by_id.get_mut(&chan_id).unwrap();
let (funding, context) = channel.funding_and_context_mut();
- let signer = context.get_mut_signer().as_mut_ecdsa().unwrap();
+ let signer = context.get_mut_signer();
let signature = signer
.sign_closing_transaction(
&funding.channel_transaction_parameters,
diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs
index b939c3d..353bfaf 100644
--- a/lightning/src/ln/channel.rs
+++ b/lightning/src/ln/channel.rs
@@ -91,7 +91,6 @@ use alloc::collections::{btree_map, BTreeMap};
use crate::io;
use crate::prelude::*;
-use crate::sign::type_resolver::ChannelSignerType;
#[cfg(any(test, fuzzing, debug_assertions))]
use crate::sync::Mutex;
use core::time::Duration;
@@ -1286,14 +1285,14 @@ struct HolderCommitmentPoint {
impl HolderCommitmentPoint {
#[rustfmt::skip]
- pub fn new<SP: SignerProvider>(signer: &ChannelSignerType<SP>, secp_ctx: &Secp256k1<secp256k1::All>) -> Option<Self> {
+ pub fn new<S: ChannelSigner>(signer: &S, secp_ctx: &Secp256k1<secp256k1::All>) -> Option<Self> {
Some(HolderCommitmentPoint {
next_transaction_number: INITIAL_COMMITMENT_NUMBER,
previous_revoked_point: None,
last_revoked_point: None,
current_point: None,
- next_point: signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER, secp_ctx).ok()?,
- pending_next_point: signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, secp_ctx).ok(),
+ next_point: signer.get_per_commitment_point(INITIAL_COMMITMENT_NUMBER, secp_ctx).ok()?,
+ pending_next_point: signer.get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, secp_ctx).ok(),
})
}
@@ -1327,13 +1326,12 @@ impl HolderCommitmentPoint {
/// If we are pending advancing the next commitment point, this method tries asking the signer
/// again.
- pub fn try_resolve_pending<SP: SignerProvider, L: Logger>(
- &mut self, signer: &ChannelSignerType<SP>, secp_ctx: &Secp256k1<secp256k1::All>, logger: &L,
+ pub fn try_resolve_pending<S: ChannelSigner, L: Logger>(
+ &mut self, signer: &S, secp_ctx: &Secp256k1<secp256k1::All>, logger: &L,
) {
if !self.can_advance() {
- let pending_next_point = signer
- .as_ref()
- .get_per_commitment_point(self.next_transaction_number - 1, secp_ctx);
+ let pending_next_point =
+ signer.get_per_commitment_point(self.next_transaction_number - 1, secp_ctx);
if let Ok(point) = pending_next_point {
log_trace!(
logger,
@@ -1361,8 +1359,8 @@ impl HolderCommitmentPoint {
///
/// If our signer is ready to provide the next commitment point, the next call to `advance` will
/// succeed.
- pub fn advance<SP: SignerProvider, L: Logger>(
- &mut self, signer: &ChannelSignerType<SP>, secp_ctx: &Secp256k1<secp256k1::All>, logger: &L,
+ pub fn advance<S: ChannelSigner, L: Logger>(
+ &mut self, signer: &S, secp_ctx: &Secp256k1<secp256k1::All>, logger: &L,
) -> Result<(), ()> {
if let Some(next_point) = self.pending_next_point {
*self = Self {
@@ -2222,14 +2220,12 @@ where
let shared_input_signature =
if let Some(splice_input_index) = signing_session.unsigned_tx().shared_input_index() {
- let sig = match &context.holder_signer {
- ChannelSignerType::Ecdsa(signer) => signer.sign_splice_shared_input(
- &funding.channel_transaction_parameters,
- tx,
- splice_input_index as usize,
- &context.secp_ctx,
- ),
- };
+ let sig = context.holder_signer.sign_splice_shared_input(
+ &funding.channel_transaction_parameters,
+ tx,
+ splice_input_index as usize,
+ &context.secp_ctx,
+ );
Some(sig)
} else {
None
@@ -3057,7 +3053,6 @@ impl<'a> From<&'a Transaction> for ConfirmedTransaction<'a> {
}
/// Contains everything about the channel including state, and various flags.
-#[cfg_attr(test, derive(Debug))]
pub(super) struct ChannelContext<SP: SignerProvider> {
config: LegacyChannelConfig,
@@ -3093,7 +3088,7 @@ pub(super) struct ChannelContext<SP: SignerProvider> {
latest_monitor_update_id: u64,
- holder_signer: ChannelSignerType<SP>,
+ holder_signer: SP::EcdsaSigner,
shutdown_scriptpubkey: Option<ShutdownScript>,
destination_script: ScriptBuf,
@@ -3346,6 +3341,13 @@ pub(super) struct ChannelContext<SP: SignerProvider> {
pub interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
}
+#[cfg(test)]
+impl<SP: SignerProvider> fmt::Debug for ChannelContext<SP> {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.debug_struct("ChannelContext").finish()
+ }
+}
+
/// A channel struct implementing this trait can receive an initial counterparty commitment
/// transaction signature.
trait InitialRemoteCommitmentReceiver<SP: SignerProvider> {
@@ -3421,7 +3423,7 @@ trait InitialRemoteCommitmentReceiver<SP: SignerProvider> {
&self.funding().counterparty_funding_pubkey()
);
- if context.holder_signer.as_ref().validate_holder_commitment(&holder_commitment_tx, Vec::new()).is_err() {
+ if context.holder_signer.validate_holder_commitment(&holder_commitment_tx, Vec::new()).is_err() {
return Err(ChannelError::close("Failed to validate our commitment".to_owned()));
}
@@ -3782,7 +3784,7 @@ impl<SP: SignerProvider> ChannelContext<SP> {
latest_monitor_update_id: 0,
- holder_signer: ChannelSignerType::Ecdsa(holder_signer),
+ holder_signer,
shutdown_scriptpubkey,
destination_script,
@@ -4027,7 +4029,7 @@ impl<SP: SignerProvider> ChannelContext<SP> {
latest_monitor_update_id: 0,
- holder_signer: ChannelSignerType::Ecdsa(holder_signer),
+ holder_signer,
shutdown_scriptpubkey,
destination_script,
@@ -4342,7 +4344,7 @@ impl<SP: SignerProvider> ChannelContext<SP> {
/// Returns the holder signer for this channel.
#[cfg(any(test, feature = "_test_utils"))]
- pub fn get_mut_signer(&mut self) -> &mut ChannelSignerType<SP> {
+ pub fn get_mut_signer(&mut self) -> &mut SP::EcdsaSigner {
return &mut self.holder_signer;
}
@@ -5242,7 +5244,6 @@ impl<SP: SignerProvider> ChannelContext<SP> {
);
self.holder_signer
- .as_ref()
.validate_holder_commitment(
&holder_commitment_tx,
commitment_data.outbound_htlc_preimages,
@@ -5985,11 +5986,16 @@ impl<SP: SignerProvider> ChannelContext<SP> {
&self.channel_id(), counterparty_initial_bitcoin_tx.txid, encode::serialize_hex(&counterparty_initial_bitcoin_tx.transaction));
// We sign "counterparty" commitment transaction, allowing them to broadcast the tx if they wish.
- let signature = match &self.holder_signer {
- ChannelSignerType::Ecdsa(ecdsa) => ecdsa.sign_counterparty_commitment(
- channel_parameters, &counterparty_initial_commitment_tx, Vec::new(), Vec::new(), &self.secp_ctx
- ).ok(),
- };
+ let signature = self
+ .holder_signer
+ .sign_counterparty_commitment(
+ channel_parameters,
+ &counterparty_initial_commitment_tx,
+ Vec::new(),
+ Vec::new(),
+ &self.secp_ctx,
+ )
+ .ok();
if signature.is_some() && self.signer_pending_funding {
log_trace!(logger, "Counterparty commitment signature available for funding_signed message; clearing signer_pending_funding");
@@ -6095,20 +6101,16 @@ impl<SP: SignerProvider> ChannelContext<SP> {
logger,
);
let counterparty_initial_commitment_tx = commitment_data.tx;
- match self.holder_signer {
- ChannelSignerType::Ecdsa(ref ecdsa) => {
- let channel_parameters = &funding.channel_transaction_parameters;
- ecdsa
- .sign_counterparty_commitment(
- channel_parameters,
- &counterparty_initial_commitment_tx,
- Vec::new(),
- Vec::new(),
- &self.secp_ctx,
- )
- .ok()
- },
- }
+ let channel_parameters = &funding.channel_transaction_parameters;
+ self.holder_signer
+ .sign_counterparty_commitment(
+ channel_parameters,
+ &counterparty_initial_commitment_tx,
+ Vec::new(),
+ Vec::new(),
+ &self.secp_ctx,
+ )
+ .ok()
}
fn get_initial_commitment_signed_v2<L: Logger>(
@@ -8402,18 +8404,15 @@ where
return Err(ChannelError::close("Received an unexpected revoke_and_ack".to_owned()));
}
- match &self.context.holder_signer {
- ChannelSignerType::Ecdsa(ecdsa) => {
- ecdsa
- .validate_counterparty_revocation(
- self.context.counterparty_next_commitment_transaction_number + 1,
- &secret,
- )
- .map_err(|_| {
- ChannelError::close("Failed to validate revocation from peer".to_owned())
- })?;
- },
- };
+ self.context
+ .holder_signer
+ .validate_counterparty_revocation(
+ self.context.counterparty_next_commitment_transaction_number + 1,
+ &secret,
+ )
+ .map_err(|_| {
+ ChannelError::close("Failed to validate revocation from peer".to_owned())
+ })?;
self.context
.commitment_secrets
@@ -9275,7 +9274,9 @@ where
&mut self, logger: &L, path_for_release_htlc: CBP
) -> Result<SignerResumeUpdates, ChannelError> where CBP: Fn(u64) -> BlindedMessagePath {
if let Some((commitment_number, commitment_secret)) = self.context.signer_pending_stale_state_verification.clone() {
- if let Ok(expected_point) = self.context.holder_signer.as_ref()
+ if let Ok(expected_point) = self
+ .context
+ .holder_signer
.get_per_commitment_point(commitment_number, &self.context.secp_ctx)
{
self.context.signer_pending_stale_state_verification.take();
@@ -9441,7 +9442,6 @@ where
let signer = &self.context.holder_signer;
self.holder_commitment_point.try_resolve_pending(signer, &self.context.secp_ctx, logger);
let per_commitment_secret = signer
- .as_ref()
.release_commitment_secret(self.holder_commitment_point.next_transaction_number() + 2)
.ok();
if let Some(per_commitment_secret) = per_commitment_secret {
@@ -9650,7 +9650,7 @@ where
.map_err(|_| ChannelError::close("Peer sent a garbage channel_reestablish with unparseable secret key".to_owned()))?;
if msg.next_remote_commitment_number > our_commitment_transaction {
let given_commitment_number = INITIAL_COMMITMENT_NUMBER - msg.next_remote_commitment_number + 1;
- let expected_point = self.context.holder_signer.as_ref()
+ let expected_point = self.context.holder_signer
.get_per_commitment_point(given_commitment_number, &self.context.secp_ctx)
.ok();
if expected_point.is_none() {
@@ -10357,15 +10357,15 @@ where
&mut self, closing_tx: &ClosingTransaction, skip_remote_output: bool, fee_satoshis: u64,
min_fee_satoshis: u64, max_fee_satoshis: u64, logger: &L,
) -> Option<msgs::ClosingSigned> {
- let sig = match &self.context.holder_signer {
- ChannelSignerType::Ecdsa(ecdsa) => ecdsa
- .sign_closing_transaction(
- &self.funding.channel_transaction_parameters,
- closing_tx,
- &self.context.secp_ctx,
- )
- .ok(),
- };
+ let sig = self
+ .context
+ .holder_signer
+ .sign_closing_transaction(
+ &self.funding.channel_transaction_parameters,
+ closing_tx,
+ &self.context.secp_ctx,
+ )
+ .ok();
if sig.is_none() {
log_trace!(logger, "Closing transaction signature unavailable, waiting on signer");
self.context.signer_pending_closing = true;
@@ -10687,7 +10687,7 @@ where
}
#[cfg(any(test, feature = "_externalize_tests"))]
- pub fn get_signer(&self) -> &ChannelSignerType<SP> {
+ pub fn get_signer(&self) -> &SP::EcdsaSigner {
&self.context.holder_signer
}
@@ -11459,32 +11459,30 @@ where
},
Ok(v) => v
};
- match &self.context.holder_signer {
- ChannelSignerType::Ecdsa(ecdsa) => {
- let our_bitcoin_sig = match ecdsa.sign_channel_announcement_with_funding_key(
- &self.funding.channel_transaction_parameters, &announcement, &self.context.secp_ctx,
- ) {
- Err(_) => {
- log_error!(logger, "Signer rejected channel_announcement signing. Channel will not be announced!");
- return None;
- },
- Ok(v) => v
- };
- let short_channel_id = match self.funding.get_short_channel_id() {
- Some(scid) => scid,
- None => return None,
- };
+ let our_bitcoin_sig = match self.context.holder_signer.sign_channel_announcement_with_funding_key(
+ &self.funding.channel_transaction_parameters,
+ &announcement,
+ &self.context.secp_ctx,
+ ) {
+ Err(_) => {
+ log_error!(logger, "Signer rejected channel_announcement signing. Channel will not be announced!");
+ return None;
+ },
+ Ok(v) => v
+ };
+ let short_channel_id = match self.funding.get_short_channel_id() {
+ Some(scid) => scid,
+ None => return None,
+ };
- self.context.announcement_sigs_state = AnnouncementSigsState::MessageSent;
+ self.context.announcement_sigs_state = AnnouncementSigsState::MessageSent;
- Some(msgs::AnnouncementSignatures {
- channel_id: self.context.channel_id(),
- short_channel_id,
- node_signature: our_node_sig,
- bitcoin_signature: our_bitcoin_sig,
- })
- }
- }
+ Some(msgs::AnnouncementSignatures {
+ channel_id: self.context.channel_id(),
+ short_channel_id,
+ node_signature: our_node_sig,
+ bitcoin_signature: our_bitcoin_sig,
+ })
}
/// Signs the given channel announcement, returning a ChannelError::Ignore if no keys are
@@ -11500,21 +11498,20 @@ where
let our_node_sig = node_signer.sign_gossip_message(msgs::UnsignedGossipMessage::ChannelAnnouncement(&announcement))
.map_err(|_| ChannelError::Ignore("Failed to generate node signature for channel_announcement".to_owned()))?;
- match &self.context.holder_signer {
- ChannelSignerType::Ecdsa(ecdsa) => {
- let our_bitcoin_sig = ecdsa.sign_channel_announcement_with_funding_key(
- &self.funding.channel_transaction_parameters, &announcement, &self.context.secp_ctx,
- )
- .map_err(|_| ChannelError::Ignore("Signer rejected channel_announcement".to_owned()))?;
- Ok(msgs::ChannelAnnouncement {
- node_signature_1: if were_node_one { our_node_sig } else { their_node_sig },
- node_signature_2: if were_node_one { their_node_sig } else { our_node_sig },
- bitcoin_signature_1: if were_node_one { our_bitcoin_sig } else { their_bitcoin_sig },
- bitcoin_signature_2: if were_node_one { their_bitcoin_sig } else { our_bitcoin_sig },
- contents: announcement,
- })
- },
- }
+ let our_bitcoin_sig = self.context.holder_signer
+ .sign_channel_announcement_with_funding_key(
+ &self.funding.channel_transaction_parameters,
+ &announcement,
+ &self.context.secp_ctx,
+ )
+ .map_err(|_| ChannelError::Ignore("Signer rejected channel_announcement".to_owned()))?;
+ Ok(msgs::ChannelAnnouncement {
+ node_signature_1: if were_node_one { our_node_sig } else { their_node_sig },
+ node_signature_2: if were_node_one { their_node_sig } else { our_node_sig },
+ bitcoin_signature_1: if were_node_one { our_bitcoin_sig } else { their_bitcoin_sig },
+ bitcoin_signature_2: if were_node_one { their_bitcoin_sig } else { our_bitcoin_sig },
+ contents: announcement,
+ })
} else {
Err(ChannelError::Ignore("Attempted to sign channel announcement before we'd received announcement_signatures".to_string()))
}
@@ -11847,14 +11844,15 @@ where
debug_assert!(self.pending_splice.is_none());
// Rotate the funding pubkey using the prev_funding_txid as a tweak
let prev_funding_txid = self.funding.get_funding_txid();
- let funding_pubkey = match (prev_funding_txid, &self.context.holder_signer) {
- (None, _) => {
+ let funding_pubkey = match prev_funding_txid {
+ None => {
debug_assert!(false);
self.funding.get_holder_pubkeys().funding_pubkey
},
- (Some(prev_funding_txid), ChannelSignerType::Ecdsa(ecdsa)) => {
- ecdsa.new_funding_pubkey(prev_funding_txid, &self.context.secp_ctx)
- },
+ Some(prev_funding_txid) => self
+ .context
+ .holder_signer
+ .new_funding_pubkey(prev_funding_txid, &self.context.secp_ctx),
};
let funding_feerate_per_kw = context.funding_feerate_sat_per_1000_weight;
@@ -11951,14 +11949,15 @@ where
// Rotate the pubkeys using the prev_funding_txid as a tweak
let prev_funding_txid = self.funding.get_funding_txid();
- let funding_pubkey = match (prev_funding_txid, &self.context.holder_signer) {
- (None, _) => {
+ let funding_pubkey = match prev_funding_txid {
+ None => {
debug_assert!(false);
self.funding.get_holder_pubkeys().funding_pubkey
},
- (Some(prev_funding_txid), ChannelSignerType::Ecdsa(ecdsa)) => {
- ecdsa.new_funding_pubkey(prev_funding_txid, &self.context.secp_ctx)
- },
+ Some(prev_funding_txid) => self
+ .context
+ .holder_signer
+ .new_funding_pubkey(prev_funding_txid, &self.context.secp_ctx),
};
let mut new_keys = self.funding.get_holder_pubkeys().clone();
new_keys.funding_pubkey = funding_pubkey;
@@ -12686,46 +12685,44 @@ where
);
let counterparty_commitment_tx = commitment_data.tx;
- match &self.context.holder_signer {
- ChannelSignerType::Ecdsa(ecdsa) => {
- let (signature, htlc_signatures);
-
- {
- let res = ecdsa.sign_counterparty_commitment(
- &funding.channel_transaction_parameters,
- &counterparty_commitment_tx,
- commitment_data.inbound_htlc_preimages,
- commitment_data.outbound_htlc_preimages,
- &self.context.secp_ctx,
- ).map_err(|_| ChannelError::Ignore("Failed to get signatures for new commitment_signed".to_owned()))?;
- signature = res.0;
- htlc_signatures = res.1;
-
- let trusted_tx = counterparty_commitment_tx.trust();
- log_trace!(logger, "Signed remote commitment tx {} (txid {}) with redeemscript {} -> {}",
- encode::serialize_hex(&trusted_tx.built_transaction().transaction),
- &trusted_tx.txid(), encode::serialize_hex(&funding.get_funding_redeemscript()),
- log_bytes!(signature.serialize_compact()[..]));
-
- let counterparty_keys = trusted_tx.keys();
- debug_assert_eq!(htlc_signatures.len(), trusted_tx.nondust_htlcs().len());
- for (ref htlc_sig, ref htlc) in htlc_signatures.iter().zip(trusted_tx.nondust_htlcs()) {
- log_trace!(logger, "Signed remote HTLC tx {} with redeemscript {} with pubkey {} -> {}",
- encode::serialize_hex(&chan_utils::build_htlc_transaction(&trusted_tx.txid(), trusted_tx.negotiated_feerate_per_kw(), funding.get_holder_selected_contest_delay(), htlc, funding.get_channel_type(), &counterparty_keys.broadcaster_delayed_payment_key, &counterparty_keys.revocation_key)),
- encode::serialize_hex(&chan_utils::get_htlc_redeemscript(&htlc, funding.get_channel_type(), &counterparty_keys)),
- log_bytes!(counterparty_keys.broadcaster_htlc_key.to_public_key().serialize()),
- log_bytes!(htlc_sig.serialize_compact()[..]));
- }
- }
+ let (signature, htlc_signatures);
- Ok(msgs::CommitmentSigned {
- channel_id: self.context.channel_id,
- signature,
- htlc_signatures,
- funding_txid: funding.get_funding_txo().map(|funding_txo| funding_txo.txid),
- })
- }
+ {
+ let res = self.context.holder_signer
+ .sign_counterparty_commitment(
+ &funding.channel_transaction_parameters,
+ &counterparty_commitment_tx,
+ commitment_data.inbound_htlc_preimages,
+ commitment_data.outbound_htlc_preimages,
+ &self.context.secp_ctx,
+ )
+ .map_err(|_| ChannelError::Ignore("Failed to get signatures for new commitment_signed".to_owned()))?;
+ signature = res.0;
+ htlc_signatures = res.1;
+
+ let trusted_tx = counterparty_commitment_tx.trust();
+ log_trace!(logger, "Signed remote commitment tx {} (txid {}) with redeemscript {} -> {}",
+ encode::serialize_hex(&trusted_tx.built_transaction().transaction),
+ &trusted_tx.txid(), encode::serialize_hex(&funding.get_funding_redeemscript()),
+ log_bytes!(signature.serialize_compact()[..]));
+
+ let counterparty_keys = trusted_tx.keys();
+ debug_assert_eq!(htlc_signatures.len(), trusted_tx.nondust_htlcs().len());
+ for (ref htlc_sig, ref htlc) in htlc_signatures.iter().zip(trusted_tx.nondust_htlcs()) {
+ log_trace!(logger, "Signed remote HTLC tx {} with redeemscript {} with pubkey {} -> {}",
+ encode::serialize_hex(&chan_utils::build_htlc_transaction(&trusted_tx.txid(), trusted_tx.negotiated_feerate_per_kw(), funding.get_holder_selected_contest_delay(), htlc, funding.get_channel_type(), &counterparty_keys.broadcaster_delayed_payment_key, &counterparty_keys.revocation_key)),
+ encode::serialize_hex(&chan_utils::get_htlc_redeemscript(&htlc, funding.get_channel_type(), &counterparty_keys)),
+ log_bytes!(counterparty_keys.broadcaster_htlc_key.to_public_key().serialize()),
+ log_bytes!(htlc_sig.serialize_compact()[..]));
}
+ }
+
+ Ok(msgs::CommitmentSigned {
+ channel_id: self.context.channel_id,
+ signature,
+ htlc_signatures,
+ funding_txid: funding.get_funding_txo().map(|funding_txo| funding_txo.txid),
+ })
}
/// Adds a pending outbound HTLC to this channel, and builds a new remote commitment
@@ -13281,12 +13278,19 @@ impl<SP: SignerProvider> OutboundV1Channel<SP> {
self.context.counterparty_next_commitment_transaction_number,
&self.context.counterparty_next_commitment_point.unwrap(), false, false, logger);
let counterparty_initial_commitment_tx = commitment_data.tx;
- let signature = match &self.context.holder_signer {
- ChannelSignerType::Ecdsa(ecdsa) => {
- let channel_parameters = &self.funding.channel_transaction_parameters;
- ecdsa.sign_counterparty_commitment(channel_parameters, &counterparty_initial_commitment_tx, Vec::new(), Vec::new(), &self.context.secp_ctx)
- .map(|(sig, _)| sig).ok()
- },
+ let signature = {
+ let channel_parameters = &self.funding.channel_transaction_parameters;
+ self.context
+ .holder_signer
+ .sign_counterparty_commitment(
+ channel_parameters,
+ &counterparty_initial_commitment_tx,
+ Vec::new(),
+ Vec::new(),
+ &self.context.secp_ctx,
+ )
+ .map(|(sig, _)| sig)
+ .ok()
};
if signature.is_some() && self.context.signer_pending_funding {
@@ -13936,11 +13940,11 @@ impl<SP: SignerProvider> PendingV2Channel<SP> {
debug_assert!(false, "Tried to send an open_channel2 for a channel that has already advanced");
}
- let first_per_commitment_point = self.context.holder_signer.as_ref()
+ let first_per_commitment_point = self.context.holder_signer
.get_per_commitment_point(self.unfunded_context.transaction_number(),
&self.context.secp_ctx)
.expect("TODO: async signing is not yet supported for commitment points in v2 channel establishment");
- let second_per_commitment_point = self.context.holder_signer.as_ref()
+ let second_per_commitment_point = self.context.holder_signer
.get_per_commitment_point(self.unfunded_context.transaction_number() - 1,
&self.context.secp_ctx)
.expect("TODO: async signing is not yet supported for commitment points in v2 channel establishment");
@@ -14105,10 +14109,10 @@ impl<SP: SignerProvider> PendingV2Channel<SP> {
/// [`msgs::AcceptChannelV2`]: crate::ln::msgs::AcceptChannelV2
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
fn generate_accept_channel_v2_message(&self) -> msgs::AcceptChannelV2 {
- let first_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(
+ let first_per_commitment_point = self.context.holder_signer.get_per_commitment_point(
self.unfunded_context.transaction_number(), &self.context.secp_ctx)
.expect("TODO: async signing is not yet supported for commitment points in v2 channel establishment");
- let second_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(
+ let second_per_commitment_point = self.context.holder_signer.get_per_commitment_point(
self.unfunded_context.transaction_number() - 1, &self.context.secp_ctx)
.expect("TODO: async signing is not yet supported for commitment points in v2 channel establishment");
let keys = self.funding.get_holder_pubkeys();
@@ -15521,7 +15525,7 @@ impl<'a, 'b, 'c, ES: EntropySource, SP: SignerProvider>
latest_monitor_update_id,
- holder_signer: ChannelSignerType::Ecdsa(holder_signer),
+ holder_signer,
shutdown_scriptpubkey,
destination_script,
diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs
index 641842d..72d566e 100644
--- a/lightning/src/ln/functional_test_utils.rs
+++ b/lightning/src/ln/functional_test_utils.rs
@@ -677,7 +677,7 @@ impl<'a, 'b, 'c> Node<'a, 'b, 'c> {
if let Some(context) =
chan_lock.channel_by_id.get_mut(chan_id).map(|chan| chan.context_mut())
{
- let signer = context.get_mut_signer().as_mut_ecdsa().unwrap();
+ let signer = context.get_mut_signer();
if available {
signer.enable_op(signer_op);
} else {
diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs
index eb868d2..4b82c9b 100644
--- a/lightning/src/ln/functional_tests.rs
+++ b/lightning/src/ln/functional_tests.rs
@@ -48,6 +48,7 @@ use crate::routing::gossip::{NetworkGraph, NetworkUpdate};
use crate::routing::router::{
get_route, Path, PaymentParameters, Route, RouteHop, RouteParameters,
};
+use crate::sign::ChannelSigner;
use crate::sign::{EntropySource, OutputSpender, SignerProvider};
use crate::types::features::{ChannelFeatures, ChannelTypeFeatures, NodeFeatures};
use crate::types::payment::{PaymentHash, PaymentSecret};
@@ -6681,16 +6682,15 @@ pub fn test_counterparty_raa_skip_no_crash() {
const INITIAL_COMMITMENT_NUMBER: u64 = (1 << 48) - 1;
// Make signer believe we got a counterparty signature, so that it allows the revocation
- keys.as_ecdsa().unwrap().get_enforcement_state().last_holder_commitment -= 1;
- per_commitment_secret =
- keys.as_ref().release_commitment_secret(INITIAL_COMMITMENT_NUMBER).unwrap();
+ keys.get_enforcement_state().last_holder_commitment -= 1;
+ per_commitment_secret = keys.release_commitment_secret(INITIAL_COMMITMENT_NUMBER).unwrap();
// Must revoke without gaps
- keys.as_ecdsa().unwrap().get_enforcement_state().last_holder_commitment -= 1;
- keys.as_ref().release_commitment_secret(INITIAL_COMMITMENT_NUMBER - 1).unwrap();
+ keys.get_enforcement_state().last_holder_commitment -= 1;
+ keys.release_commitment_secret(INITIAL_COMMITMENT_NUMBER - 1).unwrap();
- keys.as_ecdsa().unwrap().get_enforcement_state().last_holder_commitment -= 1;
- let sec = keys.as_ref().release_commitment_secret(INITIAL_COMMITMENT_NUMBER - 2).unwrap();
+ keys.get_enforcement_state().last_holder_commitment -= 1;
+ let sec = keys.release_commitment_secret(INITIAL_COMMITMENT_NUMBER - 2).unwrap();
let key = SecretKey::from_slice(&sec).unwrap();
next_per_commitment_point = PublicKey::from_secret_key(&Secp256k1::new(), &key);
}
diff --git a/lightning/src/ln/htlc_reserve_unit_tests.rs b/lightning/src/ln/htlc_reserve_unit_tests.rs
index 80b3ebd..495a869 100644
--- a/lightning/src/ln/htlc_reserve_unit_tests.rs
+++ b/lightning/src/ln/htlc_reserve_unit_tests.rs
@@ -17,6 +17,7 @@ use crate::ln::outbound_payment::RecipientOnionFields;
use crate::routing::router::PaymentParameters;
use crate::sign::ecdsa::EcdsaChannelSigner;
use crate::sign::tx_builder::{SpecTxBuilder, TxBuilder};
+use crate::sign::ChannelSigner;
use crate::types::features::ChannelTypeFeatures;
use crate::types::payment::PaymentPreimage;
use crate::util::config::UserConfig;
@@ -863,14 +864,11 @@ pub fn do_test_fee_spike_buffer(cfg: Option<UserConfig>, htlc_fails: bool) {
let local_chan = chan_lock.channel_by_id.get(&chan.2).and_then(Channel::as_funded).unwrap();
let chan_signer = local_chan.get_signer();
// Make the signer believe we validated another commitment, so we can release the secret
- chan_signer.as_ecdsa().unwrap().get_enforcement_state().last_holder_commitment -= 1;
+ chan_signer.get_enforcement_state().last_holder_commitment -= 1;
(
- chan_signer.as_ref().release_commitment_secret(INITIAL_COMMITMENT_NUMBER).unwrap(),
- chan_signer
- .as_ref()
- .get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 2, &secp_ctx)
- .unwrap(),
+ chan_signer.release_commitment_secret(INITIAL_COMMITMENT_NUMBER).unwrap(),
+ chan_signer.get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 2, &secp_ctx).unwrap(),
)
};
let remote_point = {
@@ -879,10 +877,7 @@ pub fn do_test_fee_spike_buffer(cfg: Option<UserConfig>, htlc_fails: bool) {
let channel = get_channel_ref!(nodes[1], nodes[0], per_peer_lock, peer_state_lock, chan.2);
let chan_signer = channel.as_funded().unwrap().get_signer();
- chan_signer
- .as_ref()
- .get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, &secp_ctx)
- .unwrap()
+ chan_signer.get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, &secp_ctx).unwrap()
};
// Build the remote commitment transaction so we can sign it, and then later use the
@@ -919,8 +914,6 @@ pub fn do_test_fee_spike_buffer(cfg: Option<UserConfig>, htlc_fails: bool) {
);
let params = &channel.funding().channel_transaction_parameters;
chan_signer
- .as_ecdsa()
- .unwrap()
.sign_counterparty_commitment(params, &commitment_tx, Vec::new(), Vec::new(), &secp_ctx)
.unwrap()
};
@@ -2291,17 +2284,15 @@ pub fn do_test_dust_limit_fee_accounting(can_afford: bool) {
chan_lock.channel_by_id.get(&chan_id).and_then(Channel::as_funded).unwrap();
let chan_signer = local_chan.get_signer();
// Make the signer believe we validated another commitment, so we can release the secret
- chan_signer.as_ecdsa().unwrap().get_enforcement_state().last_holder_commitment -= 1;
+ chan_signer.get_enforcement_state().last_holder_commitment -= 1;
(
chan_signer
- .as_ref()
.release_commitment_secret(
INITIAL_COMMITMENT_NUMBER - MIN_AFFORDABLE_HTLC_COUNT as u64 + 1,
)
.unwrap(),
chan_signer
- .as_ref()
.get_per_commitment_point(
INITIAL_COMMITMENT_NUMBER - MIN_AFFORDABLE_HTLC_COUNT as u64,
&secp_ctx,
@@ -2317,7 +2308,6 @@ pub fn do_test_dust_limit_fee_accounting(can_afford: bool) {
get_channel_ref!(nodes[1], nodes[0], per_peer_lock, peer_state_lock, chan_id);
let chan_signer = channel.as_funded().unwrap().get_signer();
chan_signer
- .as_ref()
.get_per_commitment_point(
INITIAL_COMMITMENT_NUMBER - MIN_AFFORDABLE_HTLC_COUNT as u64,
&secp_ctx,
@@ -2367,8 +2357,6 @@ pub fn do_test_dust_limit_fee_accounting(can_afford: bool) {
);
let params = &channel.funding().channel_transaction_parameters;
chan_signer
- .as_ecdsa()
- .unwrap()
.sign_counterparty_commitment(
params,
&commitment_tx,
diff --git a/lightning/src/ln/update_fee_tests.rs b/lightning/src/ln/update_fee_tests.rs
index 77a4c32..515c23e 100644
--- a/lightning/src/ln/update_fee_tests.rs
+++ b/lightning/src/ln/update_fee_tests.rs
@@ -16,6 +16,7 @@ use crate::ln::msgs::{
};
use crate::ln::outbound_payment::RecipientOnionFields;
use crate::sign::ecdsa::EcdsaChannelSigner;
+use crate::sign::ChannelSigner;
use crate::types::features::ChannelTypeFeatures;
use crate::util::config::UserConfig;
use crate::util::errors::APIError;
@@ -471,7 +472,7 @@ pub fn do_test_update_fee_that_funder_cannot_afford(channel_type_features: Chann
let channel = get_channel_ref!(nodes[1], nodes[0], per_peer_lock, peer_state_lock, chan.2);
let chan_signer = channel.as_funded().unwrap().get_signer();
let point_number = INITIAL_COMMITMENT_NUMBER - 1;
- chan_signer.as_ref().get_per_commitment_point(point_number, &secp_ctx).unwrap()
+ chan_signer.get_per_commitment_point(point_number, &secp_ctx).unwrap()
};
let res = {
@@ -497,8 +498,6 @@ pub fn do_test_update_fee_that_funder_cannot_afford(channel_type_features: Chann
);
let params = &local_chan.funding().channel_transaction_parameters;
local_chan_signer
- .as_ecdsa()
- .unwrap()
.sign_counterparty_commitment(params, &commitment_tx, Vec::new(), Vec::new(), &secp_ctx)
.unwrap()
};
@@ -570,7 +569,7 @@ pub fn test_update_fee_that_saturates_subs() {
let channel = get_channel_ref!(nodes[1], nodes[0], per_peer_lock, peer_state_lock, chan_id);
let chan_signer = channel.as_funded().unwrap().get_signer();
- chan_signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER, &secp_ctx).unwrap()
+ chan_signer.get_per_commitment_point(INITIAL_COMMITMENT_NUMBER, &secp_ctx).unwrap()
};
let res = {
@@ -595,8 +594,6 @@ pub fn test_update_fee_that_saturates_subs() {
);
let params = &local_chan.funding().channel_transaction_parameters;
local_chan_signer
- .as_ecdsa()
- .unwrap()
.sign_counterparty_commitment(params, &commitment_tx, Vec::new(), Vec::new(), &secp_ctx)
.unwrap()
};
diff --git a/lightning/src/sign/mod.rs b/lightning/src/sign/mod.rs
index adab372..fa77b3c 100644
--- a/lightning/src/sign/mod.rs
+++ b/lightning/src/sign/mod.rs
@@ -70,8 +70,6 @@ use core::future::Future;
use core::ops::Deref;
use core::sync::atomic::{AtomicUsize, Ordering};
-pub(crate) mod type_resolver;
-
pub mod ecdsa;
pub mod tx_builder;
@@ -1088,7 +1086,8 @@ pub type DynSignerProvider = dyn SignerProvider<EcdsaSigner = InMemorySigner>;
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
/// [`MonitorUpdatingPersister`]: crate::util::persist::MonitorUpdatingPersister
pub trait SignerProvider {
- /// A type which implements [`EcdsaChannelSigner`] which will be returned by [`Self::derive_channel_signer`].
+ /// A type which implements [`EcdsaChannelSigner`] which will be returned by
+ /// [`Self::derive_channel_signer`].
type EcdsaSigner: EcdsaChannelSigner;
/// Generates a unique `channel_keys_id` that can be used to obtain a [`Self::EcdsaSigner`] through
diff --git a/lightning/src/sign/type_resolver.rs b/lightning/src/sign/type_resolver.rs
deleted file mode 100644
index 3e78489..0000000
--- a/lightning/src/sign/type_resolver.rs
+++ /dev/null
@@ -1,37 +0,0 @@
-use crate::sign::{ChannelSigner, SignerProvider};
-
-pub(crate) enum ChannelSignerType<SP: SignerProvider> {
- // in practice, this will only ever be an EcdsaChannelSigner (specifically, Writeable)
- Ecdsa(SP::EcdsaSigner),
-}
-
-#[cfg(test)]
-impl<SP: SignerProvider> std::fmt::Debug for ChannelSignerType<SP> {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- f.debug_struct("ChannelSignerType").finish()
- }
-}
-
-impl<SP: SignerProvider> ChannelSignerType<SP> {
- pub(crate) fn as_ref(&self) -> &dyn ChannelSigner {
- match self {
- ChannelSignerType::Ecdsa(ecs) => ecs,
- }
- }
-
- #[allow(unused)]
- pub(crate) fn as_ecdsa(&self) -> Option<&SP::EcdsaSigner> {
- match self {
- ChannelSignerType::Ecdsa(ecs) => Some(ecs),
- _ => None,
- }
- }
-
- #[allow(unused)]
- pub(crate) fn as_mut_ecdsa(&mut self) -> Option<&mut SP::EcdsaSigner> {
- match self {
- ChannelSignerType::Ecdsa(ecs) => Some(ecs),
- _ => None,
- }
- }
-}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.