]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Drop requirement that all ChannelKeys expose the payment_point
authorMatt Corallo <git@bluematt.me>
Thu, 28 May 2020 20:03:03 +0000 (16:03 -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/channelmonitor.rs
lightning/src/ln/functional_tests.rs
lightning/src/util/enforcing_trait_impls.rs

index 5859385d9fbc09655f6c52eeb1f5237f4348aa03..88040a04b7f6eece48ea717e6400647ff0d94aa3 100644 (file)
@@ -197,10 +197,6 @@ impl Readable for SpendableOutputDescriptor {
 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 the to_remote output of remote commitment tx (ie the
-       /// output to us in transactions our counterparty broadcasts).
-       /// Also as part of obscured commitment number.
-       fn payment_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
@@ -415,7 +411,6 @@ impl InMemoryChannelKeys {
 
 impl ChannelKeys for InMemoryChannelKeys {
        fn revocation_base_key(&self) -> &SecretKey { &self.revocation_base_key }
-       fn payment_key(&self) -> &SecretKey { &self.payment_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 }
index 9c8fc3431698e527977f21bcaf28c03d1610ac38..48d6e674d03a32928dc8cbdf4fb94d39adaa049a 100644 (file)
@@ -766,15 +766,14 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
 
        fn get_commitment_transaction_number_obscure_factor(&self) -> u64 {
                let mut sha = Sha256::engine();
-               let our_payment_point = PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.payment_key());
 
                let their_payment_point = &self.their_pubkeys.as_ref().unwrap().payment_point.serialize();
                if self.channel_outbound {
-                       sha.input(&our_payment_point.serialize());
+                       sha.input(&self.local_keys.pubkeys().payment_point.serialize());
                        sha.input(their_payment_point);
                } else {
                        sha.input(their_payment_point);
-                       sha.input(&our_payment_point.serialize());
+                       sha.input(&self.local_keys.pubkeys().payment_point.serialize());
                }
                let res = Sha256::from_engine(sha).into_inner();
 
@@ -3317,7 +3316,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
                        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()),
-                       payment_point: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.payment_key()),
+                       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()),
                        first_per_commitment_point: PublicKey::from_secret_key(&self.secp_ctx, &local_commitment_secret),
@@ -3351,7 +3350,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
                        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()),
-                       payment_point: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.payment_key()),
+                       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()),
                        first_per_commitment_point: PublicKey::from_secret_key(&self.secp_ctx, &local_commitment_secret),
index 6d10fdb4f05f049d2d035873d1b986514a0335b4..4f20b1d42fef11b3b68d4128c52d7b08de0ab34d 100644 (file)
@@ -1641,7 +1641,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
                                        self.remote_payment_script = {
                                                // Note that the Network here is ignored as we immediately drop the address for the
                                                // script_pubkey version
-                                               let payment_hash160 = WPubkeyHash::hash(&PublicKey::from_secret_key(&self.secp_ctx, &self.keys.payment_key()).serialize());
+                                               let payment_hash160 = WPubkeyHash::hash(&self.keys.pubkeys().payment_point.serialize());
                                                Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&payment_hash160[..]).into_script()
                                        };
 
index 5eb3602851e90aef62f37bdbf3b9ae5648ce8830..9513dc66561efc9a71c6a3157716c5f1bb05b410 100644 (file)
@@ -4293,10 +4293,10 @@ 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);
-                                                                       let remotepubkey = PublicKey::from_secret_key(&secp_ctx, &keys.payment_key());
+                                                                       let remotepubkey = keys.pubkeys().payment_point;
                                                                        let witness_script = Address::p2pkh(&::bitcoin::PublicKey{compressed: true, key: remotepubkey}, Network::Testnet).script_pubkey();
                                                                        let sighash = Message::from_slice(&bip143::SighashComponents::new(&spend_tx).sighash_all(&spend_tx.input[0], &witness_script, output.value)[..]).unwrap();
-                                                                       let remotesig = secp_ctx.sign(&sighash, &keys.payment_key());
+                                                                       let remotesig = secp_ctx.sign(&sighash, &keys.inner.payment_key);
                                                                        spend_tx.input[0].witness.push(remotesig.serialize_der().to_vec());
                                                                        spend_tx.input[0].witness[0].push(SigHashType::All as u8);
                                                                        spend_tx.input[0].witness.push(remotepubkey.serialize().to_vec());
index 41666374836fc8b72a7be48b58781f42c25027b6..ffb05762ae6f0a5172548560faac57975905d1c9 100644 (file)
@@ -52,7 +52,6 @@ impl EnforcingChannelKeys {
 
 impl ChannelKeys for EnforcingChannelKeys {
        fn revocation_base_key(&self) -> &SecretKey { self.inner.revocation_base_key() }
-       fn payment_key(&self) -> &SecretKey { self.inner.payment_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() }