Skip to content

Commit 20f4893

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 1b62ebb commit 20f4893

File tree

3 files changed

+47
-21
lines changed

3 files changed

+47
-21
lines changed

lightning/src/ln/channel.rs

+27-11
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
723723

724724
latest_monitor_update_id: u64,
725725

726-
holder_signer: ChannelSignerType<<SP::Target as SignerProvider>::EcdsaSigner>,
726+
holder_signer: ChannelSignerType<SP>,
727727
shutdown_scriptpubkey: Option<ShutdownScript>,
728728
destination_script: ScriptBuf,
729729

@@ -1093,7 +1093,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
10931093

10941094
/// Returns the holder signer for this channel.
10951095
#[cfg(test)]
1096-
pub fn get_signer(&self) -> &ChannelSignerType<<SP::Target as SignerProvider>::EcdsaSigner> {
1096+
pub fn get_signer(&self) -> &ChannelSignerType<SP> {
10971097
return &self.holder_signer
10981098
}
10991099

@@ -2130,7 +2130,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
21302130
ChannelSignerType::Ecdsa(ecdsa) => {
21312131
ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.secp_ctx)
21322132
.map(|(sig, _)| sig).ok()?
2133-
}
2133+
},
2134+
// TODO (taproot|arik)
2135+
_ => todo!()
21342136
};
21352137

21362138
if self.signer_pending_funding {
@@ -2182,7 +2184,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
21822184

21832185
// We sign "counterparty" commitment transaction, allowing them to broadcast the tx if they wish.
21842186
(counterparty_initial_commitment_tx, funding_signed)
2185-
}
2187+
},
2188+
// TODO (taproot|arik)
2189+
_ => todo!()
21862190
}
21872191
}
21882192
}
@@ -3473,7 +3477,9 @@ impl<SP: Deref> Channel<SP> where
34733477
self.context.cur_counterparty_commitment_transaction_number + 1,
34743478
&secret
34753479
).map_err(|_| ChannelError::Close("Failed to validate revocation from peer".to_owned()))?;
3476-
}
3480+
},
3481+
// TODO (taproot|arik)
3482+
_ => todo!()
34773483
};
34783484

34793485
self.context.commitment_secrets.provide_secret(self.context.cur_counterparty_commitment_transaction_number + 1, msg.per_commitment_secret)
@@ -4426,7 +4432,9 @@ impl<SP: Deref> Channel<SP> where
44264432
max_fee_satoshis: our_max_fee,
44274433
}),
44284434
}), None, None))
4429-
}
4435+
},
4436+
// TODO (taproot|arik)
4437+
_ => todo!()
44304438
}
44314439
}
44324440

@@ -4677,7 +4685,9 @@ impl<SP: Deref> Channel<SP> where
46774685
max_fee_satoshis: our_max_fee,
46784686
}),
46794687
}), signed_tx, shutdown_result))
4680-
}
4688+
},
4689+
// TODO (taproot|arik)
4690+
_ => todo!()
46814691
}
46824692
}
46834693
}
@@ -4789,7 +4799,7 @@ impl<SP: Deref> Channel<SP> where
47894799
}
47904800

47914801
#[cfg(test)]
4792-
pub fn get_signer(&self) -> &ChannelSignerType<<SP::Target as SignerProvider>::EcdsaSigner> {
4802+
pub fn get_signer(&self) -> &ChannelSignerType<SP> {
47934803
&self.context.holder_signer
47944804
}
47954805

@@ -5308,7 +5318,9 @@ impl<SP: Deref> Channel<SP> where
53085318
node_signature: our_node_sig,
53095319
bitcoin_signature: our_bitcoin_sig,
53105320
})
5311-
}
5321+
},
5322+
// TODO (taproot|arik)
5323+
_ => todo!()
53125324
}
53135325
}
53145326

@@ -5335,7 +5347,9 @@ impl<SP: Deref> Channel<SP> where
53355347
bitcoin_signature_2: if were_node_one { their_bitcoin_sig } else { our_bitcoin_sig },
53365348
contents: announcement,
53375349
})
5338-
}
5350+
},
5351+
// TODO (taproot|arik)
5352+
_ => todo!()
53395353
}
53405354
} else {
53415355
Err(ChannelError::Ignore("Attempted to sign channel announcement before we'd received announcement_signatures".to_string()))
@@ -5708,7 +5722,9 @@ impl<SP: Deref> Channel<SP> where
57085722
#[cfg(taproot)]
57095723
partial_signature_with_nonce: None,
57105724
}, (counterparty_commitment_txid, commitment_stats.htlcs_included)))
5711-
}
5725+
},
5726+
// TODO (taproot|arik)
5727+
_ => todo!()
57125728
}
57135729
}
57145730

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,34 +1,43 @@
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

2128
#[allow(unused)]
22-
pub(crate) fn as_ecdsa(&self) -> Option<&ECS> {
29+
pub(crate) fn as_ecdsa(&self) -> Option<&<SP::Target as SignerProvider>::EcdsaSigner> {
2330
match self {
24-
ChannelSignerType::Ecdsa(ecs) => Some(ecs)
31+
ChannelSignerType::Ecdsa(ecs) => Some(ecs),
32+
_ => None
2533
}
2634
}
2735

2836
#[allow(unused)]
29-
pub(crate) fn as_mut_ecdsa(&mut self) -> Option<&mut ECS> {
37+
pub(crate) fn as_mut_ecdsa(&mut self) -> Option<&mut <SP::Target as SignerProvider>::EcdsaSigner> {
3038
match self {
31-
ChannelSignerType::Ecdsa(ecs) => Some(ecs)
39+
ChannelSignerType::Ecdsa(ecs) => Some(ecs),
40+
_ => None
3241
}
3342
}
3443
}

0 commit comments

Comments
 (0)