Skip to content

Commit de4dd95

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 c6bcf75 commit de4dd95

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
@@ -725,7 +725,7 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
725725

726726
latest_monitor_update_id: u64,
727727

728-
holder_signer: ChannelSignerType<<SP::Target as SignerProvider>::EcdsaSigner>,
728+
holder_signer: ChannelSignerType<SP>,
729729
shutdown_scriptpubkey: Option<ShutdownScript>,
730730
destination_script: ScriptBuf,
731731

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

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

@@ -2142,7 +2142,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
21422142
ChannelSignerType::Ecdsa(ecdsa) => {
21432143
ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.secp_ctx)
21442144
.map(|(sig, _)| sig).ok()?
2145-
}
2145+
},
2146+
// TODO (taproot|arik)
2147+
_ => todo!()
21462148
};
21472149

21482150
if self.signer_pending_funding {
@@ -2194,7 +2196,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
21942196

21952197
// We sign "counterparty" commitment transaction, allowing them to broadcast the tx if they wish.
21962198
(counterparty_initial_commitment_tx, funding_signed)
2197-
}
2199+
},
2200+
// TODO (taproot|arik)
2201+
_ => todo!()
21982202
}
21992203
}
22002204
}
@@ -3485,7 +3489,9 @@ impl<SP: Deref> Channel<SP> where
34853489
self.context.cur_counterparty_commitment_transaction_number + 1,
34863490
&secret
34873491
).map_err(|_| ChannelError::Close("Failed to validate revocation from peer".to_owned()))?;
3488-
}
3492+
},
3493+
// TODO (taproot|arik)
3494+
_ => todo!()
34893495
};
34903496

34913497
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
44384444
max_fee_satoshis: our_max_fee,
44394445
}),
44404446
}), None, None))
4441-
}
4447+
},
4448+
// TODO (taproot|arik)
4449+
_ => todo!()
44424450
}
44434451
}
44444452

@@ -4689,7 +4697,9 @@ impl<SP: Deref> Channel<SP> where
46894697
max_fee_satoshis: our_max_fee,
46904698
}),
46914699
}), signed_tx, shutdown_result))
4692-
}
4700+
},
4701+
// TODO (taproot|arik)
4702+
_ => todo!()
46934703
}
46944704
}
46954705
}
@@ -4801,7 +4811,7 @@ impl<SP: Deref> Channel<SP> where
48014811
}
48024812

48034813
#[cfg(test)]
4804-
pub fn get_signer(&self) -> &ChannelSignerType<<SP::Target as SignerProvider>::EcdsaSigner> {
4814+
pub fn get_signer(&self) -> &ChannelSignerType<SP> {
48054815
&self.context.holder_signer
48064816
}
48074817

@@ -5320,7 +5330,9 @@ impl<SP: Deref> Channel<SP> where
53205330
node_signature: our_node_sig,
53215331
bitcoin_signature: our_bitcoin_sig,
53225332
})
5323-
}
5333+
},
5334+
// TODO (taproot|arik)
5335+
_ => todo!()
53245336
}
53255337
}
53265338

@@ -5347,7 +5359,9 @@ impl<SP: Deref> Channel<SP> where
53475359
bitcoin_signature_2: if were_node_one { their_bitcoin_sig } else { our_bitcoin_sig },
53485360
contents: announcement,
53495361
})
5350-
}
5362+
},
5363+
// TODO (taproot|arik)
5364+
_ => todo!()
53515365
}
53525366
} else {
53535367
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
57205734
#[cfg(taproot)]
57215735
partial_signature_with_nonce: None,
57225736
}, (counterparty_commitment_txid, commitment_stats.htlcs_included)))
5723-
}
5737+
},
5738+
// TODO (taproot|arik)
5739+
_ => todo!()
57245740
}
57255741
}
57265742

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)