Integrate destination_script from KeysInterface in ChannelManager/Channel 2018-10-214-redo
authorAntoine Riard <ariard@student.42.fr>
Fri, 26 Oct 2018 17:41:07 +0000 (13:41 -0400)
committerMatt Corallo <git@bluematt.me>
Sat, 27 Oct 2018 13:42:04 +0000 (09:42 -0400)
Drop channel_monitor_claim_key from ChannelKeys

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

index 765479a40dce3ec0806296c23d74cd169fe89f91..ed5001a3e08f86b49d6751619fb5f2b8b681ac35 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_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],
                        }
                } else {
@@ -237,7 +236,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_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 84ebde34252c95a530c4c0bb6c5f6ef63d9f64ac..b3823e2156106ac79573e9b56a529ab33002a197 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 in justice tx, claim tx and preimage tx outputs
-       pub channel_monitor_claim_key: SecretKey,
        /// Commitment seed
        pub commitment_seed: [u8; 32],
 }
@@ -104,9 +102,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 monitor claim key info", &mut okm);
-               let channel_monitor_claim_key = SecretKey::from_slice(&secp_ctx, &okm).expect("Sha256 is broken");
-
                hkdf_expand(Sha256::new(), &prk, b"rust-lightning local commitment seed info", &mut okm);
 
                ChannelKeys {
@@ -115,7 +110,6 @@ impl ChannelKeys {
                        payment_base_key: payment_base_key,
                        delayed_payment_base_key: delayed_payment_base_key,
                        htlc_base_key: htlc_base_key,
-                       channel_monitor_claim_key: channel_monitor_claim_key,
                        commitment_seed: okm
                }
        }
index 2f73cd3c5d4f5cf89d343507b5da28d1fb37386b..6fd6afe8e36ba6ff6ac2707cf909096ebd8a5706 100644 (file)
@@ -436,11 +436,9 @@ impl Channel {
                let feerate = fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::Normal);
 
                let secp_ctx = Secp256k1::new();
-               let our_channel_monitor_claim_key_hash = Hash160::from_data(&PublicKey::from_secret_key(&secp_ctx, &chan_keys.channel_monitor_claim_key).serialize());
-               let our_channel_monitor_claim_script = Builder::new().push_opcode(opcodes::All::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script();
                let channel_monitor = ChannelMonitor::new(&chan_keys.revocation_base_key, &chan_keys.delayed_payment_base_key,
-                                                         &chan_keys.htlc_base_key,
-                                                         BREAKDOWN_TIMEOUT, our_channel_monitor_claim_script);
+                                                         &chan_keys.htlc_base_key, BREAKDOWN_TIMEOUT,
+                                                         keys_provider.get_destination_script());
 
                Ok(Channel {
                        user_id: user_id,
@@ -600,11 +598,9 @@ impl Channel {
                }
 
                let secp_ctx = Secp256k1::new();
-               let our_channel_monitor_claim_key_hash = Hash160::from_data(&PublicKey::from_secret_key(&secp_ctx, &chan_keys.channel_monitor_claim_key).serialize());
-               let our_channel_monitor_claim_script = Builder::new().push_opcode(opcodes::All::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script();
                let mut channel_monitor = ChannelMonitor::new(&chan_keys.revocation_base_key, &chan_keys.delayed_payment_base_key,
-                                                             &chan_keys.htlc_base_key,
-                                                             BREAKDOWN_TIMEOUT, our_channel_monitor_claim_script);
+                                                             &chan_keys.htlc_base_key, BREAKDOWN_TIMEOUT,
+                                                             keys_provider.get_destination_script());
                channel_monitor.set_their_base_keys(&msg.htlc_basepoint, &msg.delayed_payment_basepoint);
                channel_monitor.set_their_to_self_delay(msg.to_self_delay);
 
@@ -3232,11 +3228,12 @@ impl Channel {
 
 #[cfg(test)]
 mod tests {
-       use bitcoin::util::hash::Sha256dHash;
+       use bitcoin::util::hash::{Sha256dHash, Hash160};
        use bitcoin::util::bip143;
        use bitcoin::network::serialize::serialize;
-       use bitcoin::blockdata::script::Script;
+       use bitcoin::blockdata::script::{Script, Builder};
        use bitcoin::blockdata::transaction::Transaction;
+       use bitcoin::blockdata::opcodes;
        use hex;
        use ln::channelmanager::HTLCSource;
        use ln::channel::{Channel,ChannelKeys,InboundHTLCOutput,OutboundHTLCOutput,InboundHTLCState,OutboundHTLCState,HTLCOutputInCommitment,TxCreationKeys};
@@ -3273,7 +3270,12 @@ mod tests {
        }
        impl KeysInterface for Keys {
                fn get_node_secret(&self) -> SecretKey { panic!(); }
-               fn get_destination_script(&self) -> Script { panic!(); }
+               fn get_destination_script(&self) -> Script {
+                       let secp_ctx = Secp256k1::signing_only();
+                       let channel_monitor_claim_key = SecretKey::from_slice(&secp_ctx, &hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
+                       let our_channel_monitor_claim_key_hash = Hash160::from_data(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
+                       Builder::new().push_opcode(opcodes::All::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script()
+               }
 
                fn get_shutdown_pubkey(&self) -> PublicKey {
                        let secp_ctx = Secp256k1::signing_only();
@@ -3299,7 +3301,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_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],
                };
                assert_eq!(PublicKey::from_secret_key(&secp_ctx, &chan_keys.funding_key).serialize()[..],