Skip to content

Commit aac17b1

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 9dd5d3f commit aac17b1

File tree

2 files changed

+46
-21
lines changed

2 files changed

+46
-21
lines changed

lightning/src/ln/channel.rs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
722722

723723
latest_monitor_update_id: u64,
724724

725-
holder_signer: ChannelSignerType<<SP::Target as SignerProvider>::EcdsaSigner>,
725+
holder_signer: ChannelSignerType<SP>,
726726
shutdown_scriptpubkey: Option<ShutdownScript>,
727727
destination_script: Script,
728728

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

10801080
/// Returns the holder signer for this channel.
10811081
#[cfg(test)]
1082-
pub fn get_signer(&self) -> &ChannelSignerType<<SP::Target as SignerProvider>::EcdsaSigner> {
1082+
pub fn get_signer(&self) -> &ChannelSignerType<SP> {
10831083
return &self.holder_signer
10841084
}
10851085

@@ -2116,7 +2116,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
21162116
ChannelSignerType::Ecdsa(ecdsa) => {
21172117
ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.secp_ctx)
21182118
.map(|(sig, _)| sig).ok()?
2119-
}
2119+
},
2120+
// TODO (taproot|arik)
2121+
_ => todo!()
21202122
};
21212123

21222124
if self.signer_pending_funding {
@@ -2168,7 +2170,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
21682170

21692171
// We sign "counterparty" commitment transaction, allowing them to broadcast the tx if they wish.
21702172
(counterparty_initial_commitment_tx, funding_signed)
2171-
}
2173+
},
2174+
// TODO (taproot|arik)
2175+
_ => todo!()
21722176
}
21732177
}
21742178
}
@@ -3472,7 +3476,9 @@ impl<SP: Deref> Channel<SP> where
34723476
self.context.cur_counterparty_commitment_transaction_number + 1,
34733477
&secret
34743478
).map_err(|_| ChannelError::Close("Failed to validate revocation from peer".to_owned()))?;
3475-
}
3479+
},
3480+
// TODO (taproot|arik)
3481+
_ => todo!()
34763482
};
34773483

34783484
self.context.commitment_secrets.provide_secret(self.context.cur_counterparty_commitment_transaction_number + 1, msg.per_commitment_secret)
@@ -4414,7 +4420,9 @@ impl<SP: Deref> Channel<SP> where
44144420
max_fee_satoshis: our_max_fee,
44154421
}),
44164422
}), None, None))
4417-
}
4423+
},
4424+
// TODO (taproot|arik)
4425+
_ => todo!()
44184426
}
44194427
}
44204428

@@ -4665,7 +4673,9 @@ impl<SP: Deref> Channel<SP> where
46654673
max_fee_satoshis: our_max_fee,
46664674
}),
46674675
}), signed_tx, shutdown_result))
4668-
}
4676+
},
4677+
// TODO (taproot|arik)
4678+
_ => todo!()
46694679
}
46704680
}
46714681
}
@@ -4777,7 +4787,7 @@ impl<SP: Deref> Channel<SP> where
47774787
}
47784788

47794789
#[cfg(test)]
4780-
pub fn get_signer(&self) -> &ChannelSignerType<<SP::Target as SignerProvider>::EcdsaSigner> {
4790+
pub fn get_signer(&self) -> &ChannelSignerType<SP> {
47814791
&self.context.holder_signer
47824792
}
47834793

@@ -5296,7 +5306,9 @@ impl<SP: Deref> Channel<SP> where
52965306
node_signature: our_node_sig,
52975307
bitcoin_signature: our_bitcoin_sig,
52985308
})
5299-
}
5309+
},
5310+
// TODO (taproot|arik)
5311+
_ => todo!()
53005312
}
53015313
}
53025314

@@ -5323,7 +5335,9 @@ impl<SP: Deref> Channel<SP> where
53235335
bitcoin_signature_2: if were_node_one { their_bitcoin_sig } else { our_bitcoin_sig },
53245336
contents: announcement,
53255337
})
5326-
}
5338+
},
5339+
// TODO (taproot|arik)
5340+
_ => todo!()
53275341
}
53285342
} else {
53295343
Err(ChannelError::Ignore("Attempted to sign channel announcement before we'd received announcement_signatures".to_string()))
@@ -5696,7 +5710,9 @@ impl<SP: Deref> Channel<SP> where
56965710
#[cfg(taproot)]
56975711
partial_signature_with_nonce: None,
56985712
}, (counterparty_commitment_txid, commitment_stats.htlcs_included)))
5699-
}
5713+
},
5714+
// TODO (taproot|arik)
5715+
_ => todo!()
57005716
}
57015717
}
57025718

lightning/src/sign/type_resolver.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,42 @@
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

2735
#[allow(unused)]
28-
pub(crate) fn as_mut_ecdsa(&mut self) -> Option<&mut ECS> {
36+
pub(crate) fn as_mut_ecdsa(&mut self) -> Option<&mut <SP::Target as SignerProvider>::EcdsaSigner> {
2937
match self {
30-
ChannelSignerType::Ecdsa(ecs) => Some(ecs)
38+
ChannelSignerType::Ecdsa(ecs) => Some(ecs),
39+
_ => None
3140
}
3241
}
3342
}

0 commit comments

Comments
 (0)