From d9f5df99b06841fba7eb4be191d05214b5b1e477 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 28 May 2020 16:06:28 -0400 Subject: [PATCH] Drop requirement that all ChannelKeys expose revocaion_basepoint --- lightning/src/chain/keysinterface.rs | 3 --- lightning/src/ln/channel.rs | 8 ++++---- lightning/src/util/enforcing_trait_impls.rs | 4 +--- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/lightning/src/chain/keysinterface.rs b/lightning/src/chain/keysinterface.rs index 88040a04b..10687b74c 100644 --- a/lightning/src/chain/keysinterface.rs +++ b/lightning/src/chain/keysinterface.rs @@ -195,8 +195,6 @@ impl Readable for SpendableOutputDescriptor { // TODO: We should remove Clone by instead requesting a new ChannelKeys copy when we create // ChannelMonitors instead of expecting to clone the one out of the Channel into the monitors. pub trait ChannelKeys : Send+Clone { - /// Gets the local secret key for blinded revocation pubkey - fn revocation_base_key<'a>(&'a self) -> &'a SecretKey; /// Gets the local secret key used in HTLC-Success/HTLC-Timeout txn and to_local output fn delayed_payment_base_key<'a>(&'a self) -> &'a SecretKey; /// Gets the local htlc secret key used in commitment tx htlc outputs @@ -410,7 +408,6 @@ impl InMemoryChannelKeys { } impl ChannelKeys for InMemoryChannelKeys { - fn revocation_base_key(&self) -> &SecretKey { &self.revocation_base_key } fn delayed_payment_base_key(&self) -> &SecretKey { &self.delayed_payment_base_key } fn htlc_base_key(&self) -> &SecretKey { &self.htlc_base_key } fn commitment_seed(&self) -> &[u8; 32] { &self.commitment_seed } diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 48d6e674d..f737e56a7 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -1108,11 +1108,11 @@ impl Channel { fn build_remote_transaction_keys(&self) -> Result { //TODO: Ensure that the payment_key derived here ends up in the library users' wallet as we //may see payments to it! - let revocation_basepoint = PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.revocation_base_key()); + let revocation_basepoint = &self.local_keys.pubkeys().revocation_basepoint; let htlc_basepoint = PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.htlc_base_key()); let their_pubkeys = self.their_pubkeys.as_ref().unwrap(); - Ok(secp_check!(TxCreationKeys::new(&self.secp_ctx, &self.their_cur_commitment_point.unwrap(), &their_pubkeys.delayed_payment_basepoint, &their_pubkeys.htlc_basepoint, &revocation_basepoint, &htlc_basepoint), "Remote tx keys generation got bogus keys")) + Ok(secp_check!(TxCreationKeys::new(&self.secp_ctx, &self.their_cur_commitment_point.unwrap(), &their_pubkeys.delayed_payment_basepoint, &their_pubkeys.htlc_basepoint, revocation_basepoint, &htlc_basepoint), "Remote tx keys generation got bogus keys")) } /// Gets the redeemscript for the funding transaction output (ie the funding transaction output @@ -3315,7 +3315,7 @@ impl Channel { to_self_delay: self.our_to_self_delay, max_accepted_htlcs: OUR_MAX_HTLCS, funding_pubkey: local_keys.funding_pubkey, - revocation_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.revocation_base_key()), + revocation_basepoint: local_keys.revocation_basepoint, payment_point: local_keys.payment_point, delayed_payment_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.delayed_payment_base_key()), htlc_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.htlc_base_key()), @@ -3349,7 +3349,7 @@ impl Channel { to_self_delay: self.our_to_self_delay, max_accepted_htlcs: OUR_MAX_HTLCS, funding_pubkey: local_keys.funding_pubkey, - revocation_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.revocation_base_key()), + revocation_basepoint: local_keys.revocation_basepoint, payment_point: local_keys.payment_point, delayed_payment_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.delayed_payment_base_key()), htlc_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.htlc_base_key()), diff --git a/lightning/src/util/enforcing_trait_impls.rs b/lightning/src/util/enforcing_trait_impls.rs index ffb05762a..425b2124f 100644 --- a/lightning/src/util/enforcing_trait_impls.rs +++ b/lightning/src/util/enforcing_trait_impls.rs @@ -35,7 +35,6 @@ impl EnforcingChannelKeys { impl EnforcingChannelKeys { fn check_keys(&self, secp_ctx: &Secp256k1, keys: &TxCreationKeys) { - let revocation_base = PublicKey::from_secret_key(secp_ctx, &self.inner.revocation_base_key()); let htlc_base = PublicKey::from_secret_key(secp_ctx, &self.inner.htlc_base_key()); let remote_points = self.inner.remote_channel_pubkeys.as_ref().unwrap(); @@ -44,14 +43,13 @@ impl EnforcingChannelKeys { &keys.per_commitment_point, &remote_points.delayed_payment_basepoint, &remote_points.htlc_basepoint, - &revocation_base, + &self.inner.pubkeys().revocation_basepoint, &htlc_base).unwrap(); if keys != &keys_expected { panic!("derived different per-tx keys") } } } impl ChannelKeys for EnforcingChannelKeys { - fn revocation_base_key(&self) -> &SecretKey { self.inner.revocation_base_key() } fn delayed_payment_base_key(&self) -> &SecretKey { self.inner.delayed_payment_base_key() } fn htlc_base_key(&self) -> &SecretKey { self.inner.htlc_base_key() } fn commitment_seed(&self) -> &[u8; 32] { self.inner.commitment_seed() } -- 2.39.5