From: Matt Corallo Date: Mon, 9 Apr 2018 01:01:13 +0000 (-0400) Subject: Minor cleanups X-Git-Tag: v0.0.12~412^2~1 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=4d75d4c099cd6875f7ba95050012de340367278a;p=rust-lightning Minor cleanups --- diff --git a/src/ln/chan_utils.rs b/src/ln/chan_utils.rs index dfe17c591..81fa29f55 100644 --- a/src/ln/chan_utils.rs +++ b/src/ln/chan_utils.rs @@ -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) } diff --git a/src/ln/channel.rs b/src/ln/channel.rs index d690ef3ea..067b2bc53 100644 --- a/src/ln/channel.rs +++ b/src/ln/channel.rs @@ -43,7 +43,7 @@ impl ChannelKeys { pub fn new_from_seed(seed: &[u8; 32]) -> Result { 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); diff --git a/src/ln/channelmanager.rs b/src/ln/channelmanager.rs index b731556da..68cfed8fd 100644 --- a/src/ln/channelmanager.rs +++ b/src/ln/channelmanager.rs @@ -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()[..]) diff --git a/src/ln/channelmonitor.rs b/src/ln/channelmonitor.rs index 27010d522..3021163f9 100644 --- a/src/ln/channelmonitor.rs +++ b/src/ln/channelmonitor.rs @@ -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));