]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Rename payment_basepoint/key to simply payment_point/key. 2020-03-static-remotekey
authorMatt Corallo <git@bluematt.me>
Mon, 9 Mar 2020 00:38:16 +0000 (20:38 -0400)
committerMatt Corallo <git@bluematt.me>
Wed, 6 May 2020 01:42:36 +0000 (21:42 -0400)
We no longer derive any keys from the payment point, so they aren't
a "base" but simply a point/key.

lightning/src/chain/keysinterface.rs
lightning/src/ln/chan_utils.rs
lightning/src/ln/channel.rs
lightning/src/ln/channelmonitor.rs
lightning/src/ln/functional_tests.rs
lightning/src/ln/msgs.rs
lightning/src/util/enforcing_trait_impls.rs

index fdcac550928112b83cdf58beb7ee662bc6a42587..9ed28e12fe8e983dc40f3a2abb7d00a36a018763 100644 (file)
@@ -196,9 +196,10 @@ pub trait ChannelKeys : Send+Clone {
        fn funding_key<'a>(&'a self) -> &'a SecretKey;
        /// 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 to_remote output of remote commitment tx
-       /// (and also as part of obscured commitment number)
-       fn payment_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
@@ -275,8 +276,8 @@ pub struct InMemoryChannelKeys {
        funding_key: SecretKey,
        /// Local secret key for blinded revocation pubkey
        revocation_base_key: SecretKey,
-       /// Local secret key used in commitment tx htlc outputs
-       payment_base_key: SecretKey,
+       /// Local secret key used for our balance in remote-broadcasted commitment transactions
+       payment_key: SecretKey,
        /// Local secret key used in HTLC tx
        delayed_payment_base_key: SecretKey,
        /// Local htlc secret key used in commitment tx htlc outputs
@@ -297,19 +298,19 @@ impl InMemoryChannelKeys {
                secp_ctx: &Secp256k1<C>,
                funding_key: SecretKey,
                revocation_base_key: SecretKey,
-               payment_base_key: SecretKey,
+               payment_key: SecretKey,
                delayed_payment_base_key: SecretKey,
                htlc_base_key: SecretKey,
                commitment_seed: [u8; 32],
                channel_value_satoshis: u64) -> InMemoryChannelKeys {
                let local_channel_pubkeys =
                        InMemoryChannelKeys::make_local_keys(secp_ctx, &funding_key, &revocation_base_key,
-                                                            &payment_base_key, &delayed_payment_base_key,
+                                                            &payment_key, &delayed_payment_base_key,
                                                             &htlc_base_key);
                InMemoryChannelKeys {
                        funding_key,
                        revocation_base_key,
-                       payment_base_key,
+                       payment_key,
                        delayed_payment_base_key,
                        htlc_base_key,
                        commitment_seed,
@@ -322,14 +323,14 @@ impl InMemoryChannelKeys {
        fn make_local_keys<C: Signing>(secp_ctx: &Secp256k1<C>,
                                       funding_key: &SecretKey,
                                       revocation_base_key: &SecretKey,
-                                      payment_base_key: &SecretKey,
+                                      payment_key: &SecretKey,
                                       delayed_payment_base_key: &SecretKey,
                                       htlc_base_key: &SecretKey) -> ChannelPublicKeys {
                let from_secret = |s: &SecretKey| PublicKey::from_secret_key(secp_ctx, s);
                ChannelPublicKeys {
                        funding_pubkey: from_secret(&funding_key),
                        revocation_basepoint: from_secret(&revocation_base_key),
-                       payment_basepoint: from_secret(&payment_base_key),
+                       payment_point: from_secret(&payment_key),
                        delayed_payment_basepoint: from_secret(&delayed_payment_base_key),
                        htlc_basepoint: from_secret(&htlc_base_key),
                }
@@ -339,7 +340,7 @@ impl InMemoryChannelKeys {
 impl ChannelKeys for InMemoryChannelKeys {
        fn funding_key(&self) -> &SecretKey { &self.funding_key }
        fn revocation_base_key(&self) -> &SecretKey { &self.revocation_base_key }
-       fn payment_base_key(&self) -> &SecretKey { &self.payment_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 }
@@ -424,7 +425,7 @@ impl Writeable for InMemoryChannelKeys {
        fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error> {
                self.funding_key.write(writer)?;
                self.revocation_base_key.write(writer)?;
-               self.payment_base_key.write(writer)?;
+               self.payment_key.write(writer)?;
                self.delayed_payment_base_key.write(writer)?;
                self.htlc_base_key.write(writer)?;
                self.commitment_seed.write(writer)?;
@@ -439,7 +440,7 @@ impl Readable for InMemoryChannelKeys {
        fn read<R: ::std::io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
                let funding_key = Readable::read(reader)?;
                let revocation_base_key = Readable::read(reader)?;
-               let payment_base_key = Readable::read(reader)?;
+               let payment_key = Readable::read(reader)?;
                let delayed_payment_base_key = Readable::read(reader)?;
                let htlc_base_key = Readable::read(reader)?;
                let commitment_seed = Readable::read(reader)?;
@@ -448,13 +449,13 @@ impl Readable for InMemoryChannelKeys {
                let secp_ctx = Secp256k1::signing_only();
                let local_channel_pubkeys =
                        InMemoryChannelKeys::make_local_keys(&secp_ctx, &funding_key, &revocation_base_key,
-                                                            &payment_base_key, &delayed_payment_base_key,
+                                                            &payment_key, &delayed_payment_base_key,
                                                             &htlc_base_key);
 
                Ok(InMemoryChannelKeys {
                        funding_key,
                        revocation_base_key,
-                       payment_base_key,
+                       payment_key,
                        delayed_payment_base_key,
                        htlc_base_key,
                        commitment_seed,
@@ -600,15 +601,15 @@ impl KeysInterface for KeysManager {
                }
                let funding_key = key_step!(b"funding key", commitment_seed);
                let revocation_base_key = key_step!(b"revocation base key", funding_key);
-               let payment_base_key = key_step!(b"payment base key", revocation_base_key);
-               let delayed_payment_base_key = key_step!(b"delayed payment base key", payment_base_key);
+               let payment_key = key_step!(b"payment key", revocation_base_key);
+               let delayed_payment_base_key = key_step!(b"delayed payment base key", payment_key);
                let htlc_base_key = key_step!(b"HTLC base key", delayed_payment_base_key);
 
                InMemoryChannelKeys::new(
                        &self.secp_ctx,
                        funding_key,
                        revocation_base_key,
-                       payment_base_key,
+                       payment_key,
                        delayed_payment_base_key,
                        htlc_base_key,
                        commitment_seed,
index a57fafcd99216a03b6de02f3a56c0b56bb2a873d..c229819c3b64e6d3e875002c814190a1d40e153e 100644 (file)
@@ -277,9 +277,10 @@ pub struct ChannelPublicKeys {
        /// a commitment transaction so that their counterparty can claim all available funds if they
        /// broadcast an old state.
        pub revocation_basepoint: PublicKey,
-       /// The base point which is used (with derive_public_key) to derive a per-commitment payment
-       /// public key which receives immediately-spendable non-HTLC-encumbered funds.
-       pub payment_basepoint: PublicKey,
+       /// The public key which receives our immediately spendable primary channel balance in
+       /// remote-broadcasted commitment transactions. This key is static across every commitment
+       /// transaction.
+       pub payment_point: PublicKey,
        /// The base point which is used (with derive_public_key) to derive a per-commitment payment
        /// public key which receives non-HTLC-encumbered funds which are only available for spending
        /// after some delay (or can be claimed via the revocation path).
@@ -292,7 +293,7 @@ pub struct ChannelPublicKeys {
 impl_writeable!(ChannelPublicKeys, 33*5, {
        funding_pubkey,
        revocation_basepoint,
-       payment_basepoint,
+       payment_point,
        delayed_payment_basepoint,
        htlc_basepoint
 });
index fca1cee2da828bf900cf3465f80fe90b0780514a..53946720e69f48a3c54f39d59923f259f97e6ecf 100644 (file)
@@ -556,7 +556,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
                let their_pubkeys = ChannelPublicKeys {
                        funding_pubkey: msg.funding_pubkey,
                        revocation_basepoint: msg.revocation_basepoint,
-                       payment_basepoint: msg.payment_basepoint,
+                       payment_point: msg.payment_point,
                        delayed_payment_basepoint: msg.delayed_payment_basepoint,
                        htlc_basepoint: msg.htlc_basepoint
                };
@@ -772,15 +772,15 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
 
        fn get_commitment_transaction_number_obscure_factor(&self) -> u64 {
                let mut sha = Sha256::engine();
-               let our_payment_basepoint = PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.payment_base_key());
+               let our_payment_point = PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.payment_key());
 
-               let their_payment_basepoint = &self.their_pubkeys.as_ref().unwrap().payment_basepoint.serialize();
+               let their_payment_point = &self.their_pubkeys.as_ref().unwrap().payment_point.serialize();
                if self.channel_outbound {
-                       sha.input(&our_payment_basepoint.serialize());
-                       sha.input(their_payment_basepoint);
+                       sha.input(&our_payment_point.serialize());
+                       sha.input(their_payment_point);
                } else {
-                       sha.input(their_payment_basepoint);
-                       sha.input(&our_payment_basepoint.serialize());
+                       sha.input(their_payment_point);
+                       sha.input(&our_payment_point.serialize());
                }
                let res = Sha256::from_engine(sha).into_inner();
 
@@ -978,9 +978,9 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
                if value_to_b >= (dust_limit_satoshis as i64) {
                        log_trace!(self, "   ...including {} output with value {}", if local { "to_remote" } else { "to_local" }, value_to_b);
                        let static_payment_pk = if local {
-                               self.their_pubkeys.as_ref().unwrap().payment_basepoint
+                               self.their_pubkeys.as_ref().unwrap().payment_point
                        } else {
-                               self.local_keys.pubkeys().payment_basepoint
+                               self.local_keys.pubkeys().payment_point
                        }.serialize();
                        txouts.push((TxOut {
                                script_pubkey: Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0)
@@ -1434,7 +1434,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
                let their_pubkeys = ChannelPublicKeys {
                        funding_pubkey: msg.funding_pubkey,
                        revocation_basepoint: msg.revocation_basepoint,
-                       payment_basepoint: msg.payment_basepoint,
+                       payment_point: msg.payment_point,
                        delayed_payment_basepoint: msg.delayed_payment_basepoint,
                        htlc_basepoint: msg.htlc_basepoint
                };
@@ -3321,7 +3321,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
                        max_accepted_htlcs: OUR_MAX_HTLCS,
                        funding_pubkey: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.funding_key()),
                        revocation_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.revocation_base_key()),
-                       payment_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.payment_base_key()),
+                       payment_point: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.payment_key()),
                        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),
@@ -3354,7 +3354,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
                        max_accepted_htlcs: OUR_MAX_HTLCS,
                        funding_pubkey: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.funding_key()),
                        revocation_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.revocation_base_key()),
-                       payment_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.payment_base_key()),
+                       payment_point: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.payment_key()),
                        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),
@@ -4464,13 +4464,13 @@ mod tests {
                let their_pubkeys = ChannelPublicKeys {
                        funding_pubkey: public_from_secret_hex(&secp_ctx, "1552dfba4f6cf29a62a0af13c8d6981d36d0ef8d61ba10fb0fe90da7634d7e13"),
                        revocation_basepoint: PublicKey::from_slice(&hex::decode("02466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f27").unwrap()[..]).unwrap(),
-                       payment_basepoint: public_from_secret_hex(&secp_ctx, "4444444444444444444444444444444444444444444444444444444444444444"),
+                       payment_point: public_from_secret_hex(&secp_ctx, "4444444444444444444444444444444444444444444444444444444444444444"),
                        delayed_payment_basepoint: public_from_secret_hex(&secp_ctx, "1552dfba4f6cf29a62a0af13c8d6981d36d0ef8d61ba10fb0fe90da7634d7e13"),
                        htlc_basepoint: public_from_secret_hex(&secp_ctx, "4444444444444444444444444444444444444444444444444444444444444444")
                };
                chan_keys.set_remote_channel_pubkeys(&their_pubkeys);
 
-               assert_eq!(their_pubkeys.payment_basepoint.serialize()[..],
+               assert_eq!(their_pubkeys.payment_point.serialize()[..],
                           hex::decode("032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991").unwrap()[..]);
 
                assert_eq!(their_pubkeys.funding_pubkey.serialize()[..],
index e1143732a279f0b8833fbd7d8d722a9debf57dd4..c8fe6f1e306fd0840226580510ef469377ba319d 100644 (file)
@@ -1042,8 +1042,8 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
                assert!(commitment_transaction_number_obscure_factor <= (1 << 48));
                let our_channel_close_key_hash = WPubkeyHash::hash(&shutdown_pubkey.serialize());
                let shutdown_script = Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_close_key_hash[..]).into_script();
-               let payment_base_key_hash = WPubkeyHash::hash(&keys.pubkeys().payment_basepoint.serialize());
-               let remote_payment_script = Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&payment_base_key_hash[..]).into_script();
+               let payment_key_hash = WPubkeyHash::hash(&keys.pubkeys().payment_point.serialize());
+               let remote_payment_script = Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&payment_key_hash[..]).into_script();
 
                let mut onchain_tx_handler = OnchainTxHandler::new(destination_script.clone(), keys.clone(), their_to_self_delay, logger.clone());
 
@@ -2130,7 +2130,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
                        } else if self.remote_payment_script == outp.script_pubkey {
                                spendable_output = Some(SpendableOutputDescriptor::DynamicOutputP2WPKH {
                                        outpoint: BitcoinOutPoint { txid: tx.txid(), vout: i as u32 },
-                                       key: self.keys.payment_base_key().clone(),
+                                       key: self.keys.payment_key().clone(),
                                        output: outp.clone(),
                                });
                                break;
index 8093b49228ab93b9390f3b5e3e3b1265fe8f6bf4..8794b4357501f2fccf4950641222523c59a40108 100644 (file)
@@ -5775,7 +5775,7 @@ fn bolt2_open_channel_sending_node_checks_part2() {
        assert!(PublicKey::from_slice(&node0_to_1_send_open_channel.funding_pubkey.serialize()).is_ok());
        assert!(PublicKey::from_slice(&node0_to_1_send_open_channel.revocation_basepoint.serialize()).is_ok());
        assert!(PublicKey::from_slice(&node0_to_1_send_open_channel.htlc_basepoint.serialize()).is_ok());
-       assert!(PublicKey::from_slice(&node0_to_1_send_open_channel.payment_basepoint.serialize()).is_ok());
+       assert!(PublicKey::from_slice(&node0_to_1_send_open_channel.payment_point.serialize()).is_ok());
        assert!(PublicKey::from_slice(&node0_to_1_send_open_channel.delayed_payment_basepoint.serialize()).is_ok());
 }
 
index cce8c3d0b121722ff4b3ec24f592cc89067687de..43005ad1d65370095f70e28823fc53ef2b95386f 100644 (file)
@@ -97,7 +97,7 @@ pub struct OpenChannel {
        pub(crate) max_accepted_htlcs: u16,
        pub(crate) funding_pubkey: PublicKey,
        pub(crate) revocation_basepoint: PublicKey,
-       pub(crate) payment_basepoint: PublicKey,
+       pub(crate) payment_point: PublicKey,
        pub(crate) delayed_payment_basepoint: PublicKey,
        pub(crate) htlc_basepoint: PublicKey,
        pub(crate) first_per_commitment_point: PublicKey,
@@ -118,7 +118,7 @@ pub struct AcceptChannel {
        pub(crate) max_accepted_htlcs: u16,
        pub(crate) funding_pubkey: PublicKey,
        pub(crate) revocation_basepoint: PublicKey,
-       pub(crate) payment_basepoint: PublicKey,
+       pub(crate) payment_point: PublicKey,
        pub(crate) delayed_payment_basepoint: PublicKey,
        pub(crate) htlc_basepoint: PublicKey,
        pub(crate) first_per_commitment_point: PublicKey,
@@ -757,7 +757,7 @@ impl_writeable_len_match!(AcceptChannel, {
        max_accepted_htlcs,
        funding_pubkey,
        revocation_basepoint,
-       payment_basepoint,
+       payment_point,
        delayed_payment_basepoint,
        htlc_basepoint,
        first_per_commitment_point,
@@ -884,7 +884,7 @@ impl_writeable_len_match!(OpenChannel, {
        max_accepted_htlcs,
        funding_pubkey,
        revocation_basepoint,
-       payment_basepoint,
+       payment_point,
        delayed_payment_basepoint,
        htlc_basepoint,
        first_per_commitment_point,
@@ -1686,7 +1686,7 @@ mod tests {
                        max_accepted_htlcs: 49340,
                        funding_pubkey: pubkey_1,
                        revocation_basepoint: pubkey_2,
-                       payment_basepoint: pubkey_3,
+                       payment_point: pubkey_3,
                        delayed_payment_basepoint: pubkey_4,
                        htlc_basepoint: pubkey_5,
                        first_per_commitment_point: pubkey_6,
@@ -1740,7 +1740,7 @@ mod tests {
                        max_accepted_htlcs: 49340,
                        funding_pubkey: pubkey_1,
                        revocation_basepoint: pubkey_2,
-                       payment_basepoint: pubkey_3,
+                       payment_point: pubkey_3,
                        delayed_payment_basepoint: pubkey_4,
                        htlc_basepoint: pubkey_5,
                        first_per_commitment_point: pubkey_6,
index f691b6fa922e8f15a3d8d490a792e9011485a3ed..d8db20f0f9a6008d9b23e8f85072a85ed48609fa 100644 (file)
@@ -53,7 +53,7 @@ impl EnforcingChannelKeys {
 impl ChannelKeys for EnforcingChannelKeys {
        fn funding_key(&self) -> &SecretKey { self.inner.funding_key() }
        fn revocation_base_key(&self) -> &SecretKey { self.inner.revocation_base_key() }
-       fn payment_base_key(&self) -> &SecretKey { self.inner.payment_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() }