Reparametrize ChannelSignerType by SignerProvider.
authorArik Sosman <git@arik.io>
Mon, 6 Nov 2023 05:51:15 +0000 (21:51 -0800)
committerArik Sosman <git@arik.io>
Tue, 28 Nov 2023 00:27:21 +0000 (16:27 -0800)
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
lightning/src/sign/taproot.rs
lightning/src/sign/type_resolver.rs

index 157103fea2692f0c54e98629d5fc3d0d464c36e8..38c605515cc0134bb2972d30635c9f21568bb158 100644 (file)
@@ -725,7 +725,7 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
 
        latest_monitor_update_id: u64,
 
-       holder_signer: ChannelSignerType<<SP::Target as SignerProvider>::EcdsaSigner>,
+       holder_signer: ChannelSignerType<SP>,
        shutdown_scriptpubkey: Option<ShutdownScript>,
        destination_script: ScriptBuf,
 
@@ -1095,7 +1095,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider  {
 
        /// Returns the holder signer for this channel.
        #[cfg(test)]
-       pub fn get_signer(&self) -> &ChannelSignerType<<SP::Target as SignerProvider>::EcdsaSigner> {
+       pub fn get_signer(&self) -> &ChannelSignerType<SP> {
                return &self.holder_signer
        }
 
@@ -2142,7 +2142,9 @@ impl<SP: Deref> ChannelContext<SP> 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<SP: Deref> ChannelContext<SP> 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<SP: Deref> Channel<SP> 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<SP: Deref> Channel<SP> where
                                                max_fee_satoshis: our_max_fee,
                                        }),
                                }), None, None))
-                       }
+                       },
+                       // TODO (taproot|arik)
+                       _ => todo!()
                }
        }
 
@@ -4689,7 +4697,9 @@ impl<SP: Deref> Channel<SP> where
                                                                max_fee_satoshis: our_max_fee,
                                                        }),
                                                }), signed_tx, shutdown_result))
-                                       }
+                                       },
+                                       // TODO (taproot|arik)
+                                       _ => todo!()
                                }
                        }
                }
@@ -4801,7 +4811,7 @@ impl<SP: Deref> Channel<SP> where
        }
 
        #[cfg(test)]
-       pub fn get_signer(&self) -> &ChannelSignerType<<SP::Target as SignerProvider>::EcdsaSigner> {
+       pub fn get_signer(&self) -> &ChannelSignerType<SP> {
                &self.context.holder_signer
        }
 
@@ -5320,7 +5330,9 @@ impl<SP: Deref> Channel<SP> where
                                        node_signature: our_node_sig,
                                        bitcoin_signature: our_bitcoin_sig,
                                })
-                       }
+                       },
+                       // TODO (taproot|arik)
+                       _ => todo!()
                }
        }
 
@@ -5347,7 +5359,9 @@ impl<SP: Deref> Channel<SP> 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<SP: Deref> Channel<SP> where
                                        #[cfg(taproot)]
                                        partial_signature_with_nonce: None,
                                }, (counterparty_commitment_txid, commitment_stats.htlcs_included)))
-                       }
+                       },
+                       // TODO (taproot|arik)
+                       _ => todo!()
                }
        }
 
index 2c9eb6970464e8f81940c3d3d876bf6e0cfcfc4f..0028a0cd12bb4e111aa04da29aa6d36788b3a404 100644 (file)
@@ -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};
index f76650982c2b4f2ae8e4126975d56728b2e4e261..2a122da34470332e1147a427de86c864abe4adab 100644 (file)
@@ -1,34 +1,43 @@
-use crate::sign::{ChannelSigner, EcdsaChannelSigner};
+use core::ops::Deref;
+use crate::sign::{ChannelSigner, SignerProvider};
 
-pub(crate) enum ChannelSignerType<ECS: EcdsaChannelSigner> {
+pub(crate) enum ChannelSignerType<SP: Deref> where SP::Target: SignerProvider {
        // in practice, this will only ever be an EcdsaChannelSigner (specifically, Writeable)
-       Ecdsa(ECS)
+       Ecdsa(<SP::Target as SignerProvider>::EcdsaSigner),
+       #[cfg(taproot)]
+       Taproot(<SP::Target as SignerProvider>::TaprootSigner),
 }
 
-impl<ECS: EcdsaChannelSigner> ChannelSignerType<ECS>{
+impl<SP: Deref> ChannelSignerType<SP> 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<&<SP::Target as SignerProvider>::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 <SP::Target as SignerProvider>::EcdsaSigner> {
                match self {
-                       ChannelSignerType::Ecdsa(ecs) => Some(ecs)
+                       ChannelSignerType::Ecdsa(ecs) => Some(ecs),
+                       _ => None
                }
        }
 }