]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Minor cleanups
authorMatt Corallo <git@bluematt.me>
Mon, 9 Apr 2018 01:01:13 +0000 (21:01 -0400)
committerMatt Corallo <git@bluematt.me>
Tue, 17 Apr 2018 00:35:21 +0000 (20:35 -0400)
src/ln/chan_utils.rs
src/ln/channel.rs
src/ln/channelmanager.rs
src/ln/channelmonitor.rs

index dfe17c5911e711e3601d90670879718b24ecbcd8..81fa29f554113a5cb156205ab5be351ceb3290fb 100644 (file)
@@ -157,7 +157,7 @@ pub struct HTLCOutputInCommitment {
 }
 
 #[inline]
-pub fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommitment, a_htlc_key: &PublicKey, b_htlc_key: &PublicKey, revocation_key: &PublicKey, offered: bool) -> Script {
+pub fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommitment, a_htlc_key: &PublicKey, b_htlc_key: &PublicKey, revocation_key: &PublicKey) -> Script {
        let payment_hash160 = {
                let mut ripemd = Ripemd160::new();
                ripemd.input(&htlc.payment_hash);
@@ -165,7 +165,7 @@ pub fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommitment, a
                ripemd.result(&mut res);
                res
        };
-       if offered {
+       if htlc.offered {
                Builder::new().push_opcode(opcodes::All::OP_DUP)
                              .push_opcode(opcodes::All::OP_HASH160)
                              .push_slice(&Hash160::from_data(&revocation_key.serialize())[..])
@@ -231,5 +231,5 @@ pub fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommitment, a
 /// commitment secret. 'htlc' does *not* need to have its previous_output_index filled.
 #[inline]
 pub fn get_htlc_redeemscript(htlc: &HTLCOutputInCommitment, keys: &TxCreationKeys) -> Script {
-       get_htlc_redeemscript_with_explicit_keys(htlc, &keys.a_htlc_key, &keys.b_htlc_key, &keys.revocation_key, htlc.offered)
+       get_htlc_redeemscript_with_explicit_keys(htlc, &keys.a_htlc_key, &keys.b_htlc_key, &keys.revocation_key)
 }
index d690ef3ea0068dfe82211f1c45d4616e9e9cb976..067b2bc530dd1ae551c324f65318197421466ab1 100644 (file)
@@ -43,7 +43,7 @@ impl ChannelKeys {
        pub fn new_from_seed(seed: &[u8; 32]) -> Result<ChannelKeys, secp256k1::Error> {
                let mut prk = [0; 32];
                hkdf_extract(Sha256::new(), b"rust-lightning key gen salt", seed, &mut prk);
-               let secp_ctx = Secp256k1::new();
+               let secp_ctx = Secp256k1::without_caps();
 
                let mut okm = [0; 32];
                hkdf_expand(Sha256::new(), &prk, b"rust-lightning funding key info", &mut okm);
index b731556daba3d14255bd515d0063cd48b1d4e9cb..68cfed8fd0d422cce1f17550bdefde7d129dbae1 100644 (file)
@@ -307,6 +307,7 @@ impl ChannelManager {
                res
        }
 
+       #[inline]
        fn gen_ammag_from_shared_secret(shared_secret: &SharedSecret) -> [u8; 32] {
                let mut hmac = Hmac::new(Sha256::new(), &[0x61, 0x6d, 0x6d, 0x61, 0x67]); // ammag
                hmac.input(&shared_secret[..]);
@@ -505,6 +506,7 @@ impl ChannelManager {
                packet
        }
 
+       #[inline]
        fn build_first_hop_failure_packet(shared_secret: &SharedSecret, failure_type: u16, failure_data: &[u8]) -> msgs::OnionErrorPacket {
                let failure_packet = ChannelManager::build_failure_packet(shared_secret, failure_type, failure_data);
                ChannelManager::encrypt_failure_packet(shared_secret, &failure_packet.encode()[..])
index 27010d522dfe7037485c4bfac6f18237417df829..3021163f9e7271493a4c9d30ea7e98413640091c 100644 (file)
@@ -335,7 +335,7 @@ impl ChannelMonitor {
                                        total_value += tx.output[per_commitment_data.revoked_output_index as usize].value;
 
                                        for &(ref htlc, ref _next_tx_sig) in per_commitment_data.htlcs.iter() {
-                                               let expected_script = chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, &a_htlc_key, &b_htlc_key, &revocation_pubkey, htlc.offered);
+                                               let expected_script = chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, &a_htlc_key, &b_htlc_key, &revocation_pubkey);
                                                if htlc.transaction_output_index as usize >= tx.output.len() ||
                                                                tx.output[htlc.transaction_output_index as usize].value != htlc.amount_msat / 1000 ||
                                                                tx.output[htlc.transaction_output_index as usize].script_pubkey != expected_script.to_v0_p2wsh() {
@@ -426,7 +426,7 @@ impl ChannelMonitor {
 
                                                let sig = match self.revocation_base_key {
                                                        RevocationStorage::PrivMode { ref revocation_base_key } => {
-                                                               let htlc_redeemscript = chan_utils::get_htlc_redeemscript_with_explicit_keys(htlc, &a_htlc_key, &b_htlc_key, &revocation_pubkey, htlc.offered);
+                                                               let htlc_redeemscript = chan_utils::get_htlc_redeemscript_with_explicit_keys(htlc, &a_htlc_key, &b_htlc_key, &revocation_pubkey);
                                                                let sighash = ignore_error!(Message::from_slice(&sighash_parts.sighash_all(&input, &htlc_redeemscript, values_drain.next().unwrap())[..]));
 
                                                                let revocation_key = ignore_error!(chan_utils::derive_private_revocation_key(&self.secp_ctx, &per_commitment_key, &revocation_base_key));