mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-24 15:02:20 +01:00
Minor cleanups
This commit is contained in:
parent
f5ca346011
commit
4d75d4c099
4 changed files with 8 additions and 6 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()[..])
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Add table
Reference in a new issue