Integrate shutdown_pubkey from KeysInterface in ChannelManager/Channel
authorAntoine Riard <ariard@student.42.fr>
Fri, 26 Oct 2018 17:35:57 +0000 (13:35 -0400)
committerMatt Corallo <git@bluematt.me>
Sat, 27 Oct 2018 13:42:04 +0000 (09:42 -0400)
Drop channel_close_key from ChannelKeys

fuzz/fuzz_targets/full_stack_target.rs
src/chain/keysinterface.rs
src/ln/channel.rs

index 3222252ef2e5b67de122f59f8a1e942e3ed8c64d..765479a40dce3ec0806296c23d74cd169fe89f91 100644 (file)
@@ -227,7 +227,6 @@ impl KeysInterface for KeyProvider {
                                payment_base_key:          SecretKey::from_slice(&secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0]).unwrap(),
                                delayed_payment_base_key:  SecretKey::from_slice(&secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0]).unwrap(),
                                htlc_base_key:             SecretKey::from_slice(&secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0]).unwrap(),
-                               channel_close_key:         SecretKey::from_slice(&secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0]).unwrap(),
                                channel_monitor_claim_key: SecretKey::from_slice(&secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0]).unwrap(),
                                commitment_seed: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                        }
@@ -238,7 +237,6 @@ impl KeysInterface for KeyProvider {
                                payment_base_key:          SecretKey::from_slice(&secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
                                delayed_payment_base_key:  SecretKey::from_slice(&secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
                                htlc_base_key:             SecretKey::from_slice(&secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
-                               channel_close_key:         SecretKey::from_slice(&secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
                                channel_monitor_claim_key: SecretKey::from_slice(&secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
                                commitment_seed: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                        }
index 3a5ca6942c69d0473f5bfd7113fac9f311a89a50..84ebde34252c95a530c4c0bb6c5f6ef63d9f64ac 100644 (file)
@@ -74,8 +74,6 @@ pub struct ChannelKeys {
        pub delayed_payment_base_key: SecretKey,
        /// Local htlc secret key used in commitment tx htlc outputs
        pub htlc_base_key: SecretKey,
-       /// Local secret key used for closing tx
-       pub channel_close_key: SecretKey,
        /// Local secret key used in justice tx, claim tx and preimage tx outputs
        pub channel_monitor_claim_key: SecretKey,
        /// Commitment seed
@@ -106,9 +104,6 @@ impl ChannelKeys {
                hkdf_expand(Sha256::new(), &prk, b"rust-lightning htlc base key info", &mut okm);
                let htlc_base_key = SecretKey::from_slice(&secp_ctx, &okm).expect("Sha256 is broken");
 
-               hkdf_expand(Sha256::new(), &prk, b"rust-lightning channel close key info", &mut okm);
-               let channel_close_key = SecretKey::from_slice(&secp_ctx, &okm).expect("Sha256 is broken");
-
                hkdf_expand(Sha256::new(), &prk, b"rust-lightning channel monitor claim key info", &mut okm);
                let channel_monitor_claim_key = SecretKey::from_slice(&secp_ctx, &okm).expect("Sha256 is broken");
 
@@ -120,7 +115,6 @@ impl ChannelKeys {
                        payment_base_key: payment_base_key,
                        delayed_payment_base_key: delayed_payment_base_key,
                        htlc_base_key: htlc_base_key,
-                       channel_close_key: channel_close_key,
                        channel_monitor_claim_key: channel_monitor_claim_key,
                        commitment_seed: okm
                }
index a889e2ecad6eb89309564d45bde082974a8f082f..2f73cd3c5d4f5cf89d343507b5da28d1fb37386b 100644 (file)
@@ -238,6 +238,7 @@ pub(super) struct Channel {
        channel_value_satoshis: u64,
 
        local_keys: ChannelKeys,
+       shutdown_pubkey: PublicKey,
 
        // Our commitment numbers start at 2^48-1 and count down, whereas the ones used in transaction
        // generation start at 0 and count up...this simplifies some parts of implementation at the
@@ -452,6 +453,7 @@ impl Channel {
                        channel_value_satoshis: channel_value_satoshis,
 
                        local_keys: chan_keys,
+                       shutdown_pubkey: keys_provider.get_shutdown_pubkey(),
                        cur_local_commitment_transaction_number: INITIAL_COMMITMENT_NUMBER,
                        cur_remote_commitment_transaction_number: INITIAL_COMMITMENT_NUMBER,
                        value_to_self_msat: channel_value_satoshis * 1000 - push_msat,
@@ -616,6 +618,7 @@ impl Channel {
                        announce_publicly: their_announce,
 
                        local_keys: chan_keys,
+                       shutdown_pubkey: keys_provider.get_shutdown_pubkey(),
                        cur_local_commitment_transaction_number: INITIAL_COMMITMENT_NUMBER,
                        cur_remote_commitment_transaction_number: INITIAL_COMMITMENT_NUMBER,
                        value_to_self_msat: msg.push_msat,
@@ -898,7 +901,7 @@ impl Channel {
 
        #[inline]
        fn get_closing_scriptpubkey(&self) -> Script {
-               let our_channel_close_key_hash = Hash160::from_data(&PublicKey::from_secret_key(&self.secp_ctx, &self.local_keys.channel_close_key).serialize());
+               let our_channel_close_key_hash = Hash160::from_data(&self.shutdown_pubkey.serialize());
                Builder::new().push_opcode(opcodes::All::OP_PUSHBYTES_0).push_slice(&our_channel_close_key_hash[..]).into_script()
        }
 
@@ -3271,7 +3274,13 @@ mod tests {
        impl KeysInterface for Keys {
                fn get_node_secret(&self) -> SecretKey { panic!(); }
                fn get_destination_script(&self) -> Script { panic!(); }
-               fn get_shutdown_pubkey(&self) -> PublicKey { panic!(); }
+
+               fn get_shutdown_pubkey(&self) -> PublicKey {
+                       let secp_ctx = Secp256k1::signing_only();
+                       let channel_close_key = SecretKey::from_slice(&secp_ctx, &hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
+                       PublicKey::from_secret_key(&secp_ctx, &channel_close_key)
+               }
+
                fn get_channel_keys(&self, _inbound: bool) -> ChannelKeys { self.chan_keys.clone() }
        }
 
@@ -3290,7 +3299,6 @@ mod tests {
 
                        // These aren't set in the test vectors:
                        revocation_base_key: SecretKey::from_slice(&secp_ctx, &hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap(),
-                       channel_close_key: SecretKey::from_slice(&secp_ctx, &hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap(),
                        channel_monitor_claim_key: SecretKey::from_slice(&secp_ctx, &hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap(),
                        commitment_seed: [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff],
                };