Skip to content

Commit ebade9a

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 de826fa commit ebade9a

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

694694
latest_monitor_update_id: u64,
695695

696-
holder_signer: ChannelSignerType<<SP::Target as SignerProvider>::EcdsaSigner>,
696+
holder_signer: ChannelSignerType<SP>,
697697
shutdown_scriptpubkey: Option<ShutdownScript>,
698698
destination_script: Script,
699699

@@ -3285,7 +3285,9 @@ impl<SP: Deref> Channel<SP> where
32853285
self.context.cur_counterparty_commitment_transaction_number + 1,
32863286
&secret
32873287
).map_err(|_| ChannelError::Close("Failed to validate revocation from peer".to_owned()))?;
3288-
}
3288+
},
3289+
// TODO (taproot|arik)
3290+
_ => todo!()
32893291
};
32903292

32913293
self.context.commitment_secrets.provide_secret(self.context.cur_counterparty_commitment_transaction_number + 1, msg.per_commitment_secret)
@@ -4176,7 +4178,9 @@ impl<SP: Deref> Channel<SP> where
41764178
max_fee_satoshis: our_max_fee,
41774179
}),
41784180
}), None))
4179-
}
4181+
},
4182+
// TODO (taproot|arik)
4183+
_ => todo!()
41804184
}
41814185
}
41824186

@@ -4416,7 +4420,9 @@ impl<SP: Deref> Channel<SP> where
44164420
max_fee_satoshis: our_max_fee,
44174421
}),
44184422
}), signed_tx))
4419-
}
4423+
},
4424+
// TODO (taproot|arik)
4425+
_ => todo!()
44204426
}
44214427
}
44224428
}
@@ -4528,7 +4534,7 @@ impl<SP: Deref> Channel<SP> where
45284534
}
45294535

45304536
#[cfg(test)]
4531-
pub fn get_signer(&self) -> &ChannelSignerType<<SP::Target as SignerProvider>::EcdsaSigner> {
4537+
pub fn get_signer(&self) -> &ChannelSignerType<SP> {
45324538
&self.context.holder_signer
45334539
}
45344540

@@ -5038,7 +5044,9 @@ impl<SP: Deref> Channel<SP> where
50385044
node_signature: our_node_sig,
50395045
bitcoin_signature: our_bitcoin_sig,
50405046
})
5041-
}
5047+
},
5048+
// TODO (taproot|arik)
5049+
_ => todo!()
50425050
}
50435051
}
50445052

@@ -5065,7 +5073,9 @@ impl<SP: Deref> Channel<SP> where
50655073
bitcoin_signature_2: if were_node_one { their_bitcoin_sig } else { our_bitcoin_sig },
50665074
contents: announcement,
50675075
})
5068-
}
5076+
},
5077+
// TODO (taproot|arik)
5078+
_ => todo!()
50695079
}
50705080
} else {
50715081
Err(ChannelError::Ignore("Attempted to sign channel announcement before we'd received announcement_signatures".to_string()))
@@ -5438,7 +5448,9 @@ impl<SP: Deref> Channel<SP> where
54385448
#[cfg(taproot)]
54395449
partial_signature_with_nonce: None,
54405450
}, (counterparty_commitment_txid, commitment_stats.htlcs_included)))
5441-
}
5451+
},
5452+
// TODO (taproot|arik)
5453+
_ => todo!()
54425454
}
54435455
}
54445456

@@ -5814,7 +5826,9 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
58145826
ChannelSignerType::Ecdsa(ecdsa) => {
58155827
Ok(ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.context.secp_ctx)
58165828
.map_err(|_| ChannelError::Close("Failed to get signatures for new commitment_signed".to_owned()))?.0)
5817-
}
5829+
},
5830+
// TODO (taproot|arik)
5831+
_ => todo!()
58185832
}
58195833
}
58205834

@@ -6553,6 +6567,8 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
65536567
// We sign "counterparty" commitment transaction, allowing them to broadcast the tx if they wish.
65546568
Ok((counterparty_initial_commitment_tx, initial_commitment_tx, counterparty_signature))
65556569
}
6570+
// TODO (taproot|arik)
6571+
_ => todo!()
65566572
}
65576573
}
65586574

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)