Skip to content

Commit d36f3a8

Browse files
committed
Eliminate unnecessary generics from Sign
1 parent fc139e8 commit d36f3a8

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

lightning/src/chain/keysinterface.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ pub trait Sign : Send + Writeable {
230230
/// Gets the per-commitment point for a specific commitment number
231231
///
232232
/// Note that the commitment number starts at (1 << 48) - 1 and counts backwards.
233-
fn get_per_commitment_point<T: secp256k1::Signing + secp256k1::Verification>(&self, idx: u64, secp_ctx: &Secp256k1<T>) -> PublicKey;
233+
fn get_per_commitment_point(&self, idx: u64, secp_ctx: &Secp256k1<secp256k1::All>) -> PublicKey;
234234
/// Gets the commitment secret for a specific commitment number as part of the revocation process
235235
///
236236
/// An external signer implementation should error here if the commitment was already signed
@@ -253,7 +253,7 @@ pub trait Sign : Send + Writeable {
253253
/// Note that if signing fails or is rejected, the channel will be force-closed.
254254
//
255255
// TODO: Document the things someone using this interface should enforce before signing.
256-
fn sign_counterparty_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, commitment_tx: &CommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<(Signature, Vec<Signature>), ()>;
256+
fn sign_counterparty_commitment(&self, commitment_tx: &CommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<(Signature, Vec<Signature>), ()>;
257257

258258
/// Create a signatures for a holder's commitment transaction and its claiming HTLC transactions.
259259
/// This will only ever be called with a non-revoked commitment_tx. This will be called with the
@@ -269,14 +269,14 @@ pub trait Sign : Send + Writeable {
269269
//
270270
// TODO: Document the things someone using this interface should enforce before signing.
271271
// TODO: Key derivation failure should panic rather than Err
272-
fn sign_holder_commitment_and_htlcs<T: secp256k1::Signing + secp256k1::Verification>(&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<(Signature, Vec<Signature>), ()>;
272+
fn sign_holder_commitment_and_htlcs(&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<(Signature, Vec<Signature>), ()>;
273273

274274
/// Same as sign_holder_commitment, but exists only for tests to get access to holder commitment
275275
/// transactions which will be broadcasted later, after the channel has moved on to a newer
276276
/// state. Thus, needs its own method as sign_holder_commitment may enforce that we only ever
277277
/// get called once.
278278
#[cfg(any(test,feature = "unsafe_revoked_tx_signing"))]
279-
fn unsafe_sign_holder_commitment_and_htlcs<T: secp256k1::Signing + secp256k1::Verification>(&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<(Signature, Vec<Signature>), ()>;
279+
fn unsafe_sign_holder_commitment_and_htlcs(&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<(Signature, Vec<Signature>), ()>;
280280

281281
/// Create a signature for the given input in a transaction spending an HTLC or commitment
282282
/// transaction output when our counterparty broadcasts an old state.
@@ -296,7 +296,7 @@ pub trait Sign : Send + Writeable {
296296
/// htlc holds HTLC elements (hash, timelock) if the output being spent is a HTLC output, thus
297297
/// changing the format of the witness script (which is committed to in the BIP 143
298298
/// signatures).
299-
fn sign_justice_transaction<T: secp256k1::Signing + secp256k1::Verification>(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, htlc: &Option<HTLCOutputInCommitment>, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()>;
299+
fn sign_justice_transaction(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, htlc: &Option<HTLCOutputInCommitment>, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()>;
300300

301301
/// Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment
302302
/// transaction, either offered or received.
@@ -315,21 +315,21 @@ pub trait Sign : Send + Writeable {
315315
/// detected onchain. It has been generated by our counterparty and is used to derive
316316
/// channel state keys, which are then included in the witness script and committed to in the
317317
/// BIP 143 signature.
318-
fn sign_counterparty_htlc_transaction<T: secp256k1::Signing + secp256k1::Verification>(&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()>;
318+
fn sign_counterparty_htlc_transaction(&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()>;
319319

320320
/// Create a signature for a (proposed) closing transaction.
321321
///
322322
/// Note that, due to rounding, there may be one "missing" satoshi, and either party may have
323323
/// chosen to forgo their output as dust.
324-
fn sign_closing_transaction<T: secp256k1::Signing>(&self, closing_tx: &Transaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()>;
324+
fn sign_closing_transaction(&self, closing_tx: &Transaction, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()>;
325325

326326
/// Signs a channel announcement message with our funding key, proving it comes from one
327327
/// of the channel participants.
328328
///
329329
/// Note that if this fails or is rejected, the channel will not be publicly announced and
330330
/// our counterparty may (though likely will not) close the channel on us for violating the
331331
/// protocol.
332-
fn sign_channel_announcement<T: secp256k1::Signing>(&self, msg: &UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()>;
332+
fn sign_channel_announcement(&self, msg: &UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()>;
333333

334334
/// Set the counterparty static channel data, including basepoints,
335335
/// counterparty_selected/holder_selected_contest_delay and funding outpoint.
@@ -550,7 +550,7 @@ impl InMemorySigner {
550550
}
551551

552552
impl Sign for InMemorySigner {
553-
fn get_per_commitment_point<T: secp256k1::Signing + secp256k1::Verification>(&self, idx: u64, secp_ctx: &Secp256k1<T>) -> PublicKey {
553+
fn get_per_commitment_point(&self, idx: u64, secp_ctx: &Secp256k1<secp256k1::All>) -> PublicKey {
554554
let commitment_secret = SecretKey::from_slice(&chan_utils::build_commitment_secret(&self.commitment_seed, idx)).unwrap();
555555
PublicKey::from_secret_key(secp_ctx, &commitment_secret)
556556
}
@@ -562,7 +562,7 @@ impl Sign for InMemorySigner {
562562
fn pubkeys(&self) -> &ChannelPublicKeys { &self.holder_channel_pubkeys }
563563
fn channel_keys_id(&self) -> [u8; 32] { self.channel_keys_id }
564564

565-
fn sign_counterparty_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, commitment_tx: &CommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<(Signature, Vec<Signature>), ()> {
565+
fn sign_counterparty_commitment(&self, commitment_tx: &CommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<(Signature, Vec<Signature>), ()> {
566566
let trusted_tx = commitment_tx.trust();
567567
let keys = trusted_tx.keys();
568568

@@ -588,7 +588,7 @@ impl Sign for InMemorySigner {
588588
Ok((commitment_sig, htlc_sigs))
589589
}
590590

591-
fn sign_holder_commitment_and_htlcs<T: secp256k1::Signing + secp256k1::Verification>(&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<(Signature, Vec<Signature>), ()> {
591+
fn sign_holder_commitment_and_htlcs(&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<(Signature, Vec<Signature>), ()> {
592592
let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key);
593593
let funding_redeemscript = make_funding_redeemscript(&funding_pubkey, &self.counterparty_pubkeys().funding_pubkey);
594594
let trusted_tx = commitment_tx.trust();
@@ -599,7 +599,7 @@ impl Sign for InMemorySigner {
599599
}
600600

601601
#[cfg(any(test,feature = "unsafe_revoked_tx_signing"))]
602-
fn unsafe_sign_holder_commitment_and_htlcs<T: secp256k1::Signing + secp256k1::Verification>(&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<(Signature, Vec<Signature>), ()> {
602+
fn unsafe_sign_holder_commitment_and_htlcs(&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<(Signature, Vec<Signature>), ()> {
603603
let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key);
604604
let funding_redeemscript = make_funding_redeemscript(&funding_pubkey, &self.counterparty_pubkeys().funding_pubkey);
605605
let trusted_tx = commitment_tx.trust();
@@ -609,7 +609,7 @@ impl Sign for InMemorySigner {
609609
Ok((sig, htlc_sigs))
610610
}
611611

612-
fn sign_justice_transaction<T: secp256k1::Signing + secp256k1::Verification>(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, htlc: &Option<HTLCOutputInCommitment>, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
612+
fn sign_justice_transaction(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, htlc: &Option<HTLCOutputInCommitment>, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
613613
let revocation_key = match chan_utils::derive_private_revocation_key(&secp_ctx, &per_commitment_key, &self.revocation_base_key) {
614614
Ok(revocation_key) => revocation_key,
615615
Err(_) => return Err(())
@@ -641,7 +641,7 @@ impl Sign for InMemorySigner {
641641
return Ok(secp_ctx.sign(&sighash, &revocation_key))
642642
}
643643

644-
fn sign_counterparty_htlc_transaction<T: secp256k1::Signing + secp256k1::Verification>(&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
644+
fn sign_counterparty_htlc_transaction(&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
645645
if let Ok(htlc_key) = chan_utils::derive_private_key(&secp_ctx, &per_commitment_point, &self.htlc_base_key) {
646646
let witness_script = if let Ok(revocation_pubkey) = chan_utils::derive_public_revocation_key(&secp_ctx, &per_commitment_point, &self.pubkeys().revocation_basepoint) {
647647
if let Ok(counterparty_htlcpubkey) = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.counterparty_pubkeys().htlc_basepoint) {
@@ -657,7 +657,7 @@ impl Sign for InMemorySigner {
657657
Err(())
658658
}
659659

660-
fn sign_closing_transaction<T: secp256k1::Signing>(&self, closing_tx: &Transaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
660+
fn sign_closing_transaction(&self, closing_tx: &Transaction, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
661661
if closing_tx.input.len() != 1 { return Err(()); }
662662
if closing_tx.input[0].witness.len() != 0 { return Err(()); }
663663
if closing_tx.output.len() > 2 { return Err(()); }
@@ -670,7 +670,7 @@ impl Sign for InMemorySigner {
670670
Ok(secp_ctx.sign(&sighash, &self.funding_key))
671671
}
672672

673-
fn sign_channel_announcement<T: secp256k1::Signing>(&self, msg: &UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
673+
fn sign_channel_announcement(&self, msg: &UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
674674
let msghash = hash_to_message!(&Sha256dHash::hash(&msg.encode()[..])[..]);
675675
Ok(secp_ctx.sign(&msghash, &self.funding_key))
676676
}
@@ -738,7 +738,7 @@ impl Readable for InMemorySigner {
738738
/// Cooperative closes may use seed/2'
739739
/// The two close keys may be needed to claim on-chain funds!
740740
pub struct KeysManager {
741-
secp_ctx: Secp256k1<secp256k1::SignOnly>,
741+
secp_ctx: Secp256k1<secp256k1::All>,
742742
node_secret: SecretKey,
743743
destination_script: Script,
744744
shutdown_pubkey: PublicKey,
@@ -775,7 +775,7 @@ impl KeysManager {
775775
/// versions. Once the library is more fully supported, the docs will be updated to include a
776776
/// detailed description of the guarantee.
777777
pub fn new(seed: &[u8; 32], starting_time_secs: u64, starting_time_nanos: u32) -> Self {
778-
let secp_ctx = Secp256k1::signing_only();
778+
let secp_ctx = Secp256k1::new();
779779
// Note that when we aren't serializing the key, network doesn't matter
780780
match ExtendedPrivKey::new_master(Network::Testnet, seed) {
781781
Ok(master_key) => {

lightning/src/util/enforcing_trait_impls.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl EnforcingSigner {
7575
}
7676

7777
impl Sign for EnforcingSigner {
78-
fn get_per_commitment_point<T: secp256k1::Signing + secp256k1::Verification>(&self, idx: u64, secp_ctx: &Secp256k1<T>) -> PublicKey {
78+
fn get_per_commitment_point(&self, idx: u64, secp_ctx: &Secp256k1<secp256k1::All>) -> PublicKey {
7979
self.inner.get_per_commitment_point(idx, secp_ctx)
8080
}
8181

@@ -91,7 +91,7 @@ impl Sign for EnforcingSigner {
9191
fn pubkeys(&self) -> &ChannelPublicKeys { self.inner.pubkeys() }
9292
fn channel_keys_id(&self) -> [u8; 32] { self.inner.channel_keys_id() }
9393

94-
fn sign_counterparty_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, commitment_tx: &CommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<(Signature, Vec<Signature>), ()> {
94+
fn sign_counterparty_commitment(&self, commitment_tx: &CommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<(Signature, Vec<Signature>), ()> {
9595
self.verify_counterparty_commitment_tx(commitment_tx, secp_ctx);
9696

9797
{
@@ -107,7 +107,7 @@ impl Sign for EnforcingSigner {
107107
Ok(self.inner.sign_counterparty_commitment(commitment_tx, secp_ctx).unwrap())
108108
}
109109

110-
fn sign_holder_commitment_and_htlcs<T: secp256k1::Signing + secp256k1::Verification>(&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<(Signature, Vec<Signature>), ()> {
110+
fn sign_holder_commitment_and_htlcs(&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<(Signature, Vec<Signature>), ()> {
111111
let trusted_tx = self.verify_holder_commitment_tx(commitment_tx, secp_ctx);
112112
let commitment_txid = trusted_tx.txid();
113113
let holder_csv = self.inner.counterparty_selected_contest_delay();
@@ -136,23 +136,23 @@ impl Sign for EnforcingSigner {
136136
}
137137

138138
#[cfg(any(test,feature = "unsafe_revoked_tx_signing"))]
139-
fn unsafe_sign_holder_commitment_and_htlcs<T: secp256k1::Signing + secp256k1::Verification>(&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<(Signature, Vec<Signature>), ()> {
139+
fn unsafe_sign_holder_commitment_and_htlcs(&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<(Signature, Vec<Signature>), ()> {
140140
Ok(self.inner.unsafe_sign_holder_commitment_and_htlcs(commitment_tx, secp_ctx).unwrap())
141141
}
142142

143-
fn sign_justice_transaction<T: secp256k1::Signing + secp256k1::Verification>(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, htlc: &Option<HTLCOutputInCommitment>, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
143+
fn sign_justice_transaction(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, htlc: &Option<HTLCOutputInCommitment>, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
144144
Ok(self.inner.sign_justice_transaction(justice_tx, input, amount, per_commitment_key, htlc, secp_ctx).unwrap())
145145
}
146146

147-
fn sign_counterparty_htlc_transaction<T: secp256k1::Signing + secp256k1::Verification>(&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
147+
fn sign_counterparty_htlc_transaction(&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
148148
Ok(self.inner.sign_counterparty_htlc_transaction(htlc_tx, input, amount, per_commitment_point, htlc, secp_ctx).unwrap())
149149
}
150150

151-
fn sign_closing_transaction<T: secp256k1::Signing>(&self, closing_tx: &Transaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
151+
fn sign_closing_transaction(&self, closing_tx: &Transaction, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
152152
Ok(self.inner.sign_closing_transaction(closing_tx, secp_ctx).unwrap())
153153
}
154154

155-
fn sign_channel_announcement<T: secp256k1::Signing>(&self, msg: &msgs::UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
155+
fn sign_channel_announcement(&self, msg: &msgs::UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
156156
self.inner.sign_channel_announcement(msg, secp_ctx)
157157
}
158158

0 commit comments

Comments
 (0)