diff --git a/Cargo.toml b/Cargo.toml index 1eb7b572d8b..7978d9de6a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,7 +63,6 @@ check-cfg = [ "cfg(c_bindings)", "cfg(ldk_bench)", "cfg(ldk_test_vectors)", - "cfg(taproot)", "cfg(require_route_graph_test)", "cfg(simple_close)", "cfg(peer_storage)", diff --git a/ci/ci-tests-cfg-flags.sh b/ci/ci-tests-cfg-flags.sh index 5380c986f3f..e6a22a83491 100755 --- a/ci/ci-tests-cfg-flags.sh +++ b/ci/ci-tests-cfg-flags.sh @@ -5,8 +5,6 @@ set -eox pipefail source "$(dirname "$0")/ci-tests-common.sh" echo -e "\n\nTest cfg-flag builds" -RUSTFLAGS="--cfg=taproot" cargo test --quiet --color always -p lightning -[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean RUSTFLAGS="--cfg=simple_close" cargo test --quiet --color always -p lightning [ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean RUSTFLAGS="--cfg=lsps1_service" cargo test --quiet --color always -p lightning-liquidity diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 5bf899f34b1..5a2e397a064 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -62,5 +62,4 @@ check-cfg = [ "cfg(fuzzing)", "cfg(secp256k1_fuzz)", "cfg(hashes_fuzz)", - "cfg(taproot)", ] diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs index 22006897a0f..a6288e1a7c3 100644 --- a/fuzz/src/chanmon_consistency.rs +++ b/fuzz/src/chanmon_consistency.rs @@ -447,8 +447,6 @@ impl NodeSigner for KeyProvider { impl SignerProvider for KeyProvider { type EcdsaSigner = TestChannelSigner; - #[cfg(taproot)] - type TaprootSigner = TestChannelSigner; fn generate_channel_keys_id(&self, _inbound: bool, _user_channel_id: u128) -> [u8; 32] { let id = self.rand_bytes_id.fetch_add(1, atomic::Ordering::Relaxed) as u8; diff --git a/fuzz/src/full_stack.rs b/fuzz/src/full_stack.rs index 5dfa51079d8..35b1632ae7c 100644 --- a/fuzz/src/full_stack.rs +++ b/fuzz/src/full_stack.rs @@ -457,8 +457,6 @@ impl NodeSigner for KeyProvider { impl SignerProvider for KeyProvider { type EcdsaSigner = TestChannelSigner; - #[cfg(taproot)] - type TaprootSigner = TestChannelSigner; fn generate_channel_keys_id(&self, inbound: bool, _user_channel_id: u128) -> [u8; 32] { let ctr = self.counter.fetch_add(1, Ordering::Relaxed) as u8; diff --git a/fuzz/src/onion_message.rs b/fuzz/src/onion_message.rs index 70dfb0753d3..4859f7379fb 100644 --- a/fuzz/src/onion_message.rs +++ b/fuzz/src/onion_message.rs @@ -296,8 +296,6 @@ impl NodeSigner for KeyProvider { impl SignerProvider for KeyProvider { type EcdsaSigner = TestChannelSigner; - #[cfg(taproot)] - type TaprootSigner = TestChannelSigner; fn generate_channel_keys_id(&self, _inbound: bool, _user_channel_id: u128) -> [u8; 32] { unreachable!() diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs index da415c70a32..be0d7ee6faf 100644 --- a/lightning-background-processor/src/lib.rs +++ b/lightning-background-processor/src/lib.rs @@ -378,18 +378,11 @@ type DynMessageRouter = lightning::onion_message::messenger::DefaultMessageRoute &'static (dyn EntropySource + Send + Sync), >; -#[cfg(all(not(c_bindings), not(taproot)))] +#[cfg(not(c_bindings))] type DynSignerProvider = dyn lightning::sign::SignerProvider + Send + Sync; -#[cfg(all(not(c_bindings), taproot))] -type DynSignerProvider = (dyn lightning::sign::SignerProvider< - EcdsaSigner = lightning::sign::InMemorySigner, - TaprootSigner = lightning::sign::InMemorySigner, -> + Send - + Sync); - #[cfg(not(c_bindings))] type DynChannelManager = lightning::ln::channelmanager::ChannelManager< &'static (dyn chain::Watch + Send + Sync), diff --git a/lightning-tests/Cargo.toml b/lightning-tests/Cargo.toml index 4e8d330089d..05a5bd55ce5 100644 --- a/lightning-tests/Cargo.toml +++ b/lightning-tests/Cargo.toml @@ -29,6 +29,4 @@ level = "forbid" # # Note that Cargo automatically declares corresponding cfgs for every feature # defined in the member-level [features] tables as "expected". -check-cfg = [ - "cfg(taproot)", -] +check-cfg = [] diff --git a/lightning-tests/src/lib.rs b/lightning-tests/src/lib.rs index c028193d692..80c95299d5b 100644 --- a/lightning-tests/src/lib.rs +++ b/lightning-tests/src/lib.rs @@ -1,5 +1,5 @@ #[cfg_attr(test, macro_use)] extern crate lightning; -#[cfg(all(test, not(taproot)))] +#[cfg(test)] pub mod upgrade_downgrade_tests; diff --git a/lightning/Cargo.toml b/lightning/Cargo.toml index fd6c5052359..2f2f01bc401 100644 --- a/lightning/Cargo.toml +++ b/lightning/Cargo.toml @@ -65,8 +65,5 @@ features = ["bitcoinconsensus", "secp-recovery"] [target.'cfg(ldk_bench)'.dependencies] criterion = { version = "0.4", optional = true, default-features = false } -[target.'cfg(taproot)'.dependencies] -musig2 = { git = "https://github.com/arik-so/rust-musig2", rev = "6f95a05718cbb44d8fe3fa6021aea8117aa38d50" } - [lints] workspace = true diff --git a/lightning/src/ln/async_signer_tests.rs b/lightning/src/ln/async_signer_tests.rs index 451af3918bf..b9e57632b2b 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 9361cd3c749..353bfafbed0 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(signer: &ChannelSignerType, secp_ctx: &Secp256k1) -> Option { + pub fn new(signer: &S, secp_ctx: &Secp256k1) -> Option { 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( - &mut self, signer: &ChannelSignerType, secp_ctx: &Secp256k1, logger: &L, + pub fn try_resolve_pending( + &mut self, signer: &S, secp_ctx: &Secp256k1, 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( - &mut self, signer: &ChannelSignerType, secp_ctx: &Secp256k1, logger: &L, + pub fn advance( + &mut self, signer: &S, secp_ctx: &Secp256k1, logger: &L, ) -> Result<(), ()> { if let Some(next_point) = self.pending_next_point { *self = Self { @@ -2222,16 +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, - ), - #[cfg(taproot)] - ChannelSignerType::Taproot(_) => todo!(), - }; + 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 @@ -3059,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 { config: LegacyChannelConfig, @@ -3095,7 +3088,7 @@ pub(super) struct ChannelContext { latest_monitor_update_id: u64, - holder_signer: ChannelSignerType, + holder_signer: SP::EcdsaSigner, shutdown_scriptpubkey: Option, destination_script: ScriptBuf, @@ -3348,6 +3341,13 @@ pub(super) struct ChannelContext { pub interactive_tx_signing_session: Option, } +#[cfg(test)] +impl fmt::Debug for ChannelContext { + 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 { @@ -3423,7 +3423,7 @@ trait InitialRemoteCommitmentReceiver { &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())); } @@ -3784,7 +3784,7 @@ impl ChannelContext { latest_monitor_update_id: 0, - holder_signer: ChannelSignerType::Ecdsa(holder_signer), + holder_signer, shutdown_scriptpubkey, destination_script, @@ -4029,7 +4029,7 @@ impl ChannelContext { latest_monitor_update_id: 0, - holder_signer: ChannelSignerType::Ecdsa(holder_signer), + holder_signer, shutdown_scriptpubkey, destination_script, @@ -4344,7 +4344,7 @@ impl ChannelContext { /// Returns the holder signer for this channel. #[cfg(any(test, feature = "_test_utils"))] - pub fn get_mut_signer(&mut self) -> &mut ChannelSignerType { + pub fn get_mut_signer(&mut self) -> &mut SP::EcdsaSigner { return &mut self.holder_signer; } @@ -5244,7 +5244,6 @@ impl ChannelContext { ); self.holder_signer - .as_ref() .validate_holder_commitment( &holder_commitment_tx, commitment_data.outbound_htlc_preimages, @@ -5987,15 +5986,16 @@ impl ChannelContext { &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 { - // TODO (arik): move match into calling method for Taproot - ChannelSignerType::Ecdsa(ecdsa) => ecdsa.sign_counterparty_commitment( - channel_parameters, &counterparty_initial_commitment_tx, Vec::new(), Vec::new(), &self.secp_ctx - ).ok(), - // TODO (taproot|arik) - #[cfg(taproot)] - _ => todo!() - }; + 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"); @@ -6008,8 +6008,6 @@ impl ChannelContext { signature.map(|(signature, _)| msgs::FundingSigned { channel_id: self.channel_id(), signature, - #[cfg(taproot)] - partial_signature_with_nonce: None, }) } @@ -6103,24 +6101,16 @@ impl ChannelContext { logger, ); let counterparty_initial_commitment_tx = commitment_data.tx; - match self.holder_signer { - // TODO (taproot|arik): move match into calling method for Taproot - 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() - }, - // TODO (taproot|arik) - #[cfg(taproot)] - _ => todo!(), - } + 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( @@ -6139,8 +6129,6 @@ impl ChannelContext { htlc_signatures, signature, funding_txid: funding.get_funding_txo().map(|funding_txo| funding_txo.txid), - #[cfg(taproot)] - partial_signature_with_nonce: None, }) } else { log_debug!( @@ -8416,21 +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()) - })?; - }, - // TODO (taproot|arik) - #[cfg(taproot)] - _ => todo!(), - }; + 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 @@ -9292,7 +9274,9 @@ where &mut self, logger: &L, path_for_release_htlc: CBP ) -> Result 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(); @@ -9458,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 { @@ -9476,8 +9459,6 @@ where channel_id: self.context.channel_id, per_commitment_secret, next_per_commitment_point: self.holder_commitment_point.next_point(), - #[cfg(taproot)] - next_local_nonce: None, release_htlc_message_paths, }); } @@ -9669,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() { @@ -10376,18 +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 { - 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(), - // TODO (taproot|arik) - #[cfg(taproot)] - _ => todo!(), - }; + 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; @@ -10709,7 +10687,7 @@ where } #[cfg(any(test, feature = "_externalize_tests"))] - pub fn get_signer(&self) -> &ChannelSignerType { + pub fn get_signer(&self) -> &SP::EcdsaSigner { &self.context.holder_signer } @@ -11481,35 +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, - }) - }, - // TODO (taproot|arik) - #[cfg(taproot)] - _ => todo!() - } + 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 @@ -11525,24 +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, - }) - }, - // TODO (taproot|arik) - #[cfg(taproot)] - _ => todo!() - } + 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())) } @@ -11875,16 +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) - }, - #[cfg(taproot)] - _ => todo!(), + 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; @@ -11981,16 +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) - }, - #[cfg(taproot)] - _ => todo!(), + 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; @@ -12718,51 +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), - #[cfg(taproot)] - partial_signature_with_nonce: None, - }) - }, - // TODO (taproot|arik) - #[cfg(taproot)] - _ => todo!() + { + 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 @@ -13318,16 +13278,19 @@ impl OutboundV1Channel { 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 { - // TODO (taproot|arik): move match into calling method for Taproot - 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() - }, - // TODO (taproot|arik) - #[cfg(taproot)] - _ => todo!() + 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 { @@ -13343,10 +13306,6 @@ impl OutboundV1Channel { funding_txid: self.funding.channel_transaction_parameters.funding_outpoint.as_ref().unwrap().txid, funding_output_index: self.funding.channel_transaction_parameters.funding_outpoint.as_ref().unwrap().index, signature, - #[cfg(taproot)] - partial_signature_with_nonce: None, - #[cfg(taproot)] - next_local_nonce: None, }) } @@ -13751,8 +13710,6 @@ impl InboundV1Channel { channel_type: Some(self.funding.get_channel_type().clone()), }, channel_reserve_satoshis: self.funding.holder_selected_channel_reserve_satoshis, - #[cfg(taproot)] - next_local_nonce: None, }) } @@ -13983,11 +13940,11 @@ impl PendingV2Channel { 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"); @@ -14152,10 +14109,10 @@ impl PendingV2Channel { /// [`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(); @@ -15568,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, @@ -15775,8 +15732,6 @@ mod tests { #[cfg(ldk_test_vectors)] impl SignerProvider for Keys { type EcdsaSigner = InMemorySigner; - #[cfg(taproot)] - type TaprootSigner = InMemorySigner; fn generate_channel_keys_id(&self, _inbound: bool, _user_channel_id: u128) -> [u8; 32] { self.signer.channel_keys_id() diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index 641842ddaff..72d566ef4fb 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 17fbc1fce28..4b82c9b1877 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); } @@ -6699,8 +6699,6 @@ pub fn test_counterparty_raa_skip_no_crash() { channel_id, per_commitment_secret, next_per_commitment_point, - #[cfg(taproot)] - next_local_nonce: None, release_htlc_message_paths: Vec::new(), }; nodes[1].node.handle_revoke_and_ack(node_a_id, &raa); diff --git a/lightning/src/ln/htlc_reserve_unit_tests.rs b/lightning/src/ln/htlc_reserve_unit_tests.rs index d88b9a2dc3f..495a8698dfb 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, 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, 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, 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() }; @@ -930,8 +923,6 @@ pub fn do_test_fee_spike_buffer(cfg: Option, htlc_fails: bool) { signature: res.0, htlc_signatures: res.1, funding_txid: None, - #[cfg(taproot)] - partial_signature_with_nonce: None, }; // Send the commitment_signed message to the nodes[1]. @@ -943,8 +934,6 @@ pub fn do_test_fee_spike_buffer(cfg: Option, htlc_fails: bool) { channel_id: chan.2, per_commitment_secret: local_secret, next_per_commitment_point: next_local_point, - #[cfg(taproot)] - next_local_nonce: None, release_htlc_message_paths: Vec::new(), }; nodes[1].node.handle_revoke_and_ack(node_a_id, &raa_msg); @@ -2295,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, @@ -2321,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, @@ -2371,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, @@ -2388,8 +2372,6 @@ pub fn do_test_dust_limit_fee_accounting(can_afford: bool) { signature: res.0, htlc_signatures: res.1, funding_txid: None, - #[cfg(taproot)] - partial_signature_with_nonce: None, }; // Send the commitment_signed message to the nodes[1]. @@ -2401,8 +2383,6 @@ pub fn do_test_dust_limit_fee_accounting(can_afford: bool) { channel_id: chan_id, per_commitment_secret: local_secret, next_per_commitment_point: next_local_point, - #[cfg(taproot)] - next_local_nonce: None, release_htlc_message_paths: Vec::new(), }; nodes[1].node.handle_revoke_and_ack(node_a_id, &raa_msg); diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index ac549ddd50c..29089032843 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -69,14 +69,6 @@ use crate::routing::gossip::{NodeAlias, NodeId}; /// 21 million * 10^8 * 1000 pub(crate) const MAX_VALUE_MSAT: u64 = 21_000_000_0000_0000_000; -#[cfg(taproot)] -/// A partial signature that also contains the Musig2 nonce its signer used -#[derive(Clone, Debug, Hash, PartialEq, Eq)] -pub struct PartialSignatureWithNonce( - pub musig2::types::PartialSignature, - pub musig2::types::PublicNonce, -); - /// An error in decoding a message or struct. #[derive(Clone, Debug, Hash, PartialEq, Eq)] pub enum DecodeError { @@ -370,9 +362,6 @@ pub struct AcceptChannel { pub common_fields: CommonAcceptChannelFields, /// The minimum value unencumbered by HTLCs for the counterparty to keep in the channel pub channel_reserve_satoshis: u64, - #[cfg(taproot)] - /// Next nonce the channel initiator should use to create a funding output signature against - pub next_local_nonce: Option, } /// An [`accept_channel2`] message to be sent by or received from the channel accepter. @@ -407,12 +396,6 @@ pub struct FundingCreated { pub funding_output_index: u16, /// The signature of the channel initiator (funder) on the initial commitment transaction pub signature: Signature, - #[cfg(taproot)] - /// The partial signature of the channel initiator (funder) - pub partial_signature_with_nonce: Option, - #[cfg(taproot)] - /// Next nonce the channel acceptor should use to finalize the funding output signature - pub next_local_nonce: Option, } /// A [`funding_signed`] message to be sent to or received from a peer. @@ -426,9 +409,6 @@ pub struct FundingSigned { pub channel_id: ChannelId, /// The signature of the channel acceptor (fundee) on the initial commitment transaction pub signature: Signature, - #[cfg(taproot)] - /// The partial signature of the channel acceptor (fundee) - pub partial_signature_with_nonce: Option, } /// A [`channel_ready`] message to be sent to or received from a peer. @@ -906,9 +886,6 @@ pub struct CommitmentSigned { pub htlc_signatures: Vec, /// The funding transaction, to discriminate among multiple pending funding transactions (e.g. in case of splicing) pub funding_txid: Option, - #[cfg(taproot)] - /// The partial Taproot signature on the commitment transaction - pub partial_signature_with_nonce: Option, } /// A [`revoke_and_ack`] message to be sent to or received from a peer. @@ -922,9 +899,6 @@ pub struct RevokeAndACK { pub per_commitment_secret: [u8; 32], /// The next sender-broadcast commitment transaction's per-commitment point pub next_per_commitment_point: PublicKey, - #[cfg(taproot)] - /// Musig nonce the recipient should use in their next commitment signature message - pub next_local_nonce: Option, /// A list of `(htlc_id, blinded_path)`. The receiver of this message will use the blinded paths /// as reply paths to [`HeldHtlcAvailable`] onion messages that they send to the often-offline /// receiver of this HTLC. The `htlc_id` is used by the receiver of this message to identify which @@ -2909,17 +2883,10 @@ impl Writeable for AcceptChannel { self.common_fields.delayed_payment_basepoint.write(w)?; self.common_fields.htlc_basepoint.write(w)?; self.common_fields.first_per_commitment_point.write(w)?; - #[cfg(not(taproot))] encode_tlv_stream!(w, { (0, self.common_fields.shutdown_scriptpubkey.as_ref().map(|s| WithoutLength(s)), option), // Don't encode length twice. (1, self.common_fields.channel_type, option), }); - #[cfg(taproot)] - encode_tlv_stream!(w, { - (0, self.common_fields.shutdown_scriptpubkey.as_ref().map(|s| WithoutLength(s)), option), // Don't encode length twice. - (1, self.common_fields.channel_type, option), - (4, self.next_local_nonce, option), - }); Ok(()) } } @@ -2943,18 +2910,9 @@ impl LengthReadable for AcceptChannel { let mut shutdown_scriptpubkey: Option = None; let mut channel_type: Option = None; - #[cfg(not(taproot))] - decode_tlv_stream!(r, { - (0, shutdown_scriptpubkey, (option, encoding: (ScriptBuf, WithoutLength))), - (1, channel_type, option), - }); - #[cfg(taproot)] - let mut next_local_nonce: Option = None; - #[cfg(taproot)] decode_tlv_stream!(r, { (0, shutdown_scriptpubkey, (option, encoding: (ScriptBuf, WithoutLength))), (1, channel_type, option), - (4, next_local_nonce, option), }); Ok(AcceptChannel { @@ -2976,8 +2934,6 @@ impl LengthReadable for AcceptChannel { channel_type, }, channel_reserve_satoshis, - #[cfg(taproot)] - next_local_nonce, }) } } @@ -3245,7 +3201,6 @@ impl_writeable!(ClosingSignedFeeRange, { max_fee_satoshis }); -#[cfg(not(taproot))] impl_writeable_msg!(CommitmentSigned, { channel_id, signature, @@ -3254,54 +3209,24 @@ impl_writeable_msg!(CommitmentSigned, { (1, funding_txid, option), }); -#[cfg(taproot)] -impl_writeable_msg!(CommitmentSigned, { - channel_id, - signature, - htlc_signatures -}, { - (1, funding_txid, option), - (2, partial_signature_with_nonce, option), -}); - impl_writeable!(DecodedOnionErrorPacket, { hmac, failuremsg, pad }); -#[cfg(not(taproot))] impl_writeable_msg!(FundingCreated, { temporary_channel_id, funding_txid, funding_output_index, signature }, {}); -#[cfg(taproot)] -impl_writeable_msg!(FundingCreated, { - temporary_channel_id, - funding_txid, - funding_output_index, - signature -}, { - (2, partial_signature_with_nonce, option), - (4, next_local_nonce, option) -}); -#[cfg(not(taproot))] impl_writeable_msg!(FundingSigned, { channel_id, signature }, {}); -#[cfg(taproot)] -impl_writeable_msg!(FundingSigned, { - channel_id, - signature -}, { - (2, partial_signature_with_nonce, option) -}); - impl_writeable_msg!(ChannelReady, { channel_id, next_per_commitment_point, @@ -3529,7 +3454,6 @@ impl LengthReadable for OpenChannelV2 { } } -#[cfg(not(taproot))] impl_writeable_msg!(RevokeAndACK, { channel_id, per_commitment_secret, @@ -3538,16 +3462,6 @@ impl_writeable_msg!(RevokeAndACK, { (75537, release_htlc_message_paths, optional_vec) }); -#[cfg(taproot)] -impl_writeable_msg!(RevokeAndACK, { - channel_id, - per_commitment_secret, - next_per_commitment_point -}, { - (4, next_local_nonce, option), - (75537, release_htlc_message_paths, optional_vec) -}); - impl_writeable_msg!(Shutdown, { channel_id, scriptpubkey @@ -5504,8 +5418,6 @@ mod tests { channel_type: None, }, channel_reserve_satoshis: 3608586615801332854, - #[cfg(taproot)] - next_local_nonce: None, }; let encoded_value = accept_channel.encode(); let mut target_value = >::from_hex("020202020202020202020202020202020202020202020202020202020202020212345678901234562334032891223698321446687011447600083a840000034d000c89d4c0bcc0bc031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f024d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d076602531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe33703462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b0362c0a046dacce86ddd0343c6d3c7c79c2208ba0d9c9cf24a6d046d21d21f90f703f006a18d5653c4edf5391ff23a61f03ff83d237e880ee61187fa9f379a028e0a").unwrap(); @@ -5671,10 +5583,6 @@ mod tests { .unwrap(), funding_output_index: 255, signature: sig_1, - #[cfg(taproot)] - partial_signature_with_nonce: None, - #[cfg(taproot)] - next_local_nonce: None, }; let encoded_value = funding_created.encode(); let target_value = >::from_hex("02020202020202020202020202020202020202020202020202020202020202026e96fe9f8b0ddcd729ba03cfafa5a27b050b39d354dd980814268dfa9a44d4c200ffd977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a").unwrap(); @@ -5690,12 +5598,8 @@ mod tests { ); let sig_1 = get_sig_on!(privkey_1, secp_ctx, String::from("01010101010101010101010101010101")); - let funding_signed = msgs::FundingSigned { - channel_id: ChannelId::from_bytes([2; 32]), - signature: sig_1, - #[cfg(taproot)] - partial_signature_with_nonce: None, - }; + let funding_signed = + msgs::FundingSigned { channel_id: ChannelId::from_bytes([2; 32]), signature: sig_1 }; let encoded_value = funding_signed.encode(); let target_value = >::from_hex("0202020202020202020202020202020202020202020202020202020202020202d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a").unwrap(); assert_eq!(encoded_value, target_value); @@ -6234,8 +6138,6 @@ mod tests { Txid::from_str("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e") .unwrap(), ), - #[cfg(taproot)] - partial_signature_with_nonce: None, }; let encoded_value = commitment_signed.encode(); let mut target_value = "0202020202020202020202020202020202020202020202020202020202020202d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a".to_string(); @@ -6270,8 +6172,6 @@ mod tests { 1, 1, 1, 1, ], next_per_commitment_point: pubkey_1, - #[cfg(taproot)] - next_local_nonce: None, release_htlc_message_paths: Vec::new(), }; let encoded_value = raa.encode(); diff --git a/lightning/src/ln/update_fee_tests.rs b/lightning/src/ln/update_fee_tests.rs index ac566393bdb..515c23e127a 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() }; @@ -508,8 +507,6 @@ pub fn do_test_update_fee_that_funder_cannot_afford(channel_type_features: Chann signature: res.0, htlc_signatures: res.1, funding_txid: None, - #[cfg(taproot)] - partial_signature_with_nonce: None, }; let update_fee = msgs::UpdateFee { channel_id: chan.2, feerate_per_kw: non_buffer_feerate + 4 }; @@ -572,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 = { @@ -597,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() }; @@ -608,8 +603,6 @@ pub fn test_update_fee_that_saturates_subs() { signature: res.0, htlc_signatures: res.1, funding_txid: None, - #[cfg(taproot)] - partial_signature_with_nonce: None, }; let update_fee = msgs::UpdateFee { channel_id: chan_id, feerate_per_kw: FEERATE }; diff --git a/lightning/src/sign/mod.rs b/lightning/src/sign/mod.rs index 84bfbb902ea..fa77b3c0ba1 100644 --- a/lightning/src/sign/mod.rs +++ b/lightning/src/sign/mod.rs @@ -51,8 +51,6 @@ use crate::ln::channel_keys::{ RevocationBasepoint, RevocationKey, }; use crate::ln::inbound_payment::ExpandedKey; -#[cfg(taproot)] -use crate::ln::msgs::PartialSignatureWithNonce; use crate::ln::msgs::{UnsignedChannelAnnouncement, UnsignedGossipMessage}; use crate::ln::script::ShutdownScript; use crate::offers::invoice::UnsignedBolt12Invoice; @@ -65,22 +63,14 @@ use crate::util::transaction_utils; use crate::crypto::chacha20::ChaCha20; use crate::prelude::*; use crate::sign::ecdsa::EcdsaChannelSigner; -#[cfg(taproot)] -use crate::sign::taproot::TaprootChannelSigner; use crate::util::atomic_counter::AtomicCounter; use core::convert::TryInto; use core::future::Future; use core::ops::Deref; use core::sync::atomic::{AtomicUsize, Ordering}; -#[cfg(taproot)] -use musig2::types::{PartialSignature, PublicNonce}; - -pub(crate) mod type_resolver; pub mod ecdsa; -#[cfg(taproot)] -pub mod taproot; pub mod tx_builder; pub(crate) const COMPRESSED_PUBLIC_KEY_SIZE: usize = bitcoin::secp256k1::constants::PUBLIC_KEY_SIZE; @@ -1084,18 +1074,7 @@ impl> OutputSpender for O { /// A dynamic [`SignerProvider`] temporarily needed for doc tests. /// /// This is not exported to bindings users as it is not intended for public consumption. -#[cfg(taproot)] -#[doc(hidden)] -#[deprecated(note = "Remove once taproot cfg is removed")] -pub type DynSignerProvider = - dyn SignerProvider; - -/// A dynamic [`SignerProvider`] temporarily needed for doc tests. -/// -/// This is not exported to bindings users as it is not intended for public consumption. -#[cfg(not(taproot))] #[doc(hidden)] -#[deprecated(note = "Remove once taproot cfg is removed")] pub type DynSignerProvider = dyn SignerProvider; /// A trait that can return signer instances for individual channels. @@ -1107,11 +1086,9 @@ pub type DynSignerProvider = dyn SignerProvider; /// [`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; - #[cfg(taproot)] - /// A type which implements [`TaprootChannelSigner`] - type TaprootSigner: TaprootChannelSigner; /// Generates a unique `channel_keys_id` that can be used to obtain a [`Self::EcdsaSigner`] through /// [`SignerProvider::derive_channel_signer`]. The `user_channel_id` is provided to allow @@ -1151,8 +1128,6 @@ pub trait SignerProvider { impl> SignerProvider for SP { type EcdsaSigner = T::EcdsaSigner; - #[cfg(taproot)] - type TaprootSigner = T::TaprootSigner; fn generate_channel_keys_id(&self, inbound: bool, user_channel_id: u128) -> [u8; 32] { self.deref().generate_channel_keys_id(inbound, user_channel_id) @@ -1983,65 +1958,6 @@ impl EcdsaChannelSigner for InMemorySigner { } } -#[cfg(taproot)] -#[allow(unused)] -impl TaprootChannelSigner for InMemorySigner { - fn generate_local_nonce_pair( - &self, commitment_number: u64, secp_ctx: &Secp256k1, - ) -> PublicNonce { - todo!() - } - - fn partially_sign_counterparty_commitment( - &self, counterparty_nonce: PublicNonce, commitment_tx: &CommitmentTransaction, - inbound_htlc_preimages: Vec, - outbound_htlc_preimages: Vec, secp_ctx: &Secp256k1, - ) -> Result<(PartialSignatureWithNonce, Vec), ()> { - todo!() - } - - fn finalize_holder_commitment( - &self, commitment_tx: &HolderCommitmentTransaction, - counterparty_partial_signature: PartialSignatureWithNonce, secp_ctx: &Secp256k1, - ) -> Result { - todo!() - } - - fn sign_justice_revoked_output( - &self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, - secp_ctx: &Secp256k1, - ) -> Result { - todo!() - } - - fn sign_justice_revoked_htlc( - &self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, - htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1, - ) -> Result { - todo!() - } - - fn sign_holder_htlc_transaction( - &self, htlc_tx: &Transaction, input: usize, htlc_descriptor: &HTLCDescriptor, - secp_ctx: &Secp256k1, - ) -> Result { - todo!() - } - - fn sign_counterparty_htlc_transaction( - &self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey, - htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1, - ) -> Result { - todo!() - } - - fn partially_sign_closing_transaction( - &self, closing_tx: &ClosingTransaction, secp_ctx: &Secp256k1, - ) -> Result { - todo!() - } -} - /// Simple implementation of [`EntropySource`], [`NodeSigner`], and [`SignerProvider`] that takes a /// 32-byte seed for use as a BIP 32 extended key and derives keys from that. /// @@ -2548,8 +2464,6 @@ impl OutputSpender for KeysManager { impl SignerProvider for KeysManager { type EcdsaSigner = InMemorySigner; - #[cfg(taproot)] - type TaprootSigner = InMemorySigner; fn generate_channel_keys_id(&self, _inbound: bool, user_channel_id: u128) -> [u8; 32] { let child_idx = self.channel_child_index.fetch_add(1, Ordering::AcqRel); @@ -2697,8 +2611,6 @@ impl OutputSpender for PhantomKeysManager { impl SignerProvider for PhantomKeysManager { type EcdsaSigner = InMemorySigner; - #[cfg(taproot)] - type TaprootSigner = InMemorySigner; fn generate_channel_keys_id(&self, inbound: bool, user_channel_id: u128) -> [u8; 32] { self.inner.generate_channel_keys_id(inbound, user_channel_id) diff --git a/lightning/src/sign/taproot.rs b/lightning/src/sign/taproot.rs deleted file mode 100644 index 22470f4f8b6..00000000000 --- a/lightning/src/sign/taproot.rs +++ /dev/null @@ -1,155 +0,0 @@ -//! Defines a Taproot-specific signer type. - -use alloc::vec::Vec; -use bitcoin::secp256k1; -use bitcoin::secp256k1::{schnorr::Signature, PublicKey, Secp256k1, SecretKey}; -use bitcoin::transaction::Transaction; - -use musig2::types::{PartialSignature, PublicNonce}; - -use crate::ln::chan_utils::{ - ClosingTransaction, CommitmentTransaction, HTLCOutputInCommitment, HolderCommitmentTransaction, -}; -use crate::ln::msgs::PartialSignatureWithNonce; -use crate::sign::{ChannelSigner, HTLCDescriptor}; -use crate::types::payment::PaymentPreimage; - -/// A Taproot-specific signer type that defines signing-related methods that are either unique to -/// Taproot or have argument or return types that differ from the ones an ECDSA signer would be -/// expected to have. -pub trait TaprootChannelSigner: ChannelSigner { - /// Generate a local nonce pair, which requires committing to ahead of time. - /// The counterparty needs the public nonce generated herein to compute a partial signature. - fn generate_local_nonce_pair( - &self, commitment_number: u64, secp_ctx: &Secp256k1, - ) -> PublicNonce; - - /// Create a signature for a counterparty's commitment transaction and associated HTLC transactions. - /// - /// Note that if signing fails or is rejected, the channel will be force-closed. - /// - /// Policy checks should be implemented in this function, including checking the amount - /// sent to us and checking the HTLCs. - /// - /// The preimages of outbound and inbound HTLCs that were fulfilled since the last commitment - /// are provided. A validating signer should ensure that an outbound HTLC output is removed - /// only when the matching preimage is provided and after the corresponding inbound HTLC has - /// been removed for forwarded payments. - /// - /// Note that all the relevant preimages will be provided, but there may also be additional - /// irrelevant or duplicate preimages. - // - // TODO: Document the things someone using this interface should enforce before signing. - fn partially_sign_counterparty_commitment( - &self, counterparty_nonce: PublicNonce, commitment_tx: &CommitmentTransaction, - inbound_htlc_preimages: Vec, - outbound_htlc_preimages: Vec, secp_ctx: &Secp256k1, - ) -> Result<(PartialSignatureWithNonce, Vec), ()>; - - /// Creates a signature for a holder's commitment transaction. - /// - /// This will be called - /// - with a non-revoked `commitment_tx`. - /// - with the latest `commitment_tx` when we initiate a force-close. - /// - /// This may be called multiple times for the same transaction. - /// - /// An external signer implementation should check that the commitment has not been revoked. - /// - // TODO: Document the things someone using this interface should enforce before signing. - fn finalize_holder_commitment( - &self, commitment_tx: &HolderCommitmentTransaction, - counterparty_partial_signature: PartialSignatureWithNonce, - secp_ctx: &Secp256k1, - ) -> Result; - - /// Create a signature for the given input in a transaction spending an HTLC transaction output - /// or a commitment transaction `to_local` output when our counterparty broadcasts an old state. - /// - /// A justice transaction may claim multiple outputs at the same time if timelocks are - /// similar, but only a signature for the input at index `input` should be signed for here. - /// It may be called multiple times for same output(s) if a fee-bump is needed with regards - /// to an upcoming timelock expiration. - /// - /// Amount is value of the output spent by this input, committed to in the BIP 341 signature. - /// - /// `per_commitment_key` is revocation secret which was provided by our counterparty when they - /// revoked the state which they eventually broadcast. It's not a _holder_ secret key and does - /// not allow the spending of any funds by itself (you need our holder `revocation_secret` to do - /// so). - fn sign_justice_revoked_output( - &self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, - secp_ctx: &Secp256k1, - ) -> Result; - - /// Create a signature for the given input in a transaction spending a commitment transaction - /// HTLC output when our counterparty broadcasts an old state. - /// - /// A justice transaction may claim multiple outputs at the same time if timelocks are - /// similar, but only a signature for the input at index `input` should be signed for here. - /// It may be called multiple times for same output(s) if a fee-bump is needed with regards - /// to an upcoming timelock expiration. - /// - /// `amount` is the value of the output spent by this input, committed to in the BIP 341 - /// signature. - /// - /// `per_commitment_key` is revocation secret which was provided by our counterparty when they - /// revoked the state which they eventually broadcast. It's not a _holder_ secret key and does - /// not allow the spending of any funds by itself (you need our holder revocation_secret to do - /// so). - /// - /// `htlc` holds HTLC elements (hash, timelock), thus changing the format of the witness script - /// (which is committed to in the BIP 341 signatures). - fn sign_justice_revoked_htlc( - &self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, - htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1, - ) -> Result; - - /// Computes the signature for a commitment transaction's HTLC output used as an input within - /// `htlc_tx`, which spends the commitment transaction at index `input`. The signature returned - /// must be be computed using [`TapSighashType::Default`]. - /// - /// Note that this may be called for HTLCs in the penultimate commitment transaction if a - /// [`ChannelMonitor`] [replica](https://github.com/lightningdevkit/rust-lightning/blob/main/GLOSSARY.md#monitor-replicas) - /// broadcasts it before receiving the update for the latest commitment transaction. - /// - /// - /// [`TapSighashType::Default`]: bitcoin::sighash::TapSighashType::Default - /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor - fn sign_holder_htlc_transaction( - &self, htlc_tx: &Transaction, input: usize, htlc_descriptor: &HTLCDescriptor, - secp_ctx: &Secp256k1, - ) -> Result; - - /// Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment - /// transaction, either offered or received. - /// - /// Such a transaction may claim multiples offered outputs at same time if we know the - /// preimage for each when we create it, but only the input at index `input` should be - /// signed for here. It may be called multiple times for same output(s) if a fee-bump is - /// needed with regards to an upcoming timelock expiration. - /// - /// `witness_script` is either an offered or received script as defined in BOLT3 for HTLC - /// outputs. - /// - /// `amount` is value of the output spent by this input, committed to in the BIP 341 signature. - /// - /// `per_commitment_point` is the dynamic point corresponding to the channel state - /// detected onchain. It has been generated by our counterparty and is used to derive - /// channel state keys, which are then included in the witness script and committed to in the - /// BIP 341 signature. - fn sign_counterparty_htlc_transaction( - &self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey, - htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1, - ) -> Result; - - /// Create a signature for a (proposed) closing transaction. - /// - /// Note that, due to rounding, there may be one "missing" satoshi, and either party may have - /// chosen to forgo their output as dust. - fn partially_sign_closing_transaction( - &self, closing_tx: &ClosingTransaction, secp_ctx: &Secp256k1, - ) -> Result; - - // TODO: sign channel announcement -} diff --git a/lightning/src/sign/type_resolver.rs b/lightning/src/sign/type_resolver.rs deleted file mode 100644 index 405e346dda6..00000000000 --- a/lightning/src/sign/type_resolver.rs +++ /dev/null @@ -1,43 +0,0 @@ -use crate::sign::{ChannelSigner, SignerProvider}; - -pub(crate) enum ChannelSignerType { - // in practice, this will only ever be an EcdsaChannelSigner (specifically, Writeable) - Ecdsa(SP::EcdsaSigner), - #[cfg(taproot)] - #[allow(unused)] - Taproot(SP::TaprootSigner), -} - -#[cfg(test)] -impl std::fmt::Debug for ChannelSignerType { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("ChannelSignerType").finish() - } -} - -impl ChannelSignerType { - pub(crate) fn as_ref(&self) -> &dyn ChannelSigner { - match self { - ChannelSignerType::Ecdsa(ecs) => ecs, - #[cfg(taproot)] - #[allow(unused)] - ChannelSignerType::Taproot(tcs) => tcs, - } - } - - #[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, - } - } -} diff --git a/lightning/src/util/dyn_signer.rs b/lightning/src/util/dyn_signer.rs index cf1cac37903..436eaabda34 100644 --- a/lightning/src/util/dyn_signer.rs +++ b/lightning/src/util/dyn_signer.rs @@ -12,8 +12,6 @@ use crate::ln::inbound_payment::ExpandedKey; use crate::ln::msgs::{UnsignedChannelAnnouncement, UnsignedGossipMessage}; use crate::ln::script::ShutdownScript; use crate::sign::ecdsa::EcdsaChannelSigner; -#[cfg(taproot)] -use crate::sign::taproot::TaprootChannelSigner; use crate::sign::InMemorySigner; use crate::sign::{ChannelSigner, ReceiveAuthKey}; use crate::sign::{EntropySource, HTLCDescriptor, OutputSpender, PhantomKeysManager}; @@ -25,20 +23,13 @@ use bitcoin::absolute::LockTime; use bitcoin::secp256k1::All; use bitcoin::{secp256k1, ScriptBuf, Transaction, TxOut, Txid}; use lightning_invoice::RawBolt11Invoice; -#[cfg(taproot)] -use musig2::types::{PartialSignature, PublicNonce}; use secp256k1::ecdsa::RecoverableSignature; use secp256k1::{ecdh::SharedSecret, ecdsa::Signature, PublicKey, Scalar, Secp256k1, SecretKey}; use types::payment::PaymentPreimage; -#[cfg(not(taproot))] /// A super-trait for all the traits that a dyn signer backing implements pub trait DynSignerTrait: EcdsaChannelSigner + Send + Sync {} -#[cfg(taproot)] -/// A super-trait for all the traits that a dyn signer backing implements -pub trait DynSignerTrait: EcdsaChannelSigner + TaprootChannelSigner + Send + Sync {} - /// Helper to allow DynSigner to clone itself pub trait InnerSign: DynSignerTrait { /// Clone into a Box @@ -60,67 +51,6 @@ impl DynSigner { } } -#[cfg(taproot)] -#[allow(unused_variables)] -impl TaprootChannelSigner for DynSigner { - fn generate_local_nonce_pair( - &self, commitment_number: u64, secp_ctx: &Secp256k1, - ) -> PublicNonce { - todo!() - } - - fn partially_sign_counterparty_commitment( - &self, counterparty_nonce: PublicNonce, commitment_tx: &CommitmentTransaction, - inbound_htlc_preimages: Vec, - outbound_htlc_preimages: Vec, secp_ctx: &Secp256k1, - ) -> Result<(crate::ln::msgs::PartialSignatureWithNonce, Vec), ()> - { - todo!(); - } - - fn finalize_holder_commitment( - &self, commitment_tx: &HolderCommitmentTransaction, - counterparty_partial_signature: crate::ln::msgs::PartialSignatureWithNonce, - secp_ctx: &Secp256k1, - ) -> Result { - todo!(); - } - - fn sign_justice_revoked_output( - &self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, - secp_ctx: &Secp256k1, - ) -> Result { - todo!(); - } - - fn sign_justice_revoked_htlc( - &self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, - htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1, - ) -> Result { - todo!(); - } - - fn sign_holder_htlc_transaction( - &self, htlc_tx: &Transaction, input: usize, htlc_descriptor: &HTLCDescriptor, - secp_ctx: &Secp256k1, - ) -> Result { - todo!(); - } - - fn sign_counterparty_htlc_transaction( - &self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey, - htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1, - ) -> Result { - todo!(); - } - - fn partially_sign_closing_transaction( - &self, closing_tx: &ClosingTransaction, secp_ctx: &Secp256k1, - ) -> Result { - todo!(); - } -} - impl Clone for DynSigner { fn clone(&self) -> Self { DynSigner { inner: self.inner.box_clone() } @@ -231,8 +161,6 @@ delegate!(DynKeysInterface, SignerProvider, fn generate_channel_keys_id(, _inbound: bool, _user_channel_id: u128) -> [u8; 32], fn derive_channel_signer(, _channel_keys_id: [u8; 32]) -> Self::EcdsaSigner; type EcdsaSigner = DynSigner, - #[cfg(taproot)] - type TaprootSigner = DynSigner ); delegate!(DynKeysInterface, EntropySource, inner, @@ -246,25 +174,12 @@ delegate!(DynKeysInterface, OutputSpender, inner, locktime: Option, secp_ctx: &Secp256k1 ) -> Result ); -#[cfg(not(taproot))] /// A supertrait for all the traits that a keys interface implements pub trait DynKeysInterfaceTrait: NodeSigner + OutputSpender + SignerProvider + EntropySource + Send + Sync { } -#[cfg(taproot)] -/// A supertrait for all the traits that a keys interface implements -pub trait DynKeysInterfaceTrait: - NodeSigner - + OutputSpender - + SignerProvider - + EntropySource - + Send - + Sync -{ -} - /// A dyn wrapper for PhantomKeysManager pub struct DynPhantomKeysInterface { inner: Box, @@ -293,8 +208,6 @@ delegate!(DynPhantomKeysInterface, NodeSigner, impl SignerProvider for DynPhantomKeysInterface { type EcdsaSigner = DynSigner; - #[cfg(taproot)] - type TaprootSigner = DynSigner; fn get_destination_script(&self, channel_keys_id: [u8; 32]) -> Result { self.inner.get_destination_script(channel_keys_id) diff --git a/lightning/src/util/ser.rs b/lightning/src/util/ser.rs index b226332ae93..ec5d9a0f3a1 100644 --- a/lightning/src/util/ser.rs +++ b/lightning/src/util/ser.rs @@ -47,8 +47,6 @@ use bitcoin::{consensus, Sequence, TxIn, Weight, Witness}; use dnssec_prover::rr::Name; use crate::chain::ClaimId; -#[cfg(taproot)] -use crate::ln::msgs::PartialSignatureWithNonce; use crate::ln::msgs::{DecodeError, SerialId}; use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret}; use crate::types::string::UntrustedString; @@ -734,7 +732,6 @@ impl_array!(16, u8); // for IPv6 impl_array!(32, u8); // for channel id & hmac impl_array!(PUBLIC_KEY_SIZE, u8); // for PublicKey impl_array!(64, u8); // for ecdsa::Signature and schnorr::Signature -impl_array!(66, u8); // for MuSig2 nonces impl_array!(1300, u8); // for OnionPacket.hop_data impl_array!(8, u16); @@ -1204,40 +1201,6 @@ impl Readable for SecretKey { } } -#[cfg(taproot)] -impl Writeable for musig2::types::PublicNonce { - fn write(&self, w: &mut W) -> Result<(), io::Error> { - self.serialize().write(w) - } -} - -#[cfg(taproot)] -impl Readable for musig2::types::PublicNonce { - fn read(r: &mut R) -> Result { - let buf: [u8; PUBLIC_KEY_SIZE * 2] = Readable::read(r)?; - musig2::types::PublicNonce::from_slice(&buf).map_err(|_| DecodeError::InvalidValue) - } -} - -#[cfg(taproot)] -impl Writeable for PartialSignatureWithNonce { - fn write(&self, w: &mut W) -> Result<(), io::Error> { - self.0.serialize().write(w)?; - self.1.write(w) - } -} - -#[cfg(taproot)] -impl Readable for PartialSignatureWithNonce { - fn read(r: &mut R) -> Result { - let partial_signature_buf: [u8; SECRET_KEY_SIZE] = Readable::read(r)?; - let partial_signature = musig2::types::PartialSignature::from_slice(&partial_signature_buf) - .map_err(|_| DecodeError::InvalidValue)?; - let public_nonce: musig2::types::PublicNonce = Readable::read(r)?; - Ok(PartialSignatureWithNonce(partial_signature, public_nonce)) - } -} - impl Writeable for Hmac { fn write(&self, w: &mut W) -> Result<(), io::Error> { w.write_all(&self[..]) diff --git a/lightning/src/util/test_channel_signer.rs b/lightning/src/util/test_channel_signer.rs index 70eb3223bc4..8435e7fa437 100644 --- a/lightning/src/util/test_channel_signer.rs +++ b/lightning/src/util/test_channel_signer.rs @@ -34,19 +34,11 @@ use bitcoin::sighash::EcdsaSighashType; use bitcoin::transaction::Transaction; use bitcoin::Txid; -#[cfg(taproot)] -use crate::ln::msgs::PartialSignatureWithNonce; -#[cfg(taproot)] -use crate::sign::taproot::TaprootChannelSigner; use crate::sign::HTLCDescriptor; use crate::util::dyn_signer::DynSigner; use bitcoin::secp256k1; -#[cfg(taproot)] -use bitcoin::secp256k1::All; use bitcoin::secp256k1::{ecdsa::Signature, Secp256k1}; use bitcoin::secp256k1::{PublicKey, SecretKey}; -#[cfg(taproot)] -use musig2::types::{PartialSignature, PublicNonce}; /// Initial value for revoked commitment downward counter pub const INITIAL_REVOKED_COMMITMENT_NUMBER: u64 = 1 << 48; @@ -520,65 +512,6 @@ impl EcdsaChannelSigner for TestChannelSigner { } } -#[cfg(taproot)] -#[allow(unused)] -impl TaprootChannelSigner for TestChannelSigner { - fn generate_local_nonce_pair( - &self, commitment_number: u64, secp_ctx: &Secp256k1, - ) -> PublicNonce { - todo!() - } - - fn partially_sign_counterparty_commitment( - &self, counterparty_nonce: PublicNonce, commitment_tx: &CommitmentTransaction, - inbound_htlc_preimages: Vec, - outbound_htlc_preimages: Vec, secp_ctx: &Secp256k1, - ) -> Result<(PartialSignatureWithNonce, Vec), ()> { - todo!() - } - - fn finalize_holder_commitment( - &self, commitment_tx: &HolderCommitmentTransaction, - counterparty_partial_signature: PartialSignatureWithNonce, secp_ctx: &Secp256k1, - ) -> Result { - todo!() - } - - fn sign_justice_revoked_output( - &self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, - secp_ctx: &Secp256k1, - ) -> Result { - todo!() - } - - fn sign_justice_revoked_htlc( - &self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, - htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1, - ) -> Result { - todo!() - } - - fn sign_holder_htlc_transaction( - &self, htlc_tx: &Transaction, input: usize, htlc_descriptor: &HTLCDescriptor, - secp_ctx: &Secp256k1, - ) -> Result { - todo!() - } - - fn sign_counterparty_htlc_transaction( - &self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey, - htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1, - ) -> Result { - todo!() - } - - fn partially_sign_closing_transaction( - &self, closing_tx: &ClosingTransaction, secp_ctx: &Secp256k1, - ) -> Result { - todo!() - } -} - impl TestChannelSigner { fn verify_counterparty_commitment_tx<'a, T: secp256k1::Signing + secp256k1::Verification>( &self, channel_parameters: &ChannelTransactionParameters, diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index 22be4367c7a..47f40edcc45 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -457,8 +457,6 @@ impl EntropySource for OnlyReadsKeysInterface { impl SignerProvider for OnlyReadsKeysInterface { type EcdsaSigner = TestChannelSigner; - #[cfg(taproot)] - type TaprootSigner = TestChannelSigner; fn generate_channel_keys_id(&self, _inbound: bool, _user_channel_id: u128) -> [u8; 32] { unreachable!(); @@ -1926,8 +1924,6 @@ impl NodeSigner for TestKeysInterface { impl SignerProvider for TestKeysInterface { type EcdsaSigner = TestChannelSigner; - #[cfg(taproot)] - type TaprootSigner = TestChannelSigner; fn generate_channel_keys_id(&self, inbound: bool, user_channel_id: u128) -> [u8; 32] { let mut override_keys = self.override_next_keys_id.lock().unwrap();