From de4dd95d29f242820615ace081d5f3d1e3386ff8 Mon Sep 17 00:00:00 2001 From: Arik Sosman Date: Sun, 5 Nov 2023 21:51:15 -0800 Subject: [PATCH] Reparametrize ChannelSignerType by SignerProvider. ChannelSignerType is an enum that contains variants of all currently supported signer types. Given that those signer types are enumerated as associated types in multiple places, it is prudent to denote one type as the authority on signer types. SignerProvider seemed like the best option. Thus, instead of ChannelSignerType declaring the associated types itself, it simply uses their definitions from SignerProvider. --- lightning/src/ln/channel.rs | 38 ++++++++++++++++++++--------- lightning/src/sign/taproot.rs | 1 + lightning/src/sign/type_resolver.rs | 29 ++++++++++++++-------- 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 157103fea..38c605515 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -725,7 +725,7 @@ pub(super) struct ChannelContext where SP::Target: SignerProvider { latest_monitor_update_id: u64, - holder_signer: ChannelSignerType<::EcdsaSigner>, + holder_signer: ChannelSignerType, shutdown_scriptpubkey: Option, destination_script: ScriptBuf, @@ -1095,7 +1095,7 @@ impl ChannelContext where SP::Target: SignerProvider { /// Returns the holder signer for this channel. #[cfg(test)] - pub fn get_signer(&self) -> &ChannelSignerType<::EcdsaSigner> { + pub fn get_signer(&self) -> &ChannelSignerType { return &self.holder_signer } @@ -2142,7 +2142,9 @@ impl ChannelContext where SP::Target: SignerProvider { ChannelSignerType::Ecdsa(ecdsa) => { ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.secp_ctx) .map(|(sig, _)| sig).ok()? - } + }, + // TODO (taproot|arik) + _ => todo!() }; if self.signer_pending_funding { @@ -2194,7 +2196,9 @@ impl ChannelContext where SP::Target: SignerProvider { // We sign "counterparty" commitment transaction, allowing them to broadcast the tx if they wish. (counterparty_initial_commitment_tx, funding_signed) - } + }, + // TODO (taproot|arik) + _ => todo!() } } } @@ -3485,7 +3489,9 @@ impl Channel where self.context.cur_counterparty_commitment_transaction_number + 1, &secret ).map_err(|_| ChannelError::Close("Failed to validate revocation from peer".to_owned()))?; - } + }, + // TODO (taproot|arik) + _ => todo!() }; self.context.commitment_secrets.provide_secret(self.context.cur_counterparty_commitment_transaction_number + 1, msg.per_commitment_secret) @@ -4438,7 +4444,9 @@ impl Channel where max_fee_satoshis: our_max_fee, }), }), None, None)) - } + }, + // TODO (taproot|arik) + _ => todo!() } } @@ -4689,7 +4697,9 @@ impl Channel where max_fee_satoshis: our_max_fee, }), }), signed_tx, shutdown_result)) - } + }, + // TODO (taproot|arik) + _ => todo!() } } } @@ -4801,7 +4811,7 @@ impl Channel where } #[cfg(test)] - pub fn get_signer(&self) -> &ChannelSignerType<::EcdsaSigner> { + pub fn get_signer(&self) -> &ChannelSignerType { &self.context.holder_signer } @@ -5320,7 +5330,9 @@ impl Channel where node_signature: our_node_sig, bitcoin_signature: our_bitcoin_sig, }) - } + }, + // TODO (taproot|arik) + _ => todo!() } } @@ -5347,7 +5359,9 @@ impl Channel where bitcoin_signature_2: if were_node_one { their_bitcoin_sig } else { our_bitcoin_sig }, contents: announcement, }) - } + }, + // TODO (taproot|arik) + _ => todo!() } } else { Err(ChannelError::Ignore("Attempted to sign channel announcement before we'd received announcement_signatures".to_string())) @@ -5720,7 +5734,9 @@ impl Channel where #[cfg(taproot)] partial_signature_with_nonce: None, }, (counterparty_commitment_txid, commitment_stats.htlcs_included))) - } + }, + // TODO (taproot|arik) + _ => todo!() } } diff --git a/lightning/src/sign/taproot.rs b/lightning/src/sign/taproot.rs index 2c9eb6970..0028a0cd1 100644 --- a/lightning/src/sign/taproot.rs +++ b/lightning/src/sign/taproot.rs @@ -1,5 +1,6 @@ //! Defines a Taproot-specific signer type. +use alloc::vec::Vec; use bitcoin::blockdata::transaction::Transaction; use bitcoin::secp256k1; use bitcoin::secp256k1::{PublicKey, schnorr::Signature, Secp256k1, SecretKey}; diff --git a/lightning/src/sign/type_resolver.rs b/lightning/src/sign/type_resolver.rs index f76650982..2a122da34 100644 --- a/lightning/src/sign/type_resolver.rs +++ b/lightning/src/sign/type_resolver.rs @@ -1,34 +1,43 @@ -use crate::sign::{ChannelSigner, EcdsaChannelSigner}; +use core::ops::Deref; +use crate::sign::{ChannelSigner, SignerProvider}; -pub(crate) enum ChannelSignerType { +pub(crate) enum ChannelSignerType where SP::Target: SignerProvider { // in practice, this will only ever be an EcdsaChannelSigner (specifically, Writeable) - Ecdsa(ECS) + Ecdsa(::EcdsaSigner), + #[cfg(taproot)] + Taproot(::TaprootSigner), } -impl ChannelSignerType{ +impl ChannelSignerType where SP::Target: SignerProvider { pub(crate) fn as_ref(&self) -> &dyn ChannelSigner { match self { - ChannelSignerType::Ecdsa(ecs) => ecs + ChannelSignerType::Ecdsa(ecs) => ecs, + #[cfg(taproot)] + ChannelSignerType::Taproot(tcs) => tcs, } } pub(crate) fn as_mut(&mut self) -> &mut dyn ChannelSigner { match self { - ChannelSignerType::Ecdsa(ecs) => ecs + ChannelSignerType::Ecdsa(ecs) => ecs, + #[cfg(taproot)] + ChannelSignerType::Taproot(tcs) => tcs, } } #[allow(unused)] - pub(crate) fn as_ecdsa(&self) -> Option<&ECS> { + pub(crate) fn as_ecdsa(&self) -> Option<&::EcdsaSigner> { match self { - ChannelSignerType::Ecdsa(ecs) => Some(ecs) + ChannelSignerType::Ecdsa(ecs) => Some(ecs), + _ => None } } #[allow(unused)] - pub(crate) fn as_mut_ecdsa(&mut self) -> Option<&mut ECS> { + pub(crate) fn as_mut_ecdsa(&mut self) -> Option<&mut ::EcdsaSigner> { match self { - ChannelSignerType::Ecdsa(ecs) => Some(ecs) + ChannelSignerType::Ecdsa(ecs) => Some(ecs), + _ => None } } } -- 2.39.5