From: Matt Corallo Date: Mon, 9 Mar 2020 00:38:16 +0000 (-0400) Subject: Rename payment_basepoint/key to simply payment_point/key. X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=ee68c5b5cc890df22d2f245658a999c03eeba2f1;p=rust-lightning Rename payment_basepoint/key to simply payment_point/key. We no longer derive any keys from the payment point, so they aren't a "base" but simply a point/key. --- diff --git a/lightning/src/chain/keysinterface.rs b/lightning/src/chain/keysinterface.rs index fdcac5509..72a378e28 100644 --- a/lightning/src/chain/keysinterface.rs +++ b/lightning/src/chain/keysinterface.rs @@ -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 in commitment txn generated by us (for broadcast by our counterparty) + 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, 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(secp_ctx: &Secp256k1, 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(&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(reader: &mut R) -> Result { 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 base 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, diff --git a/lightning/src/ln/chan_utils.rs b/lightning/src/ln/chan_utils.rs index a57fafcd9..944d92a82 100644 --- a/lightning/src/ln/chan_utils.rs +++ b/lightning/src/ln/chan_utils.rs @@ -279,7 +279,7 @@ pub struct ChannelPublicKeys { 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, + 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 +292,7 @@ pub struct ChannelPublicKeys { impl_writeable!(ChannelPublicKeys, 33*5, { funding_pubkey, revocation_basepoint, - payment_basepoint, + payment_point, delayed_payment_basepoint, htlc_basepoint }); diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 879cb9f8b..2349195b8 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -556,7 +556,7 @@ impl Channel { 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 Channel { 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 Channel { 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_hash = WPubkeyHash::hash(&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 Channel { 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 Channel { 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 Channel { 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()[..], diff --git a/lightning/src/ln/channelmonitor.rs b/lightning/src/ln/channelmonitor.rs index e1143732a..c8fe6f1e3 100644 --- a/lightning/src/ln/channelmonitor.rs +++ b/lightning/src/ln/channelmonitor.rs @@ -1042,8 +1042,8 @@ impl ChannelMonitor { 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 ChannelMonitor { } 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; diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index 8093b4922..8794b4357 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -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()); } diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index cce8c3d0b..43005ad1d 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -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, diff --git a/lightning/src/util/enforcing_trait_impls.rs b/lightning/src/util/enforcing_trait_impls.rs index f691b6fa9..d8db20f0f 100644 --- a/lightning/src/util/enforcing_trait_impls.rs +++ b/lightning/src/util/enforcing_trait_impls.rs @@ -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() }