Skip to content

Commit b272bfa

Browse files
committed
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.
1 parent 67175c3 commit b272bfa

File tree

3 files changed

+45
-19
lines changed

3 files changed

+45
-19
lines changed

lightning/src/ln/channel.rs

+25-9
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
664664

665665
latest_monitor_update_id: u64,
666666

667-
holder_signer: ChannelSignerType<<SP::Target as SignerProvider>::EcdsaSigner>,
667+
holder_signer: ChannelSignerType<SP>,
668668
shutdown_scriptpubkey: Option<ShutdownScript>,
669669
destination_script: Script,
670670

@@ -3261,7 +3261,9 @@ impl<SP: Deref> Channel<SP> where
32613261
self.context.cur_counterparty_commitment_transaction_number + 1,
32623262
&secret
32633263
).map_err(|_| ChannelError::Close("Failed to validate revocation from peer".to_owned()))?;
3264-
}
3264+
},
3265+
// TODO (taproot|arik)
3266+
_ => todo!()
32653267
};
32663268

32673269
self.context.commitment_secrets.provide_secret(self.context.cur_counterparty_commitment_transaction_number + 1, msg.per_commitment_secret)
@@ -4152,7 +4154,9 @@ impl<SP: Deref> Channel<SP> where
41524154
max_fee_satoshis: our_max_fee,
41534155
}),
41544156
}), None))
4155-
}
4157+
},
4158+
// TODO (taproot|arik)
4159+
_ => todo!()
41564160
}
41574161
}
41584162

@@ -4392,7 +4396,9 @@ impl<SP: Deref> Channel<SP> where
43924396
max_fee_satoshis: our_max_fee,
43934397
}),
43944398
}), signed_tx))
4395-
}
4399+
},
4400+
// TODO (taproot|arik)
4401+
_ => todo!()
43964402
}
43974403
}
43984404
}
@@ -4504,7 +4510,7 @@ impl<SP: Deref> Channel<SP> where
45044510
}
45054511

45064512
#[cfg(test)]
4507-
pub fn get_signer(&self) -> &ChannelSignerType<<SP::Target as SignerProvider>::EcdsaSigner> {
4513+
pub fn get_signer(&self) -> &ChannelSignerType<SP> {
45084514
&self.context.holder_signer
45094515
}
45104516

@@ -5014,7 +5020,9 @@ impl<SP: Deref> Channel<SP> where
50145020
node_signature: our_node_sig,
50155021
bitcoin_signature: our_bitcoin_sig,
50165022
})
5017-
}
5023+
},
5024+
// TODO (taproot|arik)
5025+
_ => todo!()
50185026
}
50195027
}
50205028

@@ -5041,7 +5049,9 @@ impl<SP: Deref> Channel<SP> where
50415049
bitcoin_signature_2: if were_node_one { their_bitcoin_sig } else { our_bitcoin_sig },
50425050
contents: announcement,
50435051
})
5044-
}
5052+
},
5053+
// TODO (taproot|arik)
5054+
_ => todo!()
50455055
}
50465056
} else {
50475057
Err(ChannelError::Ignore("Attempted to sign channel announcement before we'd received announcement_signatures".to_string()))
@@ -5414,7 +5424,9 @@ impl<SP: Deref> Channel<SP> where
54145424
#[cfg(taproot)]
54155425
partial_signature_with_nonce: None,
54165426
}, (counterparty_commitment_txid, commitment_stats.htlcs_included)))
5417-
}
5427+
},
5428+
// TODO (taproot|arik)
5429+
_ => todo!()
54185430
}
54195431
}
54205432

@@ -5790,7 +5802,9 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
57905802
ChannelSignerType::Ecdsa(ecdsa) => {
57915803
Ok(ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.context.secp_ctx)
57925804
.map_err(|_| ChannelError::Close("Failed to get signatures for new commitment_signed".to_owned()))?.0)
5793-
}
5805+
},
5806+
// TODO (taproot|arik)
5807+
_ => todo!()
57945808
}
57955809
}
57965810

@@ -6529,6 +6543,8 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
65296543
// We sign "counterparty" commitment transaction, allowing them to broadcast the tx if they wish.
65306544
Ok((counterparty_initial_commitment_tx, initial_commitment_tx, counterparty_signature))
65316545
}
6546+
// TODO (taproot|arik)
6547+
_ => todo!()
65326548
}
65336549
}
65346550

lightning/src/sign/taproot.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Defines a Taproot-specific signer type.
22
3+
use alloc::vec::Vec;
34
use bitcoin::blockdata::transaction::Transaction;
45
use bitcoin::secp256k1;
56
use bitcoin::secp256k1::{PublicKey, schnorr::Signature, Secp256k1, SecretKey};

lightning/src/sign/type_resolver.rs

+19-10
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,41 @@
1-
use crate::sign::{ChannelSigner, EcdsaChannelSigner};
1+
use core::ops::Deref;
2+
use crate::sign::{ChannelSigner, SignerProvider};
23

3-
pub(crate) enum ChannelSignerType<ECS: EcdsaChannelSigner> {
4+
pub(crate) enum ChannelSignerType<SP: Deref> where SP::Target: SignerProvider {
45
// in practice, this will only ever be an EcdsaChannelSigner (specifically, Writeable)
5-
Ecdsa(ECS)
6+
Ecdsa(<SP::Target as SignerProvider>::EcdsaSigner),
7+
#[cfg(taproot)]
8+
Taproot(<SP::Target as SignerProvider>::TaprootSigner),
69
}
710

8-
impl<ECS: EcdsaChannelSigner> ChannelSignerType<ECS>{
11+
impl<SP: Deref> ChannelSignerType<SP> where SP::Target: SignerProvider {
912
pub(crate) fn as_ref(&self) -> &dyn ChannelSigner {
1013
match self {
11-
ChannelSignerType::Ecdsa(ecs) => ecs
14+
ChannelSignerType::Ecdsa(ecs) => ecs,
15+
#[cfg(taproot)]
16+
ChannelSignerType::Taproot(tcs) => tcs,
1217
}
1318
}
1419

1520
pub(crate) fn as_mut(&mut self) -> &mut dyn ChannelSigner {
1621
match self {
17-
ChannelSignerType::Ecdsa(ecs) => ecs
22+
ChannelSignerType::Ecdsa(ecs) => ecs,
23+
#[cfg(taproot)]
24+
ChannelSignerType::Taproot(tcs) => tcs,
1825
}
1926
}
2027

21-
pub(crate) fn as_ecdsa(&self) -> Option<&ECS> {
28+
pub(crate) fn as_ecdsa(&self) -> Option<&<SP::Target as SignerProvider>::EcdsaSigner> {
2229
match self {
23-
ChannelSignerType::Ecdsa(ecs) => Some(ecs)
30+
ChannelSignerType::Ecdsa(ecs) => Some(ecs),
31+
_ => None
2432
}
2533
}
2634

27-
pub(crate) fn as_mut_ecdsa(&mut self) -> Option<&mut ECS> {
35+
pub(crate) fn as_mut_ecdsa(&mut self) -> Option<&mut <SP::Target as SignerProvider>::EcdsaSigner> {
2836
match self {
29-
ChannelSignerType::Ecdsa(ecs) => Some(ecs)
37+
ChannelSignerType::Ecdsa(ecs) => Some(ecs),
38+
_ => None
3039
}
3140
}
3241
}

0 commit comments

Comments
 (0)