Log resolution of offered HTLC by HTLC-timeout tx
[rust-lightning] / src / ln / channelmonitor.rs
index 045ee36d28af6387794736659312cfc8f80a7c52..4ebeba047585c109fe665fed1a6e6f68fe3c3b10 100644 (file)
@@ -17,11 +17,12 @@ use bitcoin::blockdata::transaction::OutPoint as BitcoinOutPoint;
 use bitcoin::blockdata::script::{Script, Builder};
 use bitcoin::blockdata::opcodes;
 use bitcoin::consensus::encode::{self, Decodable, Encodable};
-use bitcoin::util::hash::{Hash160, BitcoinHash,Sha256dHash};
+use bitcoin::util::hash::{BitcoinHash,Sha256dHash};
 use bitcoin::util::bip143;
 
 use bitcoin_hashes::Hash;
 use bitcoin_hashes::sha256::Hash as Sha256;
+use bitcoin_hashes::hash160::Hash as Hash160;
 
 use secp256k1::{Secp256k1,Message,Signature};
 use secp256k1::key::{SecretKey,PublicKey};
@@ -567,6 +568,8 @@ impl ChannelMonitor {
                }
 
                let new_txid = unsigned_commitment_tx.txid();
+               log_trace!(self, "Tracking new remote commitment transaction with txid {} at commitment number {} with {} HTLC outputs", new_txid, commitment_number, htlc_outputs.len());
+               log_trace!(self, "New potential remote commitment transaction: {}", encode::serialize_hex(unsigned_commitment_tx));
                if let Storage::Local { ref mut current_remote_commitment_txid, ref mut prev_remote_commitment_txid, .. } = self.key_storage {
                        *prev_remote_commitment_txid = current_remote_commitment_txid.take();
                        *current_remote_commitment_txid = Some(new_txid);
@@ -1077,7 +1080,7 @@ impl ChannelMonitor {
                        let local_payment_p2wpkh = if let Some(payment_key) = local_payment_key {
                                // Note that the Network here is ignored as we immediately drop the address for the
                                // script_pubkey version.
-                               let payment_hash160 = Hash160::from_data(&PublicKey::from_secret_key(&self.secp_ctx, &payment_key).serialize());
+                               let payment_hash160 = Hash160::hash(&PublicKey::from_secret_key(&self.secp_ctx, &payment_key).serialize());
                                Some(Builder::new().push_opcode(opcodes::All::OP_PUSHBYTES_0).push_slice(&payment_hash160[..]).into_script())
                        } else { None };
 
@@ -1245,6 +1248,8 @@ impl ChannelMonitor {
                        watch_outputs.append(&mut tx.output.clone());
                        self.remote_commitment_txn_on_chain.insert(commitment_txid, (commitment_number, tx.output.iter().map(|output| { output.script_pubkey.clone() }).collect()));
 
+                       log_trace!(self, "Got broadcast of non-revoked remote commitment transaction {}", commitment_txid);
+
                        if let Some(revocation_points) = self.their_cur_revocation_points {
                                let revocation_point_option =
                                        if revocation_points.0 == commitment_number { Some(&revocation_points.1) }
@@ -1619,7 +1624,7 @@ impl ChannelMonitor {
                if tx.input[0].sequence == 0xFFFFFFFF && !tx.input[0].witness.is_empty() && tx.input[0].witness.last().unwrap().len() == 71 {
                        match self.key_storage {
                                Storage::Local { ref shutdown_pubkey, .. } =>  {
-                                       let our_channel_close_key_hash = Hash160::from_data(&shutdown_pubkey.serialize());
+                                       let our_channel_close_key_hash = Hash160::hash(&shutdown_pubkey.serialize());
                                        let shutdown_script = Builder::new().push_opcode(opcodes::All::OP_PUSHBYTES_0).push_slice(&our_channel_close_key_hash[..]).into_script();
                                        for (idx, output) in tx.output.iter().enumerate() {
                                                if shutdown_script == output.script_pubkey {
@@ -1810,9 +1815,12 @@ impl ChannelMonitor {
                                        }
                                        if payment_data.is_none() {
                                                for htlc_output in $htlc_outputs {
-                                                       if input.previous_output.vout == htlc_output.transaction_output_index {
+                                                       if input.previous_output.vout == htlc_output.transaction_output_index && !htlc_output.offered {
                                                                log_info!(self, "Input spending {}:{} in {} resolves inbound HTLC with timeout from {}", input.previous_output.txid, input.previous_output.vout, tx.txid(), $source);
                                                                continue 'outer_loop;
+                                                       } else if input.previous_output.vout == htlc_output.transaction_output_index && tx.lock_time > 0 {
+                                                               log_info!(self, "Input spending {}:{} in {} resolves offered HTLC with HTLC-timeout from {}", input.previous_output.txid, input.previous_output.vout, tx.txid(), $source);
+                                                               continue 'outer_loop;
                                                        }
                                                }
                                        }