]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Drop requirement that ChannelKeys expose delayed_payment_basepoint
authorMatt Corallo <git@bluematt.me>
Thu, 28 May 2020 20:09:47 +0000 (16:09 -0400)
committerMatt Corallo <git@bluematt.me>
Sat, 6 Jun 2020 19:59:27 +0000 (15:59 -0400)
lightning/src/chain/keysinterface.rs
lightning/src/ln/channel.rs
lightning/src/ln/functional_tests.rs
lightning/src/util/enforcing_trait_impls.rs

index 10687b74c88174a3e66b7550eb38f8f15dd798e7..05e24d8c1b220556c2d43e57aa566a6670a302ef 100644 (file)
@@ -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 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
        fn htlc_base_key<'a>(&'a self) -> &'a SecretKey;
        /// Gets the commitment seed
@@ -408,7 +406,6 @@ impl InMemoryChannelKeys {
 }
 
 impl ChannelKeys for InMemoryChannelKeys {
-       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 }
        fn pubkeys<'a>(&'a self) -> &'a ChannelPublicKeys { &self.local_channel_pubkeys }
index f737e56a73d4e29238ffc502d3fcdda41daa2263..0c30a7e96cb53bfec845174a2417e002aedce211 100644 (file)
@@ -1094,11 +1094,11 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
        /// TODO Some magic rust shit to compile-time check this?
        fn build_local_transaction_keys(&self, commitment_number: u64) -> Result<TxCreationKeys, ChannelError> {
                let per_commitment_point = PublicKey::from_secret_key(&self.secp_ctx, &self.build_local_commitment_secret(commitment_number));
-               let delayed_payment_base = PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.delayed_payment_base_key());
+               let delayed_payment_base = &self.local_keys.pubkeys().delayed_payment_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, &per_commitment_point, &delayed_payment_base, &htlc_basepoint, &their_pubkeys.revocation_basepoint, &their_pubkeys.htlc_basepoint), "Local tx keys generation got bogus keys"))
+               Ok(secp_check!(TxCreationKeys::new(&self.secp_ctx, &per_commitment_point, delayed_payment_base, &htlc_basepoint, &their_pubkeys.revocation_basepoint, &their_pubkeys.htlc_basepoint), "Local tx keys generation got bogus keys"))
        }
 
        #[inline]
@@ -3317,7 +3317,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
                        funding_pubkey: local_keys.funding_pubkey,
                        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()),
+                       delayed_payment_basepoint: local_keys.delayed_payment_basepoint,
                        htlc_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.htlc_base_key()),
                        first_per_commitment_point: PublicKey::from_secret_key(&self.secp_ctx, &local_commitment_secret),
                        channel_flags: if self.config.announced_channel {1} else {0},
@@ -3351,7 +3351,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
                        funding_pubkey: local_keys.funding_pubkey,
                        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()),
+                       delayed_payment_basepoint: local_keys.delayed_payment_basepoint,
                        htlc_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.htlc_base_key()),
                        first_per_commitment_point: PublicKey::from_secret_key(&self.secp_ctx, &local_commitment_secret),
                        shutdown_scriptpubkey: OptionalField::Present(if self.config.commit_upfront_shutdown_pubkey { self.get_closing_scriptpubkey() } else { Builder::new().into_script() })
@@ -4476,11 +4476,11 @@ mod tests {
                // We can't just use build_local_transaction_keys here as the per_commitment_secret is not
                // derived from a commitment_seed, so instead we copy it here and call
                // build_commitment_transaction.
-               let delayed_payment_base = PublicKey::from_secret_key(&secp_ctx, chan.local_keys.delayed_payment_base_key());
+               let delayed_payment_base = &chan.local_keys.pubkeys().delayed_payment_basepoint;
                let per_commitment_secret = SecretKey::from_slice(&hex::decode("1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100").unwrap()[..]).unwrap();
                let per_commitment_point = PublicKey::from_secret_key(&secp_ctx, &per_commitment_secret);
                let htlc_basepoint = PublicKey::from_secret_key(&secp_ctx, chan.local_keys.htlc_base_key());
-               let keys = TxCreationKeys::new(&secp_ctx, &per_commitment_point, &delayed_payment_base, &htlc_basepoint, &their_pubkeys.revocation_basepoint, &their_pubkeys.htlc_basepoint).unwrap();
+               let keys = TxCreationKeys::new(&secp_ctx, &per_commitment_point, delayed_payment_base, &htlc_basepoint, &their_pubkeys.revocation_basepoint, &their_pubkeys.htlc_basepoint).unwrap();
 
                chan.their_pubkeys = Some(their_pubkeys);
 
index 9513dc66561efc9a71c6a3157716c5f1bb05b410..bd1b1d4f029ee1799ed0d97cfe9e2ca51ff02f3d 100644 (file)
@@ -4321,7 +4321,7 @@ macro_rules! check_spendable_outputs {
                                                                        };
                                                                        let secp_ctx = Secp256k1::new();
                                                                        let keys = $keysinterface.derive_channel_keys($chan_value, key_derivation_params.0, key_derivation_params.1);
-                                                                       if let Ok(delayed_payment_key) = chan_utils::derive_private_key(&secp_ctx, &per_commitment_point, keys.delayed_payment_base_key()) {
+                                                                       if let Ok(delayed_payment_key) = chan_utils::derive_private_key(&secp_ctx, &per_commitment_point, &keys.inner.delayed_payment_base_key) {
 
                                                                                let delayed_payment_pubkey = PublicKey::from_secret_key(&secp_ctx, &delayed_payment_key);
                                                                                let witness_script = chan_utils::get_revokeable_redeemscript(remote_revocation_pubkey, *to_self_delay, &delayed_payment_pubkey);
index 425b2124f9cc146bca00363489f4118fbfee4638..03df5af861ff200d642e50db67930d5ea7e9a62a 100644 (file)
@@ -50,7 +50,6 @@ impl EnforcingChannelKeys {
 }
 
 impl ChannelKeys for EnforcingChannelKeys {
-       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() }
        fn pubkeys<'a>(&'a self) -> &'a ChannelPublicKeys { self.inner.pubkeys() }